From 9a6965d62578bc7260c7ba1d4860152721c12ea9 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 19 Aug 2017 16:25:39 -0600 Subject: Extra debouncing in PCINT (don't emit event if push was rejected). Fixed memory error in Baton -- long-press from off didn't restart at moon. Made Momentary and Baton go to sleep while light is off. --- spaghetti-monster/baton.c | 6 ++++-- spaghetti-monster/momentary.c | 20 ++++++-------------- spaghetti-monster/spaghetti-monster.h | 20 +++++++------------- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/spaghetti-monster/baton.c b/spaghetti-monster/baton.c index ea8d49f..02b7c00 100644 --- a/spaghetti-monster/baton.c +++ b/spaghetti-monster/baton.c @@ -48,7 +48,9 @@ uint8_t off_state(EventPtr event, uint16_t arg) { if (event == EV_enter_state) { PWM1_LVL = 0; PWM2_LVL = 0; - // TODO: standby_mode(); + // sleep while off (lower power use) + //empty_event_sequence(); // just in case (but shouldn't be needed) + standby_mode(); return 0; } // hold (initially): go to lowest level, but allow abort for regular click @@ -114,7 +116,7 @@ uint8_t steady_state(EventPtr event, uint16_t arg) { // hold: change brightness else if (event == EV_click1_hold) { if ((arg % HOLD_TIMEOUT) == 0) { - memorized_level = (memorized_level+1) % sizeof(pwm1_modes); + memorized_level = (actual_level+1) % sizeof(pwm1_modes); set_mode(memorized_level); } return 0; diff --git a/spaghetti-monster/momentary.c b/spaghetti-monster/momentary.c index a585152..23cc359 100644 --- a/spaghetti-monster/momentary.c +++ b/spaghetti-monster/momentary.c @@ -44,35 +44,28 @@ uint8_t momentary_state(EventPtr event, uint16_t arg) { if (event == EV_click1_press) { brightness = 255; light_on(); - // don't attempt to parse multiple clicks - empty_event_sequence(); + empty_event_sequence(); // don't attempt to parse multiple clicks return 0; } else if (event == EV_release) { light_off(); - // don't attempt to parse multiple clicks - empty_event_sequence(); + empty_event_sequence(); // don't attempt to parse multiple clicks + standby_mode(); // sleep while light is off return 0; } - else if (event == EV_debug) { - //PWM1_LVL = arg&0xff; - DEBUG_FLASH; - return 0; - } - - // event not handled - return 1; + return 1; // event not handled } // LVP / low-voltage protection void low_voltage() { - debug_blink(3); if (brightness > 0) { + debug_blink(3); brightness >>= 1; if (on_now) light_on(); } else { + debug_blink(8); light_off(); standby_mode(); } @@ -80,6 +73,5 @@ void low_voltage() { void setup() { debug_blink(2); - push_state(momentary_state, 0); } diff --git a/spaghetti-monster/spaghetti-monster.h b/spaghetti-monster/spaghetti-monster.h index cfabea8..fe5e939 100644 --- a/spaghetti-monster/spaghetti-monster.h +++ b/spaghetti-monster/spaghetti-monster.h @@ -240,7 +240,7 @@ void empty_event_sequence() { for(uint8_t i=0; i