提交 86d1be00 编写于 作者: Z Zihao Yu

test,uart: preset some keys and them generate random keys

* now we can control the characters in PAL to trigger a battle
上级 5d18710d
......@@ -14,38 +14,40 @@ static void uart_enqueue(char ch) {
}
}
// generate a random key every 1s for pal
static int rand_key(void) {
static int uart_dequeue(void) {
int k = 0;
if (f != r) {
k = queue[f];
f = (f + 1) % QUEUE_SIZE;
} else {
// generate a random key every 1s for pal
k = "uiojkl"[rand()% 6];
}
return k;
}
int uart_getc(void) {
uint32_t uptime(void);
static uint32_t lasttime = 0;
uint32_t now = uptime();
if (now - lasttime > 1000) {
if (now - lasttime > 30000) {
lasttime = now;
return "uiojkl"[rand()% 6];
return uart_dequeue();
} else {
return 0;
}
}
int uart_getc(void) {
int k = 0;
if (f != r) {
k = queue[f];
f = (f + 1) % QUEUE_SIZE;
} else {
k = rand_key();
}
return k;
}
void uart_putc(char c) {
eprintf("%c", c);
}
static void preset_input() {
char rtthread_cmd[128] = "memtrace\n";
char init_cmd[128] = "2"; // choose PAL
char init_cmd[128] = "2" // choose PAL
"jjjjjjjkkkkkk" // walk to enemy
;
char *buf = init_cmd;
int i;
for (i = 0; i < strlen(buf); i ++) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册