diff options
| author | Selene ToyKeeper | 2017-08-19 15:33:33 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2017-08-19 15:33:33 -0600 |
| commit | ef05435261fac31790303dbff16bcc194e9e5cb5 (patch) | |
| tree | 628e02df8e30e1b4068c076ad14df2b4b3bded02 /spaghetti-monster/spaghetti-monster.h | |
| parent | Added unfinished UI similar to Olight Baton series. (diff) | |
| download | anduril-ef05435261fac31790303dbff16bcc194e9e5cb5.tar.gz anduril-ef05435261fac31790303dbff16bcc194e9e5cb5.tar.bz2 anduril-ef05435261fac31790303dbff16bcc194e9e5cb5.zip | |
Fixed unreliability of short-click detection.
(it was doing stuff like "press, release, release, timeout" so it didn't match "press, release, timeout")
(it may have also been missing the exact tick it needed, so I made it use >= instead of ==, but this is theoretical and harmless if I was wrong)
Made baton mode memory work a bit better for both regular and strobe modes.
Made baton fast strobe pulses shorter for better motion freezing.
Added USE_DELAY_ZERO option as an alternate for USE_FINE_DELAY.
Diffstat (limited to 'spaghetti-monster/spaghetti-monster.h')
| -rw-r--r-- | spaghetti-monster/spaghetti-monster.h | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/spaghetti-monster/spaghetti-monster.h b/spaghetti-monster/spaghetti-monster.h index e51416a..cfabea8 100644 --- a/spaghetti-monster/spaghetti-monster.h +++ b/spaghetti-monster/spaghetti-monster.h @@ -243,8 +243,10 @@ void empty_event_sequence() { void push_event(uint8_t ev_type) { ticks_since_last_event = 0; // something happened uint8_t i; - for(i=0; current_event[i] && (i<EV_MAX_LEN); i++); - if (i < EV_MAX_LEN) { + uint8_t prev_event = 0; // never push the same event twice in a row + for(i=0; current_event[i] && (i<EV_MAX_LEN); i++) + prev_event = current_event[i]; + if ((i < EV_MAX_LEN) && (prev_event != ev_type)) { current_event[i] = ev_type; } else { // TODO: ... something? @@ -418,6 +420,12 @@ 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 @@ -433,6 +441,7 @@ ISR(PCINT0_vect) { // check if sequence matches any defined sequences // if so, send event to current state callback emit_current_event(0); + //lockout = 0; } // clock tick -- this runs every 16ms (62.5 fps) @@ -458,7 +467,7 @@ ISR(WDT_vect) { // user held button long enough to count as a long click? if (last_event == A_PRESS) { - if (ticks_since_last_event == HOLD_TIMEOUT) { + if (ticks_since_last_event >= HOLD_TIMEOUT) { push_event(A_HOLD); emit_current_event(0); } @@ -478,7 +487,7 @@ ISR(WDT_vect) { empty_event_sequence(); } // end and clear event after release timeout - else if (ticks_since_last_event == RELEASE_TIMEOUT) { + else if (ticks_since_last_event >= RELEASE_TIMEOUT) { push_event(A_RELEASE_TIMEOUT); emit_current_event(0); empty_event_sequence(); |
