diff options
| author | Selene ToyKeeper | 2019-11-14 19:47:49 -0700 |
|---|---|---|
| committer | Selene ToyKeeper | 2019-11-14 19:47:49 -0700 |
| commit | 5362c032fdca4b20af49db0409a03524a396b815 (patch) | |
| tree | 1d437085b5b3472279167aee905385e39a4a1fe1 /spaghetti-monster/fsm-pcint.c | |
| parent | merged from fsm branch to get safety ramp-down and version check functions, a... (diff) | |
| parent | merged irq-refactor branch, which fixes some small but long-standing issues: (diff) | |
| download | anduril-5362c032fdca4b20af49db0409a03524a396b815.tar.gz anduril-5362c032fdca4b20af49db0409a03524a396b815.tar.bz2 anduril-5362c032fdca4b20af49db0409a03524a396b815.zip | |
merged fsm updates / irq-refactor branch, to get more stable voltage readings
(and otherwise get recent bugfixes)
Diffstat (limited to 'spaghetti-monster/fsm-pcint.c')
| -rw-r--r-- | spaghetti-monster/fsm-pcint.c | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/spaghetti-monster/fsm-pcint.c b/spaghetti-monster/fsm-pcint.c index 4928980..a4a496a 100644 --- a/spaghetti-monster/fsm-pcint.c +++ b/spaghetti-monster/fsm-pcint.c @@ -24,19 +24,9 @@ #include <util/delay_basic.h> uint8_t button_is_pressed() { - // remember the past 32 measurements - static uint32_t readings = 0; - // take at least one new measurement, - // and wait for measurements to settle to all zeroes or all ones - do { - // shift past readings and add current value - readings = (readings << 1) | ((SWITCH_PORT & (1<<SWITCH_PIN)) == 0); - // wait a moment - _delay_loop_2(BOGOMIPS/16); // up to 2ms to stabilize - } - while ((readings != 0) && (readings != 0xFFFFFFFF)); - button_last_state = readings; - return readings; + uint8_t value = ((SWITCH_PORT & (1<<SWITCH_PIN)) == 0); + button_last_state = value; + return value; } inline void PCINT_on() { @@ -75,7 +65,10 @@ inline void PCINT_off() { //void button_change_interrupt() { #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85) || (ATTINY == 1634) -EMPTY_INTERRUPT(PCINT0_vect); +//EMPTY_INTERRUPT(PCINT0_vect); +ISR(PCINT0_vect) { + irq_pcint = 1; +} #else #error Unrecognized MCU type #endif |
