diff options
| author | Selene ToyKeeper | 2018-06-17 19:40:38 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2018-06-17 19:40:38 -0600 |
| commit | 3dcfc924bf18c48b76f4b950471160436fddb316 (patch) | |
| tree | f3a7c80d8a2cdb116f3217d6750f6a7faf0852d5 | |
| parent | Implemented halfsleep mode. (diff) | |
| download | anduril-3dcfc924bf18c48b76f4b950471160436fddb316.tar.gz anduril-3dcfc924bf18c48b76f4b950471160436fddb316.tar.bz2 anduril-3dcfc924bf18c48b76f4b950471160436fddb316.zip | |
Changed halfsleep mode to TICK_DURING_STANDBY. Added blinking indicator LED support to Anduril.
| -rw-r--r-- | spaghetti-monster/anduril/anduril.c | 50 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/anduril.txt | 4 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-events.h | 27 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-main.c | 1 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-standby.c | 28 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-standby.h | 23 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-wdt.c | 23 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-wdt.h | 2 |
8 files changed, 113 insertions, 45 deletions
diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index 4eba836..ba9afa5 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -62,6 +62,7 @@ // specific settings for known driver types #ifdef FSM_BLF_Q8_DRIVER #define USE_INDICATOR_LED +#define TICK_DURING_STANDBY #define VOLTAGE_FUDGE_FACTOR 7 // add 0.35V #elif defined(FSM_EMISAR_D4_DRIVER) @@ -72,6 +73,7 @@ #elif defined(FSM_BLF_GT_DRIVER) #define USE_INDICATOR_LED +#define TICK_DURING_STANDBY #undef BLINK_AT_CHANNEL_BOUNDARIES #undef BLINK_AT_RAMP_CEILING #undef BLINK_AT_RAMP_FLOOR @@ -170,6 +172,9 @@ uint8_t number_entry_state(EventPtr event, uint16_t arg); volatile uint8_t number_entry_value; void blink_confirm(uint8_t num); +#if defined(USE_INDICATOR_LED) && defined(TICK_DURING_STANDBY) +void indicator_blink(uint8_t arg); +#endif // remember stuff even after battery was changed void load_config(); @@ -274,6 +279,15 @@ uint8_t off_state(EventPtr event, uint16_t arg) { } return MISCHIEF_MANAGED; } + #if defined(TICK_DURING_STANDBY) && defined(USE_INDICATOR_LED) + // blink the indicator LED, maybe + else if (event == EV_sleep_tick) { + if ((indicator_led_mode & 0b00000011) == 0b00000011) { + indicator_blink(arg); + } + return MISCHIEF_MANAGED; + } + #endif // hold (initially): go to lowest level, but allow abort for regular click else if (event == EV_click1_press) { set_level(nearest_level(1)); @@ -966,11 +980,23 @@ uint8_t lockout_state(EventPtr event, uint16_t arg) { } return MISCHIEF_MANAGED; } + #if defined(TICK_DURING_STANDBY) && defined(USE_INDICATOR_LED) + else if (event == EV_sleep_tick) { + if ((indicator_led_mode & 0b00001100) == 0b00001100) { + indicator_blink(arg); + } + return MISCHIEF_MANAGED; + } + #endif #ifdef USE_INDICATOR_LED // 3 clicks: rotate through indicator LED modes (lockout mode) else if (event == EV_3clicks) { uint8_t mode = indicator_led_mode >> 2; + #ifdef TICK_DURING_STANDBY + mode = (mode + 1) & 3; + #else mode = (mode + 1) % 3; + #endif indicator_led_mode = (mode << 2) + (indicator_led_mode & 0x03); indicator_led(mode); save_config(); @@ -978,9 +1004,20 @@ uint8_t lockout_state(EventPtr event, uint16_t arg) { } // click, click, hold: rotate through indicator LED modes (off mode) else if (event == EV_click3_hold) { + #ifdef TICK_DURING_STANDBY + uint8_t mode = (arg >> 5) & 3; + #else uint8_t mode = (arg >> 5) % 3; + #endif indicator_led_mode = (indicator_led_mode & 0b11111100) | mode; + #ifdef TICK_DURING_STANDBY + if (mode == 3) + indicator_led(mode & (arg&3)); + else + indicator_led(mode); + #else indicator_led(mode); + #endif //save_config(); return MISCHIEF_MANAGED; } @@ -1407,6 +1444,19 @@ void blink_confirm(uint8_t num) { } +#if defined(USE_INDICATOR_LED) && defined(TICK_DURING_STANDBY) +// beacon-like mode for the indicator LED +void indicator_blink(uint8_t arg) { + if (! (arg & 7)) { + indicator_led(2); + } + else { + indicator_led(0); + } +} +#endif + + #ifdef USE_PSEUDO_RAND uint8_t pseudo_rand() { static uint16_t offset = 1024; diff --git a/spaghetti-monster/anduril/anduril.txt b/spaghetti-monster/anduril/anduril.txt index fadd7d0..e74ce87 100644 --- a/spaghetti-monster/anduril/anduril.txt +++ b/spaghetti-monster/anduril/anduril.txt @@ -84,7 +84,7 @@ Discrete ramp config mode: Beacon mode: * 1 click: off * 2 clicks: tempcheck mode - * 3 clicks: configure time between pulses + * 4 clicks: configure time between pulses Beacon config mode: * At buzz, click N times to set beacon frequency to N seconds. @@ -92,7 +92,7 @@ Discrete ramp config mode: Tempcheck mode: * 1 click: off * 2 clicks: battcheck mode - * 3 clicks: thermal config mode + * 4 clicks: thermal config mode - Hold: thermal calibration mode Thermal config mode: diff --git a/spaghetti-monster/fsm-events.h b/spaghetti-monster/fsm-events.h index 84e9ea2..4a67347 100644 --- a/spaghetti-monster/fsm-events.h +++ b/spaghetti-monster/fsm-events.h @@ -42,10 +42,9 @@ typedef struct Emission { #define EV_MAX_LEN ((MAX_CLICKS*2)+3) uint8_t current_event[EV_MAX_LEN]; // at 0.016 ms per tick, 255 ticks = 4.08 s -// TODO: 16 bits? static volatile uint16_t ticks_since_last_event = 0; -// timeout durations in ticks (each tick 1/60th s) +// timeout durations in ticks (each tick 1/62th s) #ifndef HOLD_TIMEOUT #define HOLD_TIMEOUT 24 #endif @@ -57,15 +56,15 @@ static volatile uint16_t ticks_since_last_event = 0; #define A_LEAVE_STATE 2 #define A_REENTER_STATE 3 #define A_TICK 4 -#define A_PRESS 5 -#define A_HOLD 6 -#define A_RELEASE 7 -#define A_RELEASE_TIMEOUT 8 -#define A_OVERHEATING 9 -#define A_UNDERHEATING 10 -#define A_VOLTAGE_LOW 11 -#define A_HALFSLEEP_TICK 12 -//#define A_VOLTAGE_CRITICAL 12 +#define A_SLEEP_TICK 5 +#define A_PRESS 6 +#define A_HOLD 7 +#define A_RELEASE 8 +#define A_RELEASE_TIMEOUT 9 +#define A_OVERHEATING 10 +#define A_UNDERHEATING 11 +#define A_VOLTAGE_LOW 12 +//#define A_VOLTAGE_CRITICAL 13 #define A_DEBUG 255 // test event for debugging // Event types @@ -84,9 +83,9 @@ Event EV_reenter_state[] = { Event EV_tick[] = { A_TICK, 0 } ; -#ifdef USE_HALFSLEEP_MODE -Event EV_halfsleep_tick[] = { - A_HALFSLEEP_TICK, +#ifdef TICK_DURING_STANDBY +Event EV_sleep_tick[] = { + A_SLEEP_TICK, 0 } ; #endif #ifdef USE_LVP diff --git a/spaghetti-monster/fsm-main.c b/spaghetti-monster/fsm-main.c index 8f21846..b0b44fb 100644 --- a/spaghetti-monster/fsm-main.c +++ b/spaghetti-monster/fsm-main.c @@ -126,7 +126,6 @@ int main() { PWM4_LVL = 255; // inverted :( #endif #endif - go_to_standby = 0; standby_mode(); } diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c index 8e51dda..7d60c1d 100644 --- a/spaghetti-monster/fsm-standby.c +++ b/spaghetti-monster/fsm-standby.c @@ -31,16 +31,11 @@ #define standby_mode sleep_until_eswitch_pressed void sleep_until_eswitch_pressed() { - #ifdef USE_HALFSLEEP_MODE - //uint16_t sleep_counter = 0; - if (halfsleep_mode) { - // set WDT to slow mode - wdt_reset(); - WDTCR |= (1<<WDCE) | (1<<WDE); // Start timed sequence - WDTCR = (1<<WDIE) | 5; // Enable interrupt every 0.5s - } else - #endif + #ifdef TICK_DURING_STANDBY + WDT_slow(); + #else WDT_off(); + #endif ADC_off(); @@ -51,9 +46,11 @@ void sleep_until_eswitch_pressed() PCINT_on(); // wake on e-switch event - #ifdef USE_HALFSLEEP_MODE - while (halfsleep_mode) { + #ifdef TICK_DURING_STANDBY + while (go_to_standby) { f_wdt = 0; // detect if WDT was what caused a wake-up + #else + go_to_standby = 0; #endif // configure sleep mode set_sleep_mode(SLEEP_MODE_PWR_DOWN); @@ -65,13 +62,11 @@ void sleep_until_eswitch_pressed() // something happened; wake up sleep_disable(); - #ifdef USE_HALFSLEEP_MODE + #ifdef TICK_DURING_STANDBY // determine what woke us up... WDT or PCINT - if (! f_wdt) { // PCINT went off - halfsleep_mode = 0; + if (! f_wdt) { // PCINT went off; wake up + go_to_standby = 0; } - #endif - #ifdef USE_HALFSLEEP_MODE } #endif @@ -82,7 +77,6 @@ void sleep_until_eswitch_pressed() // go back to normal running mode //PCINT_on(); // should be on already - // FIXME? if button is down, make sure a button press event is added to the current sequence ADC_on(); WDT_on(); } diff --git a/spaghetti-monster/fsm-standby.h b/spaghetti-monster/fsm-standby.h index bd362a3..2cea080 100644 --- a/spaghetti-monster/fsm-standby.h +++ b/spaghetti-monster/fsm-standby.h @@ -25,9 +25,26 @@ // set this to nonzero to enter standby mode next time the system is idle volatile uint8_t go_to_standby = 0; -#ifdef USE_HALFSLEEP_MODE -// half-sleep "twilight" mode with WDT on but running slowly -volatile uint8_t halfsleep_mode = 0; +#ifdef TICK_DURING_STANDBY +#ifndef STANDBY_TICK_SPEED +#define STANDBY_TICK_SPEED 5 // every 0.512 s +/* + * From the Attiny85 manual: + * 0: 16 ms + * 1: 32 ms + * 2: 64 ms + * 3: 0.125 s + * 4: 0.25 s + * 5: 0.5 s + * 6: 1.0 s + * 7: 2.0 s + * 32: 4.0 s + * 33: 8.0 s + * (other values may have unexpected effects; not sure why the final bit is + * separated from the others, in the "32" position instead of "8", but that's + * how it is) + */ +#endif #endif #define standby_mode sleep_until_eswitch_pressed diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c index 06b0b6d..e8419bc 100644 --- a/spaghetti-monster/fsm-wdt.c +++ b/spaghetti-monster/fsm-wdt.c @@ -33,6 +33,18 @@ void WDT_on() //sei(); // Enable interrupts } +#ifdef TICK_DURING_STANDBY +inline void WDT_slow() +{ + // interrupt slower + //cli(); // Disable interrupts + wdt_reset(); // Reset the WDT + WDTCR |= (1<<WDCE) | (1<<WDE); // Start timed sequence + WDTCR = (1<<WDIE) | STANDBY_TICK_SPEED; // Enable interrupt every so often + //sei(); // Enable interrupts +} +#endif + inline void WDT_off() { //cli(); // Disable interrupts @@ -45,18 +57,15 @@ inline void WDT_off() // clock tick -- this runs every 16ms (62.5 fps) ISR(WDT_vect) { - #ifdef USE_HALFSLEEP_MODE + #ifdef TICK_DURING_STANDBY f_wdt = 1; // WDT event happened static uint16_t sleep_counter = 0; - // handle halfsleep mode specially - if (halfsleep_mode) { + // handle standby mode specially + if (go_to_standby) { // emit a halfsleep tick, and process it - emit(EV_halfsleep_tick, sleep_counter); - sleep_counter ++; + emit(EV_sleep_tick, sleep_counter++); process_emissions(); - //if (! halfsleep_mode) - // sleep_counter = 0; return; } sleep_counter = 0; diff --git a/spaghetti-monster/fsm-wdt.h b/spaghetti-monster/fsm-wdt.h index 1173382..3c395c1 100644 --- a/spaghetti-monster/fsm-wdt.h +++ b/spaghetti-monster/fsm-wdt.h @@ -25,7 +25,7 @@ void WDT_on(); inline void WDT_off(); -#ifdef USE_HALFSLEEP_MODE +#ifdef TICK_DURING_STANDBY volatile uint8_t f_wdt = 0; #endif |
