diff options
author | David Lamparter <equinox@diac24.net> | 2012-09-19 19:34:04 +0200 |
---|---|---|
committer | David Lamparter <equinox@diac24.net> | 2012-09-19 19:34:24 +0200 |
commit | 459e4d4f9b264ac2135c59a4156196f362a81db1 (patch) | |
tree | 82e632ab00126f83ca9d226eb4f9bf43f95da9f6 | |
parent | 9e4d3410b676e101d5b63a1b2ec52d2577af84d0 (diff) |
light: dyn. size CAN out packets, change addr
-rw-r--r-- | lightctrl.c | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/lightctrl.c b/lightctrl.c index 6701a66..9e8d234 100644 --- a/lightctrl.c +++ b/lightctrl.c @@ -32,19 +32,33 @@ static void can_rx_exec(void) { if (can_rx_addr.b[0] == 0xcc && (can_rx_addr.b[1] & 0xfb) == 0x08 - && can_rx_addr.b[2] == 0x04 - && can_rx_addr.b[3] == 0x7f - && (can_rx_dlc & 0x4f) == 1) { - uart_puts("-- SET\n"); - - if (!can_rx_data[0]) { - dim_state = 0; - dali_send(DALI_ADDR | 0x100); - } else { - if (!dim_state && can_rx_data[0]) - dali_send(DALI_ADDR | 0x108); - dim_state = can_rx_data[0]; - dali_send(DALI_ADDR | dim_state); + && can_rx_addr.b[2] == 0x04) { + + uint8_t base = can_rx_addr.b[3], len = can_rx_dlc & 0x4f, pos; + + for (pos = 0; pos < len; pos++) { + uint8_t dst = base + pos, val; + if (dst < 0x40 || dst >= 0x80) + continue; + dst -= 0x40; + 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); + } } } } @@ -101,7 +115,7 @@ int main(void) 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]; + uint8_t base = (ctr << 1) & 070, map = dali_map[(ctr >> 2) & 7], dlc = 0; uart_puts("ll"); uart_puthex(base); @@ -116,10 +130,11 @@ int main(void) uart_puts(" "); } else uart_puts("EE "); + dlc = i + 1; } else uart_puts("-- "); uart_puts("\n"); - can_send(0xe6080400 + base, 8, buffer); + can_send(0xe6080440 + base, dlc, buffer); } break; case 1024: |