OSDN Git Service

[UI] Fix same keyin feeling.
[openi2cradio/OpenI2CRadio.git] / ui.c
diff --git a/ui.c b/ui.c
index c9da851..6a3ba64 100644 (file)
--- a/ui.c
+++ b/ui.c
@@ -331,9 +331,14 @@ unsigned char pollkey_single(void)
                 cold = c;
                 return c;
             }
+            penalty = 0;
+        } else {
+            penalty++;
+            if(penalty > 4) {
+                penalty = 0;
+                cold = charcode_null; // About 100ms
+            }
         }
-        penalty++;
-        if(penalty > 65) cold = charcode_null; // About 1500ms
     } while(1);
 }
 
@@ -341,44 +346,52 @@ unsigned char pollkey_single_timeout(unsigned int limit, unsigned char repeat)
 {
     unsigned char c;
     unsigned int ticks = 0;
+    unsigned char penalty = 0;
+    unsigned char count = 0;
 
 
-//    cold = charcode_null;
+    cold = charcode_null;
+    pollkeybuf[0] = charcode_null;
     do {
+        if(limit != 0) {
+            ticks++;
+            if(ticks > limit) {
+                break;
+            }
+        }
         idle_time_ms(5); // 5ms.
         c = readkey(); // 2 * 9 = 18ms
         ClrWdt();
         ticks++;
-        if(c != charcode_null) {
-            if(repeat != 0){
+        if(c != charcode_null){
+            if(cold != c) {
+                pollkeybuf[count++] = c;
                 cold = c;
-                break;
-            } else {
-                if(cold != c) {
-                    cold = c;
-                    break;
+                count++;
+                if(repeat == 0) {
+                        break;
                 }
+                penalty = 0;
             }
-        }
-        if(limit != 0) {
-            ticks++;
-            if(ticks > limit) {
+        }  else {
+            penalty++;
+            if(penalty > 4){
+                penalty = 0;
                 cold = charcode_null;
-                return charcode_null;
             }
         }
-    } while(1);
+    } while(count < 32);
 
     /*
      * Set Deadzone.
      */
     if(limit == 0) {
-//        if(ticks >= (limit >> 1)) cold = charcode_null;
         while(ticks <= limit) {
             idle_time_ms(5 + 18);
             ticks++;
         }
     }
+    c = pollkeybuf[0];
     return c;
 }
 /*