From 90e7244f1fde933cad8d772190f872d44d0cd6d9 Mon Sep 17 00:00:00 2001 From: "K.Ohta" Date: Fri, 21 Jun 2013 10:04:18 +0900 Subject: [PATCH] [UI] Fix keyin-fifo-handling. --- main.c | 18 +++++++++++------- ui.c | 38 ++++++++++++++++++++++++++++++++++++-- ui.h | 1 + 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index e98ede7..2dce408 100644 --- a/main.c +++ b/main.c @@ -145,6 +145,8 @@ unsigned char scanflag; int recv_signal; int backlight_counter; unsigned char backlight_level; +unsigned char pollkeybuf[33]; + unsigned int writeword_eeprom(unsigned int p, unsigned int *sum, unsigned int word) { @@ -925,13 +927,15 @@ int main(void) set_amlamp(i & 1); set_powerlamp(i & 1); i = i + 1; - idle(65535-7128/10 + 1); - c = readkey(); - _LOCATE(0,0); -// if(c == charcode_null) _PUTCHAR('p'); - while(c != charcode_null) { - _PUTCHAR(c + '0'); - c = pop_keyinfifo(); + c = pollkeys(pollkeybuf, 30); // Poll about 600ms + if(c != 0) { + unsigned char sp; + _LOCATE(0,0); + for(sp = 0; sp < c; sp++) _PUTCHAR(pollkeybuf[sp] + '0'); + } else { + _CLS(); + _LOCATE(0,0); + _PUTCHAR(' '); } }while(1); #else diff --git a/ui.c b/ui.c index 8761276..ed8b293 100644 --- a/ui.c +++ b/ui.c @@ -82,9 +82,9 @@ void push_keyinfifo(char b) __critical keyin_counter = 31; return; } + keyin_fifo[keyin_nowp] = b; keyin_nowp++; if((keyin_nowp > 31) || (keyin_nowp < 0))keyin_nowp = 0; - keyin_fifo[keyin_nowp] = b; keyin_counter++; } @@ -98,8 +98,8 @@ char pop_keyinfifo(void) __critical keyin_counter = 0; return charcode_null ; } - if(keyin_readp > 31) keyin_readp = 0; c = keyin_fifo[keyin_readp]; + if(keyin_readp > 31) keyin_readp = 0; keyin_readp++; keyin_counter--; if(keyin_counter < 0) keyin_counter = 0; @@ -348,6 +348,40 @@ unsigned char readkey(void) } /* + * Polling key + * Max = 32bytes; + * 0 = Timeout + * 1~32 = Received. + * if((limit * 19.6ms) elapsed), break; + */ +unsigned char pollkeys(unsigned char *p, unsigned int limit) +{ + unsigned int count = 0; + unsigned int lifetime = 0; + unsigned char c; + unsigned char cold; + + do { + idle(65535 - 100 + 1); // 0.78*256 = 78ms. + c = readkey(); // 0.78*2*8 = 11.2ms + if(c != charcode_null) { + cold = c; + p[count++] = c; + } + do { + c = pop_keyinfifo(); + if(c == charcode_null) break; + if(c != cold) { + p[count++] = c; + cold = c; + } + } while(count < 32); + if(limit != 0) lifetime++; + if(lifetime >= limit) break; + } while(count < 32); + return count; +} +/* * Notes: * Initialize sequence: * keyin_init(); diff --git a/ui.h b/ui.h index e80e9ba..39e0fe8 100644 --- a/ui.h +++ b/ui.h @@ -68,6 +68,7 @@ extern unsigned int read_numeric(unsigned int initial, unsigned char digit, extern unsigned int subst_numeric(unsigned int start, unsigned char pos, unsigned char c); extern void print_numeric_nosupress(unsigned int data, unsigned char digit); extern unsigned char readkey(void); +extern unsigned char pollkeys(unsigned char *p, unsigned int limit); #ifdef __cplusplus } -- 2.11.0