remove extraneous base..
[pulsecounter.git] / Pulsecounter-Prog.c
1 #include "Pulsecounter.h"
2 #include "Hal.h"
3
4 static void gpioHandler(uint8_t id);
5 static void tickHandler(void);
6 static bool connected = false;
7 static int32_t cold = 0;
8 static int32_t hot  = 0;
9
10 void main() {
11     Hal_init();
12     Hal_gpioEnable(gpioHandler);
13     Pulsecounter_setDeviceName("PULS-CNTR");
14     Pulsecounter_start();
15     Hal_idleLoop();
16 }
17
18 static void gpioHandler(uint8_t id) {
19     uint8_t i;
20
21     switch (id) {
22     case 0:
23         Pulsecounter_accept(true);
24             Hal_greenLedOn();
25             Hal_redLedOn();
26             Hal_delay(10);
27             Hal_greenLedOff();
28             Hal_redLedOff();
29         Hal_tickStart(15000, tickHandler);
30         break;
31     case 1:
32         cold++;
33         if (connected)
34             Pulsecounter_coldTick_indicate();
35         Hal_greenLedOn();
36         Hal_delay(10);
37         Hal_greenLedOff();
38         break;
39     case 2:
40         hot++;
41         if (connected)
42             Pulsecounter_hotTick_indicate();
43         Hal_redLedOn();
44         Hal_delay(10);
45         Hal_redLedOff();
46         break;
47     default:
48         for (i = 0; i < 5; i++) {
49             Hal_greenLedOn();
50             Hal_redLedOn();
51             Hal_delay(10);
52             Hal_greenLedOff();
53             Hal_redLedOff();
54             Hal_delay(10);
55         }
56     }
57 }
58
59 static void tickHandler(void) {
60     uint8_t i;
61
62     Hal_tickStop();
63     if (connected)
64         return;
65     for (i = 0; i < 3; i++) {
66         Hal_greenLedOn();
67         Hal_delay(50);
68         Hal_redLedOn();
69         Hal_delay(50);
70         Hal_redLedOff();
71         Hal_delay(50);
72         Hal_greenLedOff();
73     }
74     Pulsecounter_accept(false);
75 }
76
77 /* -------- SCHEMA CALLBACKS -------- */
78
79 void Pulsecounter_connectHandler(void) {
80     connected = true;
81     Hal_connected();
82     Hal_redLedOn();
83     Hal_delay(100);
84     Hal_redLedOff();
85     Hal_greenLedOn();
86     Hal_delay(100);
87     Hal_greenLedOff();
88 }
89
90 void Pulsecounter_disconnectHandler(void) {
91     connected = false;
92     Hal_greenLedOn();
93     Hal_delay(100);
94     Hal_greenLedOff();
95     Hal_redLedOn();
96     Hal_delay(100);
97     Hal_redLedOff();
98     Hal_tickStart(15000, tickHandler);
99     Hal_disconnected();
100 }
101
102 void Pulsecounter_coldTick_fetch(Pulsecounter_coldTick_t* const output) {
103     *output = cold;
104 }
105
106 void Pulsecounter_hotTick_fetch(Pulsecounter_hotTick_t* const output) {
107     *output = hot;
108 }
109
110 void Pulsecounter_coldSet_store(Pulsecounter_coldSet_t* const input) {
111     cold = *input;
112 }
113
114 void Pulsecounter_hotSet_store(Pulsecounter_hotSet_t* const input) {
115     hot = *input;
116 }