add some timer
[pulsecounter.git] / Pulsecounter-Prog.c
1 #include "Pulsecounter.h"
2 #include "Hal.h"
3
4 static void buttonHandler(void);
5 static void tickHandler(void);
6 static bool connected = false;
7
8 void main() {
9     Hal_init();
10     Hal_buttonEnable(buttonHandler);
11     Pulsecounter_setDeviceName("PULS-CNTR");
12     Pulsecounter_start();
13     Hal_idleLoop();
14 }
15
16 static void buttonHandler(void) {
17     uint8_t i;
18
19     if (connected)
20         Pulsecounter_event3_indicate();
21     else
22         Pulsecounter_accept(true);
23     for (i = 0; i < 3; i++) {
24         Hal_greenLedOn();
25         Hal_redLedOn();
26         Hal_delay(100);
27         Hal_greenLedOff();
28         Hal_redLedOff();
29     }
30     Hal_tickStart(5000, tickHandler);
31 }
32
33 static void tickHandler(void) {
34     uint8_t i;
35
36     Hal_tickStop();
37     if (connected)
38         return;
39     for (i = 0; i < 3; i++) {
40         Hal_greenLedOn();
41         Hal_delay(50);
42         Hal_redLedOn();
43         Hal_delay(50);
44         Hal_redLedOff();
45         Hal_delay(50);
46         Hal_greenLedOff();
47     }
48     Pulsecounter_accept(false);
49 }
50
51 /* -------- SCHEMA CALLBACKS -------- */
52
53 void Pulsecounter_connectHandler(void) {
54     connected = true;
55     Hal_connected();
56     Hal_redLedOn();
57     Hal_delay(100);
58     Hal_redLedOff();
59     Hal_greenLedOn();
60     Hal_delay(100);
61     Hal_greenLedOff();
62 }
63
64 void Pulsecounter_disconnectHandler(void) {
65     connected = false;
66     Hal_greenLedOn();
67     Hal_delay(100);
68     Hal_greenLedOff();
69     Hal_redLedOn();
70     Hal_delay(100);
71     Hal_redLedOff();
72     Hal_tickStart(5000, tickHandler);
73     Hal_disconnected();
74 }
75
76 void Pulsecounter_event3_fetch(Pulsecounter_event3_t* const output) {
77     *output = buttonCnt;
78 }
79
80 void Pulsecounter_event4_fetch(Pulsecounter_event4_t* const output) {
81     *output = 4;
82 }
83
84 void Pulsecounter_event5_fetch(Pulsecounter_event5_t* const output) {
85     *output = 5;
86 }