aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2017-12-11 19:56:15 -0700
committerSelene ToyKeeper2017-12-11 19:56:15 -0700
commitd50c46d08a6d7f52dffb9b43784c62b11d78df8c (patch)
treeba93cc6fa1d3f681e850d57ed92721e859b4ff30 /spaghetti-monster
parentWorking toward a FW3A release now. Made strobes use Nx7135 (when available) ... (diff)
downloadanduril-d50c46d08a6d7f52dffb9b43784c62b11d78df8c.tar.gz
anduril-d50c46d08a6d7f52dffb9b43784c62b11d78df8c.tar.bz2
anduril-d50c46d08a6d7f52dffb9b43784c62b11d78df8c.zip
Greatly improved button debouncing. Helps a lot on FW3A and my light saber.
Debouncing isn't 100% yet though.
Diffstat (limited to 'spaghetti-monster')
-rw-r--r--spaghetti-monster/fsm-pcint.c25
-rw-r--r--spaghetti-monster/fsm-pcint.h5
-rw-r--r--spaghetti-monster/fsm-standby.c1
-rw-r--r--spaghetti-monster/fsm-wdt.c33
4 files changed, 57 insertions, 7 deletions
diff --git a/spaghetti-monster/fsm-pcint.c b/spaghetti-monster/fsm-pcint.c
index 763c1fe..c04375a 100644
--- a/spaghetti-monster/fsm-pcint.c
+++ b/spaghetti-monster/fsm-pcint.c
@@ -59,10 +59,25 @@ ISR(PCINT0_vect) {
//DEBUG_FLASH;
- uint8_t pushed;
+ /*
+ uint8_t pressed;
// add event to current sequence
- if (button_is_pressed()) {
+ pressed = button_is_pressed();
+ PCINT_inner(pressed);
+ */
+ if (! PCINT_since_WDT) {
+ PCINT_since_WDT = 1;
+ PCINT_inner(button_is_pressed());
+ }
+}
+
+// should only be called from PCINT and WDT
+// (is a separate function to reduce code duplication)
+void PCINT_inner(uint8_t pressed) {
+ uint8_t pushed;
+
+ if (pressed) {
pushed = push_event(A_PRESS);
} else {
pushed = push_event(A_RELEASE);
@@ -70,7 +85,9 @@ ISR(PCINT0_vect) {
// check if sequence matches any defined sequences
// if so, send event to current state callback
- if (pushed) emit_current_event(0);
+ if (pushed) {
+ button_last_state = pressed;
+ emit_current_event(0);
+ }
}
-
#endif
diff --git a/spaghetti-monster/fsm-pcint.h b/spaghetti-monster/fsm-pcint.h
index cda5ad7..a94fc82 100644
--- a/spaghetti-monster/fsm-pcint.h
+++ b/spaghetti-monster/fsm-pcint.h
@@ -21,9 +21,12 @@
#define FSM_PCINT_H
//static volatile uint8_t button_was_pressed;
-#define BP_SAMPLES 16
+#define BP_SAMPLES 32
+volatile uint8_t button_last_state;
+volatile uint8_t PCINT_since_WDT;
uint8_t button_is_pressed();
inline void PCINT_on();
inline void PCINT_off();
+void PCINT_inner(uint8_t pressed);
#endif
diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c
index 5ef666f..eb631d6 100644
--- a/spaghetti-monster/fsm-standby.c
+++ b/spaghetti-monster/fsm-standby.c
@@ -37,6 +37,7 @@ void sleep_until_eswitch_pressed()
// make sure switch isn't currently pressed
while (button_is_pressed()) {}
empty_event_sequence(); // cancel pending input on suspend
+ PCINT_since_WDT = 0; // ensure PCINT won't ignore itself
PCINT_on(); // wake on e-switch event
diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c
index 7cbe0d2..bee2914 100644
--- a/spaghetti-monster/fsm-wdt.c
+++ b/spaghetti-monster/fsm-wdt.c
@@ -50,13 +50,42 @@ ISR(WDT_vect) {
ticks_since_last_event = (ticks_since_last_event + 1) \
| (ticks_since_last_event & 0x8000);
+ // just in case the pin change interrupt missed something
+ uint8_t le_num = last_event_num();
+ uint8_t last_event = 0;
+ if (le_num >= 1) last_event = current_event[le_num-1];
+ uint8_t pressed = button_is_pressed();
+ uint8_t was_pressed_before = (last_event == A_PRESS) || (last_event == A_HOLD);
+ //if (pressed != button_last_state) {
+ if (pressed != was_pressed_before) {
+ PCINT_inner(pressed);
+ /*
+ uint8_t pushed;
+ if (pressed) {
+ pushed = push_event(A_PRESS);
+ } else {
+ pushed = push_event(A_RELEASE);
+ }
+
+ // check if sequence matches any defined sequences
+ // if so, send event to current state callback
+ if (pushed) {
+ button_last_state = pressed;
+ emit_current_event(0);
+ }
+ */
+ }
+ PCINT_since_WDT = 0;
+
// if time since last event exceeds timeout,
// append timeout to current event sequence, then
// send event to current state callback
// preload recent events
- uint8_t le_num = last_event_num();
- uint8_t last_event = 0;
+ //uint8_t le_num = last_event_num();
+ le_num = last_event_num();
+ //uint8_t last_event = 0;
+ last_event = 0;
uint8_t prev_event = 0;
if (le_num >= 1) last_event = current_event[le_num-1];
if (le_num >= 2) prev_event = current_event[le_num-2];
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.