X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=msp430%2FPulsecounter-Prog.c;h=20d8e9d55911f76b11dec891d0b45d63fc7c7492;hb=4f113757dc43e63a616d7719c09ba921df6ee48c;hp=11c704b70f34c05eca71ac6ade732c7d2a8a7e4e;hpb=99ae8d8994b8fc7a9a606b376fa71b27e8a0f472;p=pulsecounter.git diff --git a/msp430/Pulsecounter-Prog.c b/msp430/Pulsecounter-Prog.c index 11c704b..20d8e9d 100644 --- a/msp430/Pulsecounter-Prog.c +++ b/msp430/Pulsecounter-Prog.c @@ -1,23 +1,35 @@ #include "Pulsecounter.h" #include "Hal.h" -static void gpioHandler(uint8_t id); -static void tickHandler(void); +static void settleHandler(uint8_t id); +static void jitterHandler(uint8_t id, uint32_t count); static int32_t cold = 0; static int32_t hot = 0; +static int32_t coldJ = 0; +static int32_t hotJ = 0; static bool connected = false; void main() { Hal_init(); - Hal_gpioEnable(gpioHandler); + Hal_gpioEnable(settleHandler, jitterHandler); Pulsecounter_setDeviceName("PULS-CNTR"); Pulsecounter_start(); Hal_idleLoop(); } -static void gpioHandler(uint8_t id) { +static void blink(uint8_t which, uint8_t count) { uint8_t i; + for (i = 0; i < count; i++) { + if (i) Hal_delay(50); + if (which & 1) Hal_greenLedOn(); + if (which & 2) Hal_redLedOn(); + Hal_delay(50); + if (which & 1) Hal_greenLedOff(); + if (which & 2) Hal_redLedOff(); + } +} +static void settleHandler(uint8_t id) { switch (id) { case 0: /* Pulsecounter_accept(true); */ @@ -26,83 +38,57 @@ static void gpioHandler(uint8_t id) { Hal_delay(100); Pulsecounter_hotTick_indicate(); } - Hal_greenLedOn(); - Hal_redLedOn(); - Hal_delay(10); - Hal_greenLedOff(); - Hal_redLedOff(); - Hal_tickStart(15000, tickHandler); + blink(3, 2); break; case 1: cold++; if (connected) Pulsecounter_coldTick_indicate(); - Hal_greenLedOn(); - Hal_delay(10); - Hal_greenLedOff(); + blink(1, 2); break; case 2: hot++; if (connected) Pulsecounter_hotTick_indicate(); - Hal_redLedOn(); - Hal_delay(10); - Hal_redLedOff(); + blink(2, 2); break; default: - for (i = 0; i < 5; i++) { - Hal_greenLedOn(); - Hal_redLedOn(); - Hal_delay(10); - Hal_greenLedOff(); - Hal_redLedOff(); - Hal_delay(10); - } + blink(3, 15); } } -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(); +static void jitterHandler(uint8_t id, uint32_t count) { + switch (id) { + case 0: + blink(3, count); + break; + case 1: + coldJ = count; + if (connected) + Pulsecounter_coldJitter_indicate(); + blink(1, 1); + break; + case 2: + hotJ = count; + if (connected) + Pulsecounter_hotJitter_indicate(); + blink(2, 1); + break; + default: + blink(3, 13); } - /* Pulsecounter_accept(false); */ } /* -------- SCHEMA CALLBACKS -------- */ void Pulsecounter_connectHandler(void) { connected = true; - Hal_tickStop(); - Hal_connected(); - Hal_redLedOn(); - Hal_delay(100); - Hal_redLedOff(); - Hal_greenLedOn(); - Hal_delay(100); - Hal_greenLedOff(); + blink(1, 5); } void Pulsecounter_disconnectHandler(void) { connected = false; - Hal_greenLedOn(); - Hal_delay(100); - Hal_greenLedOff(); - Hal_redLedOn(); - Hal_delay(100); - Hal_redLedOff(); - /* Hal_tickStart(15000, tickHandler); */ - Hal_disconnected(); + blink(2, 5); } void Pulsecounter_coldTick_fetch(Pulsecounter_coldTick_t* const output) { @@ -112,3 +98,11 @@ void Pulsecounter_coldTick_fetch(Pulsecounter_coldTick_t* const output) { void Pulsecounter_hotTick_fetch(Pulsecounter_hotTick_t* const output) { *output = hot; } + +void Pulsecounter_coldJitter_fetch(Pulsecounter_coldJitter_t* output) { + *output = coldJ; +} + +void Pulsecounter_hotJitter_fetch(Pulsecounter_hotJitter_t* output) { + *output = hotJ; +}