completely redid PWM: Now calculate 'microprograms', i.e. pairs of
[moodlight.git] / main.c
diff --git a/main.c b/main.c
index 5e9fb2220793c5d30ceb9d2433888a70a1463bd2..05d4b6b8259968c631c1274fb8dd357d55515bdf 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.4 2010/06/30 19:39:28 simimeie Exp $
+/* $Id: main.c,v 1.8 2010/07/25 20:40:44 simimeie Exp $
  * Main file for the HaWo moodlight.
  * This is the main file that glues it all together. It also contains all
  * functionality that is too small to require an extra file.
 #include "ledpwm.h"
 #include "ircontrol.h"
 #include "timers.h"
-/* #include "eepromdata.h" */
-
-uint8_t mcusr_mirror __attribute__ ((section (".noinit")));
-
-/* This is needed to recover from a watchdog reset, as the watchdog
- * stays active after the reset.
- * The variable is just to make the reason of the last reset accessible
- * later. */
-void get_mcusr(void) __attribute__((naked)) __attribute__((section(".init3")));
-void get_mcusr(void) {
-  mcusr_mirror = MCUSR;
-  MCUSR = 0;
-  wdt_disable();
-}
+#include "ledframing.h"
+#include "rfm12.h"
+#include "eepromdata.h"
 
 #define IRSTATE_RED       1
 #define IRSTATE_GREEN     2
@@ -44,15 +33,15 @@ int main(void)
   uint8_t irstate = 0;
   
   /* Load settings from EEPROM */
-#if 0
-  something = eeprom_read_byte(&ee_something);
-#endif /* LEDMODULE */
+  ledpwm_bri = eeprom_read_byte(&ee_defledbrightness);
 
   /* Initialize stuff */
   console_init();
   timers_init();
   ledpwm_init();
+  ledframing_init();
   ircontrol_init();
+  rfm12_init();
   
   wdt_enable(WDTO_2S);
 
@@ -63,13 +52,6 @@ int main(void)
   /* All set up, enable interrupts and go. */
   sei();
   
-  if (mcusr_mirror & _BV(WDRF)) {
-    console_printpgm_P(PSTR("NOTE: last reset was from Watchdog Timer."));
-  }
-  if (mcusr_mirror & _BV(BORF)) {
-    console_printpgm_P(PSTR("NOTE: last reset was from Brownout."));
-  }
-  
   while (1) { /* We should never exit */
     wdt_reset();
     uint8_t k = ircontrol_getlastcommand();
@@ -97,6 +79,12 @@ int main(void)
                    if (ledpwm_bri > 0) { ledpwm_bri--; }
                  }
                  break;
+      case 0x02: /* "Off" */
+                 ledpwm_bri = 0;
+                 break;
+      case 0x03: /* "On" */
+                 ledpwm_bri = 128;
+                 break;
       case 0x04: /* Red */
                  if (irstate == IRSTATE_RED) {
                    ledpwm_re = 0xff; ledpwm_gr = 0; ledpwm_bl = 0;
@@ -133,22 +121,52 @@ int main(void)
                  ledpwm_re = 0xff; ledpwm_gr = 0x40; ledpwm_bl = 0x00;
                  irstate = 0;
                  break;
+      case 0x09: /* greenish cyan */
+                 ledpwm_re = 0x00; ledpwm_gr = 0xff; ledpwm_bl = 0x80;
+                 irstate = 0;
+                 break;
+      case 0x0a: /* dark blue */
+                 ledpwm_re = 0x20; ledpwm_gr = 0x00; ledpwm_bl = 0xff;
+                 irstate = 0;
+                 break;
       case 0x0c: /* orange */
                  ledpwm_re = 0xff; ledpwm_gr = 0x80; ledpwm_bl = 0x00;
                  irstate = 0;
                  break;
+      case 0x0d: /* cyan */
+                 ledpwm_re = 0x00; ledpwm_gr = 0xff; ledpwm_bl = 0xff;
+                 irstate = 0;
+                 break;
+      case 0x0e: /* dark orchid 2 */
+                 ledpwm_re = 0x50; ledpwm_gr = 0x00; ledpwm_bl = 0xff;
+                 irstate = 0;
+                 break;
       case 0x10: /* bright orange */
                  ledpwm_re = 0xff; ledpwm_gr = 0xc0; ledpwm_bl = 0x00;
                  irstate = 0;
                  break;
+      case 0x11: /* blueish cyan */
+                 ledpwm_re = 0x00; ledpwm_gr = 0xa0; ledpwm_bl = 0xff;
+                 irstate = 0;
+                 break;
+      case 0x12: /* dark orchid */
+                 ledpwm_re = 0xc0; ledpwm_gr = 0x00; ledpwm_bl = 0xff;
+                 irstate = 0;
+                 break;
       case 0x14: /* yellow */
                  ledpwm_re = 0xff; ledpwm_gr = 0xff; ledpwm_bl = 0x00;
                  irstate = 0;
                  break;
+      case 0x15: /* blueerish cyan */
+                 ledpwm_re = 0x00; ledpwm_gr = 0x60; ledpwm_bl = 0xff;
+                 irstate = 0;
+                 break;
+      case 0x16: /* violet */
+                 ledpwm_re = 0xff; ledpwm_gr = 0x00; ledpwm_bl = 0xff;
+                 irstate = 0;
+                 break;
       };
-      ledpwm_setled(LEDPWM_REDLED,   (((uint16_t)ledpwm_re * ledpwm_bri) / 255));
-      ledpwm_setled(LEDPWM_GREENLED, (((uint16_t)ledpwm_gr * ledpwm_bri) / 255));
-      ledpwm_setled(LEDPWM_BLUELED,  (((uint16_t)ledpwm_bl * ledpwm_bri) / 255));
+      ledpwm_set(ledpwm_re, ledpwm_gr, ledpwm_bl, ledpwm_bri);
     }
     /* i++;
     console_printhex8(i);
This page took 0.058528 seconds and 4 git commands to generate.