remove unused hal debug funcs
[pulsecounter.git] / msp430 / 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 int32_t cold = 0;
7 static int32_t hot  = 0;
8 static bool connected = false;
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         if (connected) {
25             Pulsecounter_coldTick_indicate();
26             Hal_delay(100);
27             Pulsecounter_hotTick_indicate();
28         }
29         Hal_greenLedOn();
30         Hal_redLedOn();
31         Hal_delay(10);
32         Hal_greenLedOff();
33         Hal_redLedOff();
34         Hal_tickStart(15000, tickHandler);
35         break;
36     case 1:
37         cold++;
38         if (connected)
39             Pulsecounter_coldTick_indicate();
40         Hal_greenLedOn();
41         Hal_delay(10);
42         Hal_greenLedOff();
43         break;
44     case 2:
45         hot++;
46         if (connected)
47             Pulsecounter_hotTick_indicate();
48         Hal_redLedOn();
49         Hal_delay(10);
50         Hal_redLedOff();
51         break;
52     default:
53         for (i = 0; i < 5; i++) {
54             Hal_greenLedOn();
55             Hal_redLedOn();
56             Hal_delay(10);
57             Hal_greenLedOff();
58             Hal_redLedOff();
59             Hal_delay(10);
60         }
61     }
62 }
63
64 static void tickHandler(void) {
65     uint8_t i;
66
67     Hal_tickStop();
68     if (connected)
69         return;
70     for (i = 0; i < 3; i++) {
71         Hal_greenLedOn();
72         Hal_delay(50);
73         Hal_redLedOn();
74         Hal_delay(50);
75         Hal_redLedOff();
76         Hal_delay(50);
77         Hal_greenLedOff();
78     }
79     /* Pulsecounter_accept(false); */
80 }
81
82 /* -------- SCHEMA CALLBACKS -------- */
83
84 void Pulsecounter_connectHandler(void) {
85     connected = true;
86     Hal_tickStop();
87     Hal_connected();
88     Hal_redLedOn();
89     Hal_delay(100);
90     Hal_redLedOff();
91     Hal_greenLedOn();
92     Hal_delay(100);
93     Hal_greenLedOff();
94 }
95
96 void Pulsecounter_disconnectHandler(void) {
97     connected = false;
98     Hal_greenLedOn();
99     Hal_delay(100);
100     Hal_greenLedOff();
101     Hal_redLedOn();
102     Hal_delay(100);
103     Hal_redLedOff();
104     /* Hal_tickStart(15000, tickHandler); */
105     Hal_disconnected();
106 }
107
108 void Pulsecounter_coldTick_fetch(Pulsecounter_coldTick_t* const output) {
109     *output = cold;
110 }
111
112 void Pulsecounter_hotTick_fetch(Pulsecounter_hotTick_t* const output) {
113     *output = hot;
114 }