Fix LED blinking protocol.
authorNIIBE Yutaka <gniibe@fsij.org>
Fri, 20 May 2016 10:36:03 +0000 (19:36 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Sat, 21 May 2016 01:56:49 +0000 (10:56 +0900)
ChangeLog
src/gnuk.h
src/main.c

index c0f5481..fb2a136 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2016-05-21  Niibe Yutaka  <gniibe@fsij.org>
+
+       * src/main.c (led_blink, main): Fix LED blink protocol.
+
 2016-05-20  NIIBE Yutaka  <gniibe@fsij.org>
 
        * VERSION: 1.2.0.
index 1247a82..eed40c1 100644 (file)
@@ -421,10 +421,11 @@ extern const uint8_t gnuk_string_serial[];
 #define LED_ONESHOT              1
 #define LED_TWOSHOTS             2
 #define LED_SHOW_STATUS                  4
-#define LED_START_COMMAND        8
-#define LED_FINISH_COMMAND      16
-#define LED_FATAL               32
-#define LED_GNUK_EXEC           64
+#define LED_FATAL                8
+#define LED_SYNC                16
+#define LED_GNUK_EXEC           32
+#define LED_START_COMMAND       64
+#define LED_FINISH_COMMAND     128
 void led_blink (int spec);
 
 #if defined(PINPAD_SUPPORT)
index e9c58e3..6604797 100644 (file)
@@ -158,6 +158,12 @@ static void display_status_code (void)
 void
 led_blink (int spec)
 {
+  if (spec == LED_START_COMMAND || spec == LED_FINISH_COMMAND)
+    {
+      led_inverted = (spec == LED_START_COMMAND);
+      spec = LED_SYNC;
+    }
+
   eventflag_signal (&led_event, spec);
 }
 
@@ -256,18 +262,12 @@ main (int argc, char *argv[])
        case LED_SHOW_STATUS:
          display_status_code ();
          break;
-       case LED_START_COMMAND:
-         set_led (1);
-         led_inverted = 1;
-         chopstx_usec_wait (LED_TIMEOUT_STOP);
-         break;
-       case LED_FINISH_COMMAND:
-         led_inverted = 0;
-         set_led (0);
-         break;
        case LED_FATAL:
          display_fatal_code ();
          break;
+       case LED_SYNC:
+         set_led (led_inverted);
+         break;
        case LED_GNUK_EXEC:
          goto exec;
        default: