]> oss.titaniummirror.com Git - rgblamp.git/commitdiff
Use pushbutton rising edge for state change
authorR. Steve McKown <rsmckown@gmail.com>
Tue, 6 Dec 2011 02:39:16 +0000 (19:39 -0700)
committerR. Steve McKown <rsmckown@gmail.com>
Tue, 6 Dec 2011 02:41:41 +0000 (19:41 -0700)
main.c

diff --git a/main.c b/main.c
index f2987998841d0315f00a47114e7fcaae42d5fdee..b9a8cbcd62de300fa6beb7b91a21f73eab3d710f 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] + \
-                                    (rand() % range_incolor_steps[f]))
-#define rand_fade_steps(f)      (min_fade_steps[f] + \
-                                    (rand() % range_fade_steps[f]))
+#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 leds_set(r,g,b,w)       rgb_set((r).value >> 7, \
                                   (g).value >> 7, \
                                   (b).value >> 7, 0)
@@ -40,9 +40,9 @@ 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, 64 };
+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] =           { 32, 32 };
+const static int min_fade_steps[2] =           { 64, 32 };
 const static int range_fade_steps[2] =         {  1,  1 };
 #endif
 
@@ -68,12 +68,13 @@ int main(void)
         unsigned char buttons = buttons_read();
 
         if ((buttons & (IN_ROCKERA | IN_ROCKERB))) {
-            if (buttons & IN_PUSHBTN) {
-              if (!fast) {
-                fast = 1;
+            /* 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;
                 reset_steps();
-              } else
-                fast = 0;
             }
 
             if (fade_steps) {