]> oss.titaniummirror.com Git - rgblamp.git/blobdiff - main.c
Change MODE_FADE to MODE_CYCLE
[rgblamp.git] / main.c
diff --git a/main.c b/main.c
index 738362cb83d9dc938a6033948c8b67c417fd214f..0f98b6aada831887f1b8be768b02c62071892a44 100644 (file)
--- a/main.c
+++ b/main.c
 #include "task.h"
 #include "adc_random.h"
 
-#if 1
-#define AUTO_OFF_COUNT   450  /* 15 mins on*/
-#define AUTO_ON_COUNT    1350 /* 45 mins off */
-#else
+//#define AUTO_OFF_COUNT   150  /* 5 mins on*/
+//#define AUTO_ON_COUNT    300  /* 10 mins off */
+//#define AUTO_OFF_COUNT   450  /* 15 mins on*/
+//#define AUTO_ON_COUNT    1350 /* 45 mins off */
+//#define AUTO_OFF_COUNT   600  /* 20 mins on*/
+//#define AUTO_ON_COUNT    1200 /* 40 mins off */
+//#define AUTO_OFF_COUNT   450  /* 2 hours on*/
+//#define AUTO_ON_COUNT    1350 /* 22 hours off */
 #define AUTO_OFF_COUNT   9000U  /*  5 hrs in 2 sec units */
 #define AUTO_ON_COUNT    34200U /* 19 hrs in 2 sec units */
-#endif
 #define dbgpin_init()    do { \
                              /* Set RA2 as output low */ \
                              RA2 = 0; \
@@ -65,7 +68,7 @@ enum {
   /* Operating modes */
   MODE_SOLID = 0,        /* Cycle through colors[][] before next mode */
   //MODE_CANDLE,
-  MODE_FADE,             /* Auto cycle through colors */
+  MODE_CYCLE,             /* Auto cycle through colors */
   MODE_PARTY,            /* Random yet fast incolor and fade */
   MODE_COUNT,
 
@@ -79,7 +82,7 @@ enum {
   HELD_TMR_PERIODS = 1,  /* Held timer fires every 32.768 msec */
   HELD_PERIODS = 16,     /* Held this long before held events fire */
   COLOR_WHITE = 0,       /* Color index for white */
-  COLOR_COUNT = 19,
+  COLOR_COUNT = 11,
   BRIGHT_TOP = 100,      /* Bright ramps up to top ... */
   BRIGHT_BOTTOM = -5,    /* ... then down to bottom */
   BRIGHT_MAX = 85,       /* Bright values are constrained for computations */
@@ -88,7 +91,8 @@ enum {
   STD_FADE = 16,         /* Fade time in 32.768 ms units */
   STD_INCOLOR = 29491,   /* Time in color when MODE_FADE, in 32.768 ms units */
   PARTY_MIN = 8,         /* Min party fade and incolor units */
-  PARTY_RANGE = 8,       /* Party fade/incolor range (max = min+range) */
+  PARTY_RANGE = 8,       /* Party fade/incolor range mask for rand() */
+                         /* ... see start_fade() */
 };
 
 typedef struct {
@@ -97,27 +101,19 @@ typedef struct {
   signed char remainder;
 } led_t;
 
-/* 18 available colors plus white, 2 bits per color, no white mix */
+/* Available colors, 6 bits per color (no values above 0x3f) */
 const unsigned char colors[COLOR_COUNT][LED_COUNT] = {
-  { 3, 0, 0, 0 },
-  { 3, 1, 0, 0 },
-  { 3, 2, 0, 0 },
-  { 3, 3, 0, 0 },
-  { 2, 3, 0, 0 },
-  { 1, 3, 0, 0 },
-  { 0, 3, 0, 0 },
-  { 0, 3, 1, 0 },
-  { 0, 3, 2, 0 },
-  { 0, 3, 3, 0 },
-  { 0, 2, 3, 0 },
-  { 0, 1, 3, 0 },
-  { 0, 0, 3, 0 },
-  { 1, 0, 3, 0 },
-  { 2, 0, 3, 0 },
-  { 3, 0, 3, 0 },
-  { 3, 0, 2, 0 },
-  { 3, 0, 1, 0 },
-  { 3, 3, 3, 3 },
+  { 0x28, 0x00, 0x00, 0x00 }, /* red */
+  { 0x30, 0x20, 0x00, 0x00 }, /* orange */
+  { 0x2c, 0x2c, 0x00, 0x00 }, /* yellow */
+  { 0x20, 0x2c, 0x00, 0x00 }, /* yellow-green */
+  { 0x00, 0x30, 0x00, 0x00 }, /* green */
+  { 0x00, 0x30, 0x18, 0x00 }, /* green-cyan */
+  { 0x00, 0x30, 0x28, 0x00 }, /* cyan */
+  { 0x00, 0x18, 0x30, 0x00 }, /* cyan-blue */
+  { 0x00, 0x00, 0x30, 0x00 }, /* blue */
+  { 0x1c, 0x00, 0x30, 0x00 }, /* magenta */
+  { 0x3f, 0x3f, 0x3f, 0x3f }, /* white */
 };
 
 unsigned char mode = MODE_SOLID;
@@ -178,16 +174,16 @@ void start_fade()
   if (mode == MODE_PARTY) {
     color = rand() % COLOR_COUNT;
     fade_steps = PARTY_MIN + (rand() % PARTY_RANGE);
-  } else if (mode == MODE_FADE) {
+  } else if (mode == MODE_CYCLE) {
     if (++color == COLOR_COUNT)
       color = 0;
   }
 
   /* Retrieve the destination color */
-  newr = colors[color][LED_RED] << 8;
-  newg = colors[color][LED_GRN] << 8;
-  newb = colors[color][LED_BLU] << 8;
-  neww = colors[color][LED_WHT] << 8;
+  newr = colors[color][LED_RED] << 4;
+  newg = colors[color][LED_GRN] << 4;
+  newb = colors[color][LED_BLU] << 4;
+  neww = colors[color][LED_WHT] << 4;
 
   /* Compute increment per fade step, and remainder, for each led */
   red.increment = (newr - red.value) / fade_steps;
@@ -324,7 +320,7 @@ void fade_task()
     blu.value += blu.remainder;
     wht.value += wht.remainder;
     tmr_stop(TMR_FADE);
-    if (mode == MODE_FADE)
+    if (mode == MODE_CYCLE)
       tmr_start(TMR_INCOLOR, STD_INCOLOR);
     else if (mode == MODE_PARTY)
       tmr_start(TMR_INCOLOR, PARTY_MIN + (rand() % PARTY_RANGE));