summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2015-01-13 22:37:55 +0100
committerDavid Lamparter <equinox@diac24.net>2015-01-13 22:42:50 +0100
commit455913cca424976c03bc4b87500d69e115b2b517 (patch)
tree8ac09532eb61e875695fa5f19deb554b48aac99a
parent8d52c392f895d1fbc486a8b5b62202be3f7b66ff (diff)
lightctrl_v2: refresh every 30 sec
-rw-r--r--lightctrl_v2.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lightctrl_v2.c b/lightctrl_v2.c
index 5d90850..22dc0b2 100644
--- a/lightctrl_v2.c
+++ b/lightctrl_v2.c
@@ -85,6 +85,8 @@ static void target_set(uint8_t dst, uint8_t val);
#define target_present(addr) devices[addr].present
#define target_set_present(addr) devices[addr].present = 1
+#define REFRESH_TIMER 30 /* seconds */
+
#include "uart.c"
#include "tick.c"
#include "dali2.c"
@@ -113,9 +115,14 @@ static void target_set(uint8_t dst, uint8_t val)
devices[dst].set = val;
}
+static uint8_t refresh_timer = 0;
+
/* irqonly */
static void systick_user_1hz(void)
{
+ if (global_state == G_BOOTING)
+ return;
+
for (uint8_t i = 0; i < DALI_NUMDEV; i++) {
if (!devices[i].cooldown)
continue;
@@ -125,6 +132,20 @@ static void systick_user_1hz(void)
devices[i].need_poweron = NEED_POWERON;
}
}
+ if (refresh_timer)
+ refresh_timer--;
+ else {
+ uart_puts("periodic DALI refresh triggered\n");
+ for (uint8_t i = 0; i < DALI_NUMDEV; i++) {
+ if (!target_present(i))
+ continue;
+ if (devices[i].set)
+ devices[i].need_set |= 1;
+ else
+ devices[i].need_poweroff |= 1;
+ }
+ refresh_timer = REFRESH_TIMER;
+ }
}
/* irqonly */
@@ -501,6 +522,7 @@ int main(void)
DDRD |= (1 << D_LED1) | (1 << D_LED2 ) | (1 << D_TXD) | (1 << D_DALIO);
PORTD |= (1 << D_LED1) | (1 << D_TAST);
PORTD &= ~(1 << D_LED1);
+ refresh_timer = REFRESH_TIMER;
uart_init();
tick_init();