]> oss.titaniummirror.com Git - rgblamp.git/commitdiff
Have 4 speed modes
authorR. Steve McKown <rsmckown@gmail.com>
Tue, 6 Dec 2011 02:50:27 +0000 (19:50 -0700)
committerR. Steve McKown <rsmckown@gmail.com>
Tue, 6 Dec 2011 02:54:52 +0000 (19:54 -0700)
main.c

diff --git a/main.c b/main.c
index b9a8cbcd62de300fa6beb7b91a21f73eab3d710f..9163c1c77e1a32af312c3d7a90e4b6a94eecb52f 100644 (file)
--- a/main.c
+++ b/main.c
                                   while (0)
 #define rand_u8()               (rand() & 0xff)
 #define rand_u16()              ((rand() << 8) + rand_u8())
-#define rand_incolor_steps(f)   (min_incolor_steps[f & 1] + \
-                                    (rand() % range_incolor_steps[f & 1]))
-#define rand_fade_steps(f)      (min_fade_steps[f & 1] + \
-                                    (rand() % range_fade_steps[f & 1]))
+#define rand_incolor_steps(s)   (min_incolor_steps[s & 3] + \
+                                    (rand() % range_incolor_steps[s & 3]))
+#define rand_fade_steps(s)      (min_fade_steps[s & 3] + \
+                                    (rand() % range_fade_steps[s & 3]))
 #define leds_set(r,g,b,w)       rgb_set((r).value >> 7, \
                                   (g).value >> 7, \
-                                  (b).value >> 7, 0)
-//                                  (w).value >> 7)
+                                  (b).value >> 7, \
+                                  (w).value >> 7)
 
 typedef struct {
   int value;
@@ -33,17 +33,17 @@ typedef struct {
 } led_t;
 #define INIT_LED { 0, 0, 0 }
 
-/* The index of all step arrays is the fast variable, 0=slow, 1=fast. */
-#if 0
-const static unsigned min_incolor_steps[2] =   {   320,  32 };
-const static unsigned range_incolor_steps[2] = { 32768, 128 };
-const static int min_fade_steps[2] =           {    64,  32 };
-const static int range_fade_steps[2] =         {   416, 128 };
-#else
-const static unsigned min_incolor_steps[2] =   { 64, 32 };
-const static unsigned range_incolor_steps[2] = {  1,  1 };
-const static int min_fade_steps[2] =           { 64, 32 };
-const static int range_fade_steps[2] =         {  1,  1 };
+/* The index of all step arrays is the speed variable */
+#if 1
+const static unsigned min_incolor_steps[4] =   {   320,  32, 32,  1 };
+const static unsigned range_incolor_steps[4] = { 32768, 128, 32,  8 };
+const static int min_fade_steps[4] =           {    64,  32, 32,  1 };
+const static int range_fade_steps[4] =         {   416, 128, 32,  8 };
+#else /* for debugging */
+const static unsigned min_incolor_steps[4] =   { 64, 32, 16,  8 };
+const static unsigned range_incolor_steps[4] = {  1,  1,  1,  1 };
+const static int min_fade_steps[4] =           { 64, 32, 16,  8 };
+const static int range_fade_steps[4] =         {  1,  1,  1,  1 };
 #endif
 
 int main(void)
@@ -52,7 +52,7 @@ int main(void)
     led_t grn = INIT_LED;
     led_t blu = INIT_LED;
     led_t wht = INIT_LED;
-    unsigned char fast = 0;
+    unsigned char speed = 0;
     unsigned incolor_steps;
     int fade_steps;
 
@@ -68,12 +68,11 @@ int main(void)
         unsigned char buttons = buttons_read();
 
         if ((buttons & (IN_ROCKERA | IN_ROCKERB))) {
-            /* Crappy way to detect rising edges to change state of fast var */
-            if (!(fast & 2) && (buttons & IN_PUSHBTN)) {
-                fast |= 2;
-            } else if ((fast & 2) && !(buttons & IN_PUSHBTN)) {
-                fast &= ~2;
-                fast = 1 - fast;
+            /* Crappy way to detect rising edges to change state of speed var */
+            if (!(speed & 4) && (buttons & IN_PUSHBTN)) {
+                speed |= 4;
+            } else if ((speed & 4) && !(buttons & IN_PUSHBTN)) {
+                speed = (speed + 1) & ~4;
                 reset_steps();
             }
 
@@ -107,8 +106,8 @@ int main(void)
               } while (newr == 0 && newg == 0 && newb == 0 && neww == 0);
 
               /* Next incolor and fade steps */
-              incolor_steps = rand_incolor_steps(fast);
-              fade_steps = (buttons & IN_ROCKERA) ? 1 : rand_fade_steps(fast);
+              incolor_steps = rand_incolor_steps(speed);
+              fade_steps = (buttons & IN_ROCKERA) ? 1 : rand_fade_steps(speed);
 
               /* Compute increment and remainder for each led */
               red.increment = (newr - red.value) / fade_steps;