summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dali_ctl.c13
-rw-r--r--lightctrl.c35
2 files changed, 40 insertions, 8 deletions
diff --git a/dali_ctl.c b/dali_ctl.c
index 726387e..797f58f 100644
--- a/dali_ctl.c
+++ b/dali_ctl.c
@@ -16,6 +16,9 @@
static uint8_t dali_s_byte, dali_sh, dali_sm, dali_sl;
static bool dali_s_notfound;
+/* [0] bit 0 => addr 0, [0] bit 1 => addr 1, etc. */
+static uint8_t dali_map[8];
+
EEMEM uint8_t dali_nextaddr = 0x02;
static uint8_t dali_assign;
@@ -90,9 +93,13 @@ static void dali_search(void)
uart_puthex(dali_sl);
dali_send(DALI_C_QURYSHORT);
if (dali_rx_avail) {
+ uint8_t addr = 0xff;
+
if ((dali_rx & 0x81) == 0x01) {
+ addr = dali_rx >> 1;
+
uart_puts(" short: ");
- uart_puthex(dali_rx >> 1);
+ uart_puthex(addr);
uart_puts("\n");
} else {
uart_puts(" noshort ");
@@ -106,8 +113,12 @@ static void dali_search(void)
} else
uart_puts("progfail\n");
+ addr = dali_assign;
dali_assign++;
}
+
+ if (addr < 64)
+ dali_map[addr >> 3] |= 1 << (addr & 0x7);
} else
uart_puts(" error\n");
dali_send(DALI_C_WITHDRAW);
diff --git a/lightctrl.c b/lightctrl.c
index 79fdeee..cc9a686 100644
--- a/lightctrl.c
+++ b/lightctrl.c
@@ -89,14 +89,35 @@ int main(void)
ctr = 0;
break;
case 512:
- dali_send(0xffa0);
- if (dali_rx_avail) {
- uart_puts("ll ");
- uart_puthex(dali_rx);
+ case 516:
+ case 520:
+ case 524:
+ case 528:
+ case 532:
+ case 536:
+ case 540:
+ 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];
+
+ uart_puts("ll");
+ uart_puthex(base);
+ uart_puts("> ");
+
+ for (int i = 0; i < 8; i++)
+ if (map & (1 << i)) {
+ dali_send(0x1a0 | ((base + i) << 9));
+ if (dali_rx_avail) {
+ buffer[i] = dali_rx;
+ uart_puthex(dali_rx);
+ uart_puts(" ");
+ } else
+ uart_puts("EE ");
+ } else
+ uart_puts("-- ");
uart_puts("\n");
- can_send(0xe608047f, 1, (uint8_t *)&dali_rx);
- } else
- uart_puts("ll noans\n");
+ can_send(0xe6080400 + base, 8, buffer);
+ }
break;
case 1024:
can_send(0xe7000000, 8, (uint8_t *)&dalistat);