From cf365fa865d05b263d358f684abd54684005ca17 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 20 Jun 2012 21:30:15 +0200 Subject: dali: better scan behaviour --- dali_ctl.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'dali_ctl.c') diff --git a/dali_ctl.c b/dali_ctl.c index b1502d4..98e7cef 100644 --- a/dali_ctl.c +++ b/dali_ctl.c @@ -18,9 +18,15 @@ static bool dali_s_notfound; static bool dali_compare(void) { + uint16_t manchester = dalistat.manchester, falsestart = dalistat.falsestart, noise = dalistat.noise; + dali_send(DALI_C_COMPARE); asm volatile ("" ::: "memory"); - return dali_rx_avail && dali_rx == 0xff; + + return dali_rx_avail + || (manchester != dalistat.manchester) + || (falsestart != dalistat.falsestart) + || (noise != dalistat.noise); } static void dali_search_byte(uint16_t cmd) @@ -31,9 +37,9 @@ static void dali_search_byte(uint16_t cmd) while (bit) { dali_twice(cmd | (dali_s_byte & ~bit)); if (dali_compare()) { - dali_s_byte &= ~bit; - } else if (dali_compare()) { - dali_s_byte &= ~bit; + _delay_ms(1); + if (dali_compare()) + dali_s_byte &= ~bit; } bit >>= 1; } @@ -68,7 +74,7 @@ static void dali_search_single(void) static void dali_search(void) { dali_twice(DALI_C_INITIALISE); - dali_twice(DALI_C_RANDOMISE); + // dali_twice(DALI_C_RANDOMISE); do { dali_search_single(); -- cgit v1.2.1