--- 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();
}
}