update only after button press
authorEugene Crosser <crosser@average.org>
Sat, 12 Dec 2015 08:50:54 +0000 (11:50 +0300)
committerEugene Crosser <crosser@average.org>
Sat, 12 Dec 2015 08:50:54 +0000 (11:50 +0300)
Pulsecounter-Prog.c

index 107ad32c2aae86362ed29fa7c62628031cbefbb4..400bb1d2af5dcae89be4750c3f6cf7bbb913770f 100644 (file)
@@ -3,9 +3,10 @@
 
 static void gpioHandler(uint8_t id);
 static void tickHandler(void);
-static bool connected = false;
 static int32_t cold = 0;
 static int32_t hot  = 0;
+static bool connected = false;
+static bool updatable = false;
 
 void main() {
     Hal_init();
@@ -20,12 +21,17 @@ static void gpioHandler(uint8_t id) {
 
     switch (id) {
     case 0:
-        Pulsecounter_accept(true);
-            Hal_greenLedOn();
-            Hal_redLedOn();
-            Hal_delay(10);
-            Hal_greenLedOff();
-            Hal_redLedOff();
+        /* Pulsecounter_accept(true); */
+        updatable = true;
+        if (connected) {
+            Pulsecounter_coldTick_indicate();
+            Pulsecounter_hotTick_indicate();
+        }
+        Hal_greenLedOn();
+        Hal_redLedOn();
+        Hal_delay(10);
+        Hal_greenLedOff();
+        Hal_redLedOff();
         Hal_tickStart(15000, tickHandler);
         break;
     case 1:
@@ -71,7 +77,8 @@ static void tickHandler(void) {
         Hal_delay(50);
         Hal_greenLedOff();
     }
-    Pulsecounter_accept(false);
+    updatable = false;
+    /* Pulsecounter_accept(false); */
 }
 
 /* -------- SCHEMA CALLBACKS -------- */
@@ -89,13 +96,14 @@ void Pulsecounter_connectHandler(void) {
 
 void Pulsecounter_disconnectHandler(void) {
     connected = false;
+    updatable = false;
     Hal_greenLedOn();
     Hal_delay(100);
     Hal_greenLedOff();
     Hal_redLedOn();
     Hal_delay(100);
     Hal_redLedOff();
-    Hal_tickStart(15000, tickHandler);
+    /* Hal_tickStart(15000, tickHandler); */
     Hal_disconnected();
 }
 
@@ -108,9 +116,11 @@ void Pulsecounter_hotTick_fetch(Pulsecounter_hotTick_t* const output) {
 }
 
 void Pulsecounter_coldSet_store(Pulsecounter_coldSet_t* const input) {
-    cold = *input;
+    if (updatable)
+        cold = *input;
 }
 
 void Pulsecounter_hotSet_store(Pulsecounter_hotSet_t* const input) {
-    hot = *input;
+    if (updatable)
+        hot = *input;
 }