summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2012-06-20 22:13:59 +0200
committerDavid Lamparter <equinox@diac24.net>2012-06-20 22:14:39 +0200
commit6c0e642bd6e6d8697a8a95f167420ecf91bc08b6 (patch)
tree1246d53d06e7f9bb8d9d68ce65a44d535acb32c8
parentcf365fa865d05b263d358f684abd54684005ca17 (diff)
dali: assign shortaddrs
-rw-r--r--dali_ctl.c30
-rw-r--r--lightctrl.c1
2 files changed, 27 insertions, 4 deletions
diff --git a/dali_ctl.c b/dali_ctl.c
index 98e7cef..726387e 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;
+EEMEM uint8_t dali_nextaddr = 0x02;
+static uint8_t dali_assign;
+
static bool dali_compare(void)
{
uint16_t manchester = dalistat.manchester, falsestart = dalistat.falsestart, noise = dalistat.noise;
@@ -76,6 +79,8 @@ static void dali_search(void)
dali_twice(DALI_C_INITIALISE);
// dali_twice(DALI_C_RANDOMISE);
+ dali_assign = eeprom_read_byte(&dali_nextaddr);
+
do {
dali_search_single();
if (!dali_s_notfound) {
@@ -85,16 +90,33 @@ static void dali_search(void)
uart_puthex(dali_sl);
dali_send(DALI_C_QURYSHORT);
if (dali_rx_avail) {
- uart_puts(" short: ");
- uart_puthex(dali_rx);
- uart_puts("\n");
+ if ((dali_rx & 0x81) == 0x01) {
+ uart_puts(" short: ");
+ uart_puthex(dali_rx >> 1);
+ uart_puts("\n");
+ } else {
+ uart_puts(" noshort ");
+
+ dali_send(DALI_C_PROGSHORT | (dali_assign << 1));
+ dali_send(DALI_C_VRFYSHORT | (dali_assign << 1));
+ if (dali_rx_avail) {
+ uart_puts("prog ");
+ uart_puthex(dali_assign);
+ uart_puts("\n");
+ } else
+ uart_puts("progfail\n");
+
+ dali_assign++;
+ }
} else
- uart_puts(" noshort\n");
+ uart_puts(" error\n");
dali_send(DALI_C_WITHDRAW);
}
} while (!dali_s_notfound);
dali_twice(DALI_C_TERMINATE);
uart_puts("dali scan end\n");
+
+ eeprom_write_byte(&dali_nextaddr, dali_assign);
}
diff --git a/lightctrl.c b/lightctrl.c
index ce9117c..79fdeee 100644
--- a/lightctrl.c
+++ b/lightctrl.c
@@ -4,6 +4,7 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
+#include <avr/eeprom.h>
#include <util/delay.h>
const uint8_t __signature[3] __attribute__((section (".signature"), used)) =