summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2013-06-06 23:01:57 +0200
committerDavid Lamparter <equinox@diac24.net>2013-06-06 23:01:57 +0200
commitceffd2f8685d34ab4d6ed547553d4d777d77e5dd (patch)
treec314f24139b57c9591fb4f0f08c81daf7c031d0e
parent10515a80e2ba88b54c7c8766a0c42c5082985c90 (diff)
lightctrl: cooldown timer for DALI EVGs
-rw-r--r--lightctrl.c26
1 files 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) {