From: R. Steve McKown Date: Tue, 6 Dec 2011 02:39:16 +0000 (-0700) Subject: Use pushbutton rising edge for state change X-Git-Tag: 1.0~60 X-Git-Url: https://oss.titaniummirror.com/gitweb?p=rgblamp.git;a=commitdiff_plain;h=abb51a86d7e6cc789f84c35694c0bff042e46a48 Use pushbutton rising edge for state change --- diff --git a/main.c b/main.c index f298799..b9a8cbc 100644 --- a/main.c +++ b/main.c @@ -17,10 +17,10 @@ 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) {