add some timer
authorEugene Crosser <crosser@average.org>
Wed, 9 Dec 2015 18:20:00 +0000 (21:20 +0300)
committerEugene Crosser <crosser@average.org>
Wed, 9 Dec 2015 18:20:00 +0000 (21:20 +0300)
Hal/Hal.c
Hal/Hal.h
Pulsecounter-Prog.c

index bb05cd4e1113913c4231649cabc5d6548dd4bbaf..00b8c6b07202727f6cc402d3f9aed6e9da7a5cf5 100644 (file)
--- a/Hal/Hal.c
+++ b/Hal/Hal.c
@@ -275,6 +275,11 @@ void Hal_tickStart(uint16_t msecs, Hal_Handler handler) {
     TA1CCTL0 = CCIE;                            // Enable the CCR0 interrupt
 }
 
+void Hal_tickStop(void) {
+    handlerTab[TICK_HANDLER_ID] = 0;
+    TA1CCR0 = 0;
+    TA1CCTL0 = 0;
+}
 
 /* -------- SRT-HAL INTERFACE -------- */
 
index cee0483a3128f243d89bcac4a9a65f5337cc26ad..374daf5f9e37b56d745240b3d5b2a5e4e2bb098b 100644 (file)
--- a/Hal/Hal.h
+++ b/Hal/Hal.h
@@ -294,6 +294,7 @@ extern void Hal_redLedToggle(void);
  *
  **/
 extern void Hal_tickStart(uint16_t msecs, Hal_Handler Handler);
+extern void Hal_tickStop(void);
 
 #ifdef __cplusplus
 }
index 62efd73b3e0daa1bb0fa9b26f04bca0238fc0f02..2c3256d849ee1eabac4e03815f8e3f0743585246 100644 (file)
@@ -1,42 +1,86 @@
-#include "Pulsecounter.h"\r
-#include "Hal.h"\r
-\r
-static void buttonHandler(void);\r
-\r
-void main() {\r
-    Hal_init();\r
-    Hal_buttonEnable(buttonHandler);\r
-    Pulsecounter_start();\r
-    Hal_idleLoop();\r
-}\r
-\r
-static void buttonHandler(void) {\r
-    Hal_greenLedOn();\r
-    Hal_redLedOn();\r
-    Hal_delay(500);\r
-    Hal_greenLedOff();\r
-    Hal_redLedOff();\r
-    Pulsecounter_event3_indicate();\r
-}\r
-\r
-/* -------- SCHEMA CALLBACKS -------- */\r
-\r
-void Pulsecounter_connectHandler(void) {\r
-    Hal_connected();\r
-}\r
-\r
-void Pulsecounter_disconnectHandler(void) {\r
-    Hal_disconnected();\r
-}\r
-\r
-void Pulsecounter_event3_fetch(Pulsecounter_event3_t* const output) {\r
-    *output = buttonCnt;\r
-}\r
-\r
-void Pulsecounter_event4_fetch(Pulsecounter_event4_t* const output) {\r
-    *output = 4;\r
-}\r
-\r
-void Pulsecounter_event5_fetch(Pulsecounter_event5_t* const output) {\r
-    *output = 5;\r
-}\r
+#include "Pulsecounter.h"
+#include "Hal.h"
+
+static void buttonHandler(void);
+static void tickHandler(void);
+static bool connected = false;
+
+void main() {
+    Hal_init();
+    Hal_buttonEnable(buttonHandler);
+    Pulsecounter_setDeviceName("PULS-CNTR");
+    Pulsecounter_start();
+    Hal_idleLoop();
+}
+
+static void buttonHandler(void) {
+    uint8_t i;
+
+    if (connected)
+        Pulsecounter_event3_indicate();
+    else
+        Pulsecounter_accept(true);
+    for (i = 0; i < 3; i++) {
+        Hal_greenLedOn();
+        Hal_redLedOn();
+        Hal_delay(100);
+        Hal_greenLedOff();
+        Hal_redLedOff();
+    }
+    Hal_tickStart(5000, tickHandler);
+}
+
+static void tickHandler(void) {
+    uint8_t i;
+
+    Hal_tickStop();
+    if (connected)
+        return;
+    for (i = 0; i < 3; i++) {
+        Hal_greenLedOn();
+        Hal_delay(50);
+        Hal_redLedOn();
+        Hal_delay(50);
+        Hal_redLedOff();
+        Hal_delay(50);
+        Hal_greenLedOff();
+    }
+    Pulsecounter_accept(false);
+}
+
+/* -------- SCHEMA CALLBACKS -------- */
+
+void Pulsecounter_connectHandler(void) {
+    connected = true;
+    Hal_connected();
+    Hal_redLedOn();
+    Hal_delay(100);
+    Hal_redLedOff();
+    Hal_greenLedOn();
+    Hal_delay(100);
+    Hal_greenLedOff();
+}
+
+void Pulsecounter_disconnectHandler(void) {
+    connected = false;
+    Hal_greenLedOn();
+    Hal_delay(100);
+    Hal_greenLedOff();
+    Hal_redLedOn();
+    Hal_delay(100);
+    Hal_redLedOff();
+    Hal_tickStart(5000, tickHandler);
+    Hal_disconnected();
+}
+
+void Pulsecounter_event3_fetch(Pulsecounter_event3_t* const output) {
+    *output = buttonCnt;
+}
+
+void Pulsecounter_event4_fetch(Pulsecounter_event4_t* const output) {
+    *output = 4;
+}
+
+void Pulsecounter_event5_fetch(Pulsecounter_event5_t* const output) {
+    *output = 5;
+}