# HG changeset patch # User Tero Marttila # Date 1398023276 -10800 # Node ID 076657910c0a084e9e27a2da68fbb08932026d6c # Parent 504c2310cddb71844f8e213f7a0fb25f91d97ea7 hello-dmx: limit dmx updates to 2Hz or on commands diff -r 504c2310cddb -r 076657910c0a src/hello-dmx.c --- a/src/hello-dmx.c Sun Apr 20 22:47:41 2014 +0300 +++ b/src/hello-dmx.c Sun Apr 20 22:47:56 2014 +0300 @@ -47,6 +47,18 @@ byte count; } dmx; +/* + * Tick output state + */ +void update () +{ + led_toggle(); + dmx_packet(dmx.count, dmx.out); +} + +/* + * Console input state. + */ enum state { START = '\n', CMD = ';', @@ -56,9 +68,6 @@ #define CONSOLE_ARGS 8 -/* - * Console input state. - */ static struct console { byte state; byte cmd; @@ -266,7 +275,11 @@ if ((ret = command(console.cmd))) { } else { + // success ret = '\n'; + + // commit changes + update(); } // return to START with response @@ -317,14 +330,6 @@ return ERROR; } -/* - * Tick output state - */ -void update () -{ - dmx_packet(dmx.count, dmx.out); -} - void main () { led_init(); @@ -334,27 +339,23 @@ // mainloop char c = '>'; - unsigned timeout = 8000; // 2Hz + unsigned interval = 8000; // 2Hz // start sei(); serial_write(c); + timer1_start(interval); while (true) { - // sleep - //led_on(); - if (timer_sleep(timeout)) { - led_toggle(); + // interval sleep + if (timer_sleep(0)) { + // output + update(); } // input while ((c = serial_read())) { serial_write(input(c)); } - - //led_off(); - - // output - update(); } }