aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/spaghetti-monster.h
diff options
context:
space:
mode:
authorSelene ToyKeeper2017-08-19 16:25:39 -0600
committerSelene ToyKeeper2017-08-19 16:25:39 -0600
commit9a6965d62578bc7260c7ba1d4860152721c12ea9 (patch)
treebf4a69d0c970f032554dbaf28ccb8e48a08e03a1 /spaghetti-monster/spaghetti-monster.h
parentFixed momentary UI (API changed a little). (diff)
downloadanduril-9a6965d62578bc7260c7ba1d4860152721c12ea9.tar.gz
anduril-9a6965d62578bc7260c7ba1d4860152721c12ea9.tar.bz2
anduril-9a6965d62578bc7260c7ba1d4860152721c12ea9.zip
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.
Diffstat (limited to 'spaghetti-monster/spaghetti-monster.h')
-rw-r--r--spaghetti-monster/spaghetti-monster.h20
1 files changed, 7 insertions, 13 deletions
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)