OSDN Git Service

[DOC][v1.0] Update documents for 1.0RC2.
[openi2cradio/OpenI2CRadio.git] / ui.c
diff --git a/ui.c b/ui.c
index 6a3ba64..6db4e20 100644 (file)
--- a/ui.c
+++ b/ui.c
@@ -63,6 +63,47 @@ char keyin_counter;
 
 unsigned char cold;
 
+// LCD Routines
+void _PUTCHAR(unsigned char c)
+{
+    acm1602_putchar(LCD_I2CADDR , c);
+}
+
+void _LOCATE(unsigned char x, unsigned char y)
+{
+    acm1602_locate_16x2(LCD_I2CADDR , x, y);
+}
+
+void _CLS(void)
+{
+    acm1602_cls(LCD_I2CADDR);
+}
+void _HOME(void)
+{
+    acm1602_home(LCD_I2CADDR);
+}
+
+void _CURSOR_ON(void)
+{
+    acm1602_dispcursor(LCD_I2CADDR, 0xff);
+}
+
+
+void _CURSOR_OFF(void)
+{
+    acm1602_dispcursor(LCD_I2CADDR, 0x00);
+}
+
+void _CURSOR_LEFT(void)
+{
+    acm1602_cursordir(LCD_I2CADDR , 0x00);
+}
+
+void _CURSOR_RIGHT(void)
+{
+    acm1602_cursordir(LCD_I2CADDR , 0xff);
+}
+
 void keyin_init(void)
 {
     char i;
@@ -93,7 +134,7 @@ void push_keyinfifo(char b)
     keyin_fifo[keyin_nowp] = b;
     keyin_nowp++;
     keyin_counter++;
-    if((keyin_nowp > 31) || (keyin_nowp < 0)) keyin_nowp = 0;
+    if(keyin_nowp > 31) keyin_nowp = 0;
 }
 
 /*
@@ -113,14 +154,14 @@ char pop_keyinfifo(void)
     c = keyin_fifo[keyin_readp];
     keyin_readp++;
     keyin_counter--;
-    if((keyin_readp > 31) || (keyin_readp < 0)) keyin_readp = 0;
+    if(keyin_readp > 31) keyin_readp = 0;
     return c;
 }
 
 void printstr(char *s)
 {
     int p = 0;
-    _CURSOR_RIGHT();
+//    _CURSOR_RIGHT();
     if(s == NULL) return;
     do {
         if(s[p] == '\0') break;
@@ -131,26 +172,26 @@ void printstr(char *s)
 
 
 
-void uint2bcd(unsigned long data, unsigned char *bcd)
+static void uint2bcd(unsigned long data, unsigned char *bcd)
 {
     unsigned char i;
     unsigned char j;
 
-    for(i = 0; i < 5; i++){
+    for(i = 0; i <= 10; i++){
         bcd[i] = data % 10;
         data = data / 10;
     }
-    bcd[5] = 0;
+    bcd[10] = 0;
 }
 
 void print_numeric_nosupress(unsigned long data, unsigned char digit)
 {
     unsigned char i;
-    unsigned char bcd[6];
+    unsigned char bcd[11];
 
 
     if(digit == 0) return;
-    if(digit >= 5) digit = 5;
+    if(digit > 10) digit = 10;
     uint2bcd(data, bcd);
     for(i = digit; i > 0; i--){
         _PUTCHAR('0' + bcd[i - 1]);
@@ -162,17 +203,24 @@ void print_numeric_nosupress(unsigned long data, unsigned char digit)
 unsigned long subst_numeric(unsigned long start, unsigned char pos, unsigned char c)
 {
     unsigned long val;
-    unsigned char bcd[6];
+    unsigned char bcd[11];
     char i;
+    unsigned long fact;
 
-    if(pos > 4) pos = 4;
+    if(pos > 10) pos = 10;
     uint2bcd(start, bcd);
     bcd[pos] = c;
-    val = bcd[0] + bcd[1] * 10 + bcd[2] * 100 + bcd[3] * 1000 + bcd[4] * 10000;
+    
+    fact = 1;
+    val = 0;
+    for(i = 0; i < 11; i++){
+        val = val + (bcd[i] * fact);
+        fact = fact * 10;
+    }
     return val;
 }
 
-unsigned int read_numeric(unsigned int initial, unsigned char digit,
+unsigned long read_numeric(unsigned int initial, unsigned char digit,
         char startx, char starty)
 {
     unsigned char c;
@@ -210,9 +258,7 @@ unsigned int read_numeric(unsigned int initial, unsigned char digit,
             i++;
         } else if(c == charcode_b) {
             // cancel
-            val = initial;
-            i = d;
-            break;
+            return 0xffffffff;
         }  else if(c == charcode_e) {
             i++;
         } else if(c == charcode_d) {
@@ -222,8 +268,8 @@ unsigned int read_numeric(unsigned int initial, unsigned char digit,
        if(i > d) i = d;
     } while(1);
     _CURSOR_OFF();
-    if(val > 65535) val = 65535;
-    return (unsigned int)val;
+    if(val > 0x7fffffff) val = 0x7fffffff;
+    return val;
 }
 
 unsigned char readkey_compare(void)
@@ -273,48 +319,6 @@ unsigned char readkey(void)
     return pop_keyinfifo();
 }
 
-/*
- * Polling key
- * Max = 32bytes;
- * 0 = Timeout
- * 1~32 = Received.
- * if((limit * 23ms) elapsed), break;
- */
-unsigned char pollkeys(unsigned char *p, unsigned int limit, unsigned char repeat)
-{
-    unsigned char count = 0;
-    unsigned int lifetime = 0;
-    unsigned int penalty = 0;
-    unsigned char c;
-    unsigned char i;
-
-    do {
-        idle_time_ms(5); // 5ms.
-        c = readkey(); //18ms
-        ClrWdt();
-        if(c != charcode_null){
-            if(cold != c) {
-                p[count++] = c;
-                cold = c;
-                count++;
-                if(repeat == 0) {
-                        break;
-                }
-                penalty = 0;
-            }
-        }  else {
-            penalty++;
-            if(penalty > 4){
-                penalty = 0;
-                cold = charcode_null;
-            }
-        }
-        if(limit != 0) lifetime++;
-        if(lifetime > limit) break;
-    } while(count < 32);
-    p[count] = charcode_null;
-    return count;
-}
 
 unsigned char pollkey_single(void)
 {
@@ -341,6 +345,18 @@ unsigned char pollkey_single(void)
         }
     } while(1);
 }
+unsigned char pollkey_numeric(unsigned char init)
+{
+    unsigned char c;
+    c = pollkey_single();
+    if(c == charcode_0) {
+        return 0;
+    } else if((c >= charcode_1) && (c <= charcode_9)){
+        return c;
+    } else {
+        return init;
+    }
+}
 
 unsigned char pollkey_single_timeout(unsigned int limit, unsigned char repeat)
 {