]> oss.titaniummirror.com Git - rgblamp.git/blobdiff - main.c
Misc fixes; close now
[rgblamp.git] / main.c
diff --git a/main.c b/main.c
index 637879f2cab0c18349df39617866dc8eea61c4fe..e4ef0f0ca52af3680129fe9d4322936a5109d280 100644 (file)
--- a/main.c
+++ b/main.c
@@ -32,8 +32,8 @@
 #include "btn.h"
 #include "rgb.h"
 #include "tmr.h"
-#include "adc_random.h"
 #include "task.h"
+#include "adc_random.h"
 
 #if 0
 #define AUTO_OFF_COUNT          549316UL  /*  5 hrs in 32.768 ms units */
@@ -125,11 +125,12 @@ void turnOn()
 {
   dbgpin_high();
   on = 1;
-  rgb_on();
   red.value = 0;
   grn.value = 0;
   blu.value = 0;
   wht.value = 0;
+  leds_set(red, grn, blu, wht);
+  rgb_on();
   start_fade();
 }
 
@@ -189,16 +190,16 @@ void fade_task()
   leds_set(red, grn, blu, wht);
 }
 
-void auto_onoff_task()
+void auto_offon_task()
 {
   if (on) {
     turnOff();
     if (btn_rs() == BTN_RS_RIGHT)
-      tmr_start(TMR_AUTO_OFFON, AUTO_OFF_COUNT);
+      tmr_start(TMR_AUTO_OFFON, AUTO_ON_COUNT);
   } else /* off */ {
     turnOn();
     if (btn_rs() == BTN_RS_RIGHT)
-      tmr_start(TMR_AUTO_OFFON, AUTO_ON_COUNT);
+      tmr_start(TMR_AUTO_OFFON, AUTO_OFF_COUNT);
   }
 }
 
@@ -214,7 +215,7 @@ void user_tasks(unsigned char block)
 {
   task_id_t tid;
 
-  while ((tid = task_get(block))) {
+  while ((tid = task_get(block)) >= 0) {
     switch (tid) {
       case TASK_BTN_PB:         /* pushbutton state change */
         pb_task();
@@ -229,7 +230,7 @@ void user_tasks(unsigned char block)
         start_fade();
         break;
       case TASK_AUTO_OFFON:     /* auto on/off timer has fired */
-        auto_onoff_task();
+        auto_offon_task();
         break;
     }
   }
@@ -237,6 +238,7 @@ void user_tasks(unsigned char block)
 
 int main(void)
 {
+  /* Platform initialization */
   pic_init();
   unused_init();
   btn_init();
@@ -264,5 +266,8 @@ int main(void)
 
   /* Process tasks forever */
   user_tasks(1);
+
+  /* Prevent return from main, which causes a device reset */
+  while (1);
 }