diff options
| -rw-r--r-- | spaghetti-monster/baton.c | 6 | ||||
| -rw-r--r-- | spaghetti-monster/momentary.c | 20 | ||||
| -rw-r--r-- | 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<EV_MAX_LEN; i++) current_event[i] = 0; } -void push_event(uint8_t ev_type) { +uint8_t push_event(uint8_t ev_type) { ticks_since_last_event = 0; // something happened uint8_t i; uint8_t prev_event = 0; // never push the same event twice in a row @@ -248,9 +248,11 @@ void push_event(uint8_t ev_type) { prev_event = current_event[i]; if ((i < EV_MAX_LEN) && (prev_event != ev_type)) { current_event[i] = ev_type; + return 1; // event pushed } else { // TODO: ... something? } + return 0; // no event pushed } // find and return last action in the current event sequence @@ -420,28 +422,20 @@ uint8_t button_is_pressed() { //void button_change_interrupt() { ISR(PCINT0_vect) { - // this interrupt should not be re-entrant - //static volatile uint8_t lockout = 0; - - //if (lockout) return; - //lockout = 1; - //DEBUG_FLASH; - // something happened - //ticks_since_last_event = 0; + uint8_t pushed; // add event to current sequence if (button_is_pressed()) { - push_event(A_PRESS); + pushed = push_event(A_PRESS); } else { - push_event(A_RELEASE); + pushed = push_event(A_RELEASE); } // check if sequence matches any defined sequences // if so, send event to current state callback - emit_current_event(0); - //lockout = 0; + if (pushed) emit_current_event(0); } // clock tick -- this runs every 16ms (62.5 fps) |
