-#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;
+}