X-Git-Url: http://www.average.org/gitweb/?p=pulsecounter.git;a=blobdiff_plain;f=Pulsecounter-Prog.c;h=400bb1d2af5dcae89be4750c3f6cf7bbb913770f;hp=331dbf5366af78b29b9d5f79612c5b24d8132704;hb=7caf44e3ea578f3a0ee113610f433a0e85637d97;hpb=440f8b92b68c9829d1b9ccf274db5f53fb4e0de7 diff --git a/Pulsecounter-Prog.c b/Pulsecounter-Prog.c index 331dbf5..400bb1d 100644 --- a/Pulsecounter-Prog.c +++ b/Pulsecounter-Prog.c @@ -3,11 +3,10 @@ static void gpioHandler(uint8_t id); static void tickHandler(void); +static int32_t cold = 0; +static int32_t hot = 0; static bool connected = false; -static int32_t base4 = 0; -static int32_t base5 = 0; -static int32_t event4 = 0; -static int32_t event5 = 0; +static bool updatable = false; void main() { Hal_init(); @@ -22,26 +21,31 @@ static void gpioHandler(uint8_t id) { switch (id) { case 0: - Pulsecounter_accept(true); - Hal_greenLedOn(); - Hal_redLedOn(); - Hal_delay(10); - Hal_greenLedOff(); - Hal_redLedOff(); - Hal_tickStart(5000, tickHandler); + /* Pulsecounter_accept(true); */ + updatable = true; + if (connected) { + Pulsecounter_coldTick_indicate(); + Pulsecounter_hotTick_indicate(); + } + Hal_greenLedOn(); + Hal_redLedOn(); + Hal_delay(10); + Hal_greenLedOff(); + Hal_redLedOff(); + Hal_tickStart(15000, tickHandler); break; case 1: - event4++; + cold++; if (connected) - Pulsecounter_event4_indicate(); + Pulsecounter_coldTick_indicate(); Hal_greenLedOn(); Hal_delay(10); Hal_greenLedOff(); break; case 2: - event5++; + hot++; if (connected) - Pulsecounter_event5_indicate(); + Pulsecounter_hotTick_indicate(); Hal_redLedOn(); Hal_delay(10); Hal_redLedOff(); @@ -73,7 +77,8 @@ static void tickHandler(void) { Hal_delay(50); Hal_greenLedOff(); } - Pulsecounter_accept(false); + updatable = false; + /* Pulsecounter_accept(false); */ } /* -------- SCHEMA CALLBACKS -------- */ @@ -91,36 +96,31 @@ void Pulsecounter_connectHandler(void) { void Pulsecounter_disconnectHandler(void) { connected = false; + updatable = false; Hal_greenLedOn(); Hal_delay(100); Hal_greenLedOff(); Hal_redLedOn(); Hal_delay(100); Hal_redLedOff(); - Hal_tickStart(5000, tickHandler); + /* Hal_tickStart(15000, tickHandler); */ Hal_disconnected(); } -void Pulsecounter_event4_fetch(Pulsecounter_event4_t* const output) { - *output = base4 + event4; -} - -void Pulsecounter_event5_fetch(Pulsecounter_event5_t* const output) { - *output = base5 + event5; -} - -void Pulsecounter_base4_fetch(Pulsecounter_base4_t* const output) { - *output = base4; +void Pulsecounter_coldTick_fetch(Pulsecounter_coldTick_t* const output) { + *output = cold; } -void Pulsecounter_base4_store(Pulsecounter_base4_t* const input) { - base4 = *input - event4; +void Pulsecounter_hotTick_fetch(Pulsecounter_hotTick_t* const output) { + *output = hot; } -void Pulsecounter_base5_fetch(Pulsecounter_base5_t* const output) { - *output = base5; +void Pulsecounter_coldSet_store(Pulsecounter_coldSet_t* const input) { + if (updatable) + cold = *input; } -void Pulsecounter_base5_store(Pulsecounter_base5_t* const input) { - base5 = *input - event5; +void Pulsecounter_hotSet_store(Pulsecounter_hotSet_t* const input) { + if (updatable) + hot = *input; }