summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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();