diff options
Diffstat (limited to 'dali_ctl.c')
-rw-r--r-- | dali_ctl.c | 36 |
1 files changed, 28 insertions, 8 deletions
@@ -1,3 +1,5 @@ +#define DALI_C_QBALLAST 0x0191 + #define DALI_C_TERMINATE 0xa100 #define DALI_C_DTR 0xa300 #define DALI_C_INITIALISE 0xa500 @@ -16,9 +18,6 @@ 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; @@ -52,6 +51,7 @@ static void dali_search_byte(uint16_t cmd) bit >>= 1; } dali_twice(cmd | dali_s_byte); + uart_puthex(dali_s_byte); } static void dali_search_single(void) @@ -81,6 +81,8 @@ static void dali_search_single(void) static void dali_search(void) { + uint8_t errtries = 0; + dali_twice(DALI_C_INITIALISE); /* _some_ EVGs keep the long address in nonvolatile memory, @@ -92,7 +94,12 @@ static void dali_search(void) dali_assign = eeprom_read_byte(&dali_nextaddr); do { + uint8_t ph = dali_sh, pm = dali_sm, pl = dali_sl; + + uart_puttick(); + uart_puts("dali search... "); dali_search_single(); + uart_puts("\n"); if (!dali_s_notfound) { wdt_reset(); @@ -102,8 +109,12 @@ static void dali_search(void) uart_puthex(dali_sm); uart_puthex(dali_sl); dali_send(DALI_C_QURYSHORT); + if (!dali_rx_avail) + dali_send(DALI_C_QURYSHORT); + wdt_reset(); if (dali_rx_avail) { uint8_t addr = 0xff; + errtries = 0; if ((dali_rx & 0x81) == 0x01) { addr = dali_rx >> 1; @@ -112,7 +123,7 @@ static void dali_search(void) uart_puthex(addr); } - if (addr == 0x00 || (dali_map[addr >> 3] & (1 << (addr & 0x07)))) { + if (addr == 0x00 || target_present(addr)) { uart_puts(" reprog"); addr = 0xff; } @@ -132,12 +143,21 @@ static void dali_search(void) uart_puts("\n"); if (addr < 64) - dali_map[addr >> 3] |= 1 << (addr & 0x7); - } else + target_set_present(addr); + + wdt_reset(); + dali_send(DALI_C_WITHDRAW); + } else { uart_puts(" error\n"); + if (errtries < 3) { + dali_sh = ph; + dali_sm = pm; + dali_sl = pl; + errtries++; + } else + errtries = 0; + } - wdt_reset(); - dali_send(DALI_C_WITHDRAW); } } while (!dali_s_notfound); |