From ceffd2f8685d34ab4d6ed547553d4d777d77e5dd Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Thu, 6 Jun 2013 23:01:57 +0200 Subject: lightctrl: cooldown timer for DALI EVGs --- lightctrl.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lightctrl.c b/lightctrl.c index e1a4916..443359c 100644 --- a/lightctrl.c +++ b/lightctrl.c @@ -29,6 +29,7 @@ const uint8_t __signature[3] __attribute__((section (".signature"), used)) = #define D_TAST 7 static uint8_t target[0x40] = { 0 }; +static uint8_t cooldown[0x40] = { 0 }; static void target_set(uint8_t dst, uint8_t val); #include "uart.c" @@ -47,6 +48,23 @@ static uint16_t ctr = 0; #define CTR_SENDSTATE 0x200 #define CTR_SENDEND 0x230 +#define T_EVG_COOLDOWN 200 // * 5ms = 1s cooldown after switchoff + +static void target_cooldown(void) +{ + for (uint8_t i = 0; i < 0x40; i++) + if (cooldown[i]) { + cooldown[i]--; + if ((cooldown[i] == 0) && target[i]) { + uint8_t val = target[i]; + if (val == 0xff) + val = 0xfe; + dali_send((i << 9) | 0x108); + dali_send((i << 9) | val); + } + } +} + static void target_set(uint8_t dst, uint8_t val) { target[dst] = val; @@ -59,12 +77,15 @@ static void target_set(uint8_t dst, uint8_t val) if (!val) { dali_send((dst << 9) | 0x100); + cooldown[dst] = T_EVG_COOLDOWN; } else { if (val == 0xff) val = 0xfe; - dali_send((dst << 9) | 0x108); - dali_send((dst << 9) | val); + if (!cooldown[dst]) { + dali_send((dst << 9) | 0x108); + dali_send((dst << 9) | val); + } } /* clear timer to trigger immediate updates on CAN */ @@ -252,6 +273,7 @@ int main(void) _delay_ms(5); do_tick(); + target_cooldown(); ctr++; switch (ctr) { -- cgit v1.2.1