summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lightctrl.c100
1 files changed, 72 insertions, 28 deletions
diff --git a/lightctrl.c b/lightctrl.c
index 66f726a..5b71fff 100644
--- a/lightctrl.c
+++ b/lightctrl.c
@@ -28,6 +28,9 @@ const uint8_t __signature[3] __attribute__((section (".signature"), used)) =
#define D_LED2 6
#define D_TAST 7
+static uint8_t target[0x40] = { 0 };
+static void target_set(uint8_t dst, uint8_t val);
+
#include "uart.c"
#include "tick.c"
#include "dali2.c"
@@ -39,6 +42,35 @@ const uint8_t __signature[3] __attribute__((section (".signature"), used)) =
#define CANA_DALI_BASE 0x440
static uint16_t ctr = 0;
+#define CTR_SENDT 0x1c0
+#define CTR_SENDTARGET 0x1d0
+#define CTR_SENDSTATE 0x200
+#define CTR_SENDEND 0x230
+
+static void target_set(uint8_t dst, uint8_t val)
+{
+ target[dst] = val;
+
+ uart_puts("++ SET ");
+ uart_puthex(dst);
+ uart_puts(" = ");
+ uart_puthex(val);
+ uart_puts("\n");
+
+ if (!val) {
+ dali_send((dst << 9) | 0x100);
+ } else {
+ if (val == 0xff)
+ val = 0xfe;
+
+ dali_send((dst << 9) | 0x108);
+ dali_send((dst << 9) | val);
+ }
+
+ /* clear timer to trigger immediate updates on CAN */
+ if (ctr < CTR_SENDT || ctr >= CTR_SENDEND)
+ ctr = CTR_SENDT;
+}
static void can_handle_light(uint16_t sublab_addr)
{
@@ -54,27 +86,8 @@ static void can_handle_light(uint16_t sublab_addr)
if (dst >= 0x40)
continue;
val = can_rx_data[pos];
- if (val == 0xff)
- val = 0xfe;
-
- uart_puts("++ SET ");
- uart_puthex(dst);
- uart_puts(" = ");
- uart_puthex(val);
- uart_puts("\n");
-
- if (!val) {
- // dim_state = 0;
- dali_send((dst << 9) | 0x100);
- } else {
- // if (!dim_state && can_rx_data[0])
- dali_send((dst << 9) | 0x108);
- dali_send((dst << 9) | val);
- }
+ target_set(dst, val);
}
-
- /* resync clock for immediate ACK */
- ctr = 500;
}
const uint8_t dalidisc_page0[6] PROGMEM = {0x01, 0x01, 0x00, 0x01, 0x00, 0x00};
@@ -245,14 +258,45 @@ int main(void)
case 2048:
ctr = 0;
break;
- case 512:
- case 516:
- case 520:
- case 524:
- case 528:
- case 532:
- case 536:
- case 540:
+
+ case CTR_SENDTARGET + 0:
+ case CTR_SENDTARGET + 4:
+ case CTR_SENDTARGET + 8:
+ case CTR_SENDTARGET + 12:
+ case CTR_SENDTARGET + 16:
+ case CTR_SENDTARGET + 20:
+ case CTR_SENDTARGET + 24:
+ case CTR_SENDTARGET + 28:
+ if (dali_map[(ctr >> 2) & 7]) {
+ uint8_t buffer[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+ uint8_t base = (ctr << 1) & 070, map = dali_map[(ctr >> 2) & 7], dlc = 0;
+
+ uart_puttick();
+ uart_puts("tt");
+ uart_puthex(base);
+ uart_puts("> ");
+
+ for (int i = 0; i < 8; i++)
+ if (map & (1 << i)) {
+ buffer[i] = target[base + i];
+ uart_puthex(dali_rx);
+ uart_puts(" ");
+ dlc = i + 1;
+ } else
+ uart_puts("-- ");
+ uart_puts("\n");
+ can_send(CANA_LIGHT_F(0, CANA_DALI_BASE + base), dlc, buffer);
+ }
+ break;
+
+ case CTR_SENDSTATE + 0:
+ case CTR_SENDSTATE + 4:
+ case CTR_SENDSTATE + 8:
+ case CTR_SENDSTATE + 12:
+ case CTR_SENDSTATE + 16:
+ case CTR_SENDSTATE + 20:
+ case CTR_SENDSTATE + 24:
+ case CTR_SENDSTATE + 28:
if (dali_map[(ctr >> 2) & 7]) {
uint8_t buffer[8] = {0, 0, 0, 0, 0, 0, 0, 0};
uint8_t base = (ctr << 1) & 070, map = dali_map[(ctr >> 2) & 7], dlc = 0;