aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2017-08-19 16:25:39 -0600
committerSelene ToyKeeper2017-08-19 16:25:39 -0600
commit9a6965d62578bc7260c7ba1d4860152721c12ea9 (patch)
treebf4a69d0c970f032554dbaf28ccb8e48a08e03a1
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.
-rw-r--r--spaghetti-monster/baton.c6
-rw-r--r--spaghetti-monster/momentary.c20
-rw-r--r--spaghetti-monster/spaghetti-monster.h20
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)
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.