From 3dcfc924bf18c48b76f4b950471160436fddb316 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 17 Jun 2018 19:40:38 -0600 Subject: Changed halfsleep mode to TICK_DURING_STANDBY. Added blinking indicator LED support to Anduril. --- spaghetti-monster/anduril/anduril.c | 50 +++++++++++++++++++++++++++++++++++ spaghetti-monster/anduril/anduril.txt | 4 +-- spaghetti-monster/fsm-events.h | 27 +++++++++---------- spaghetti-monster/fsm-main.c | 1 - spaghetti-monster/fsm-standby.c | 28 ++++++++------------ spaghetti-monster/fsm-standby.h | 23 +++++++++++++--- spaghetti-monster/fsm-wdt.c | 23 +++++++++++----- spaghetti-monster/fsm-wdt.h | 2 +- 8 files changed, 113 insertions(+), 45 deletions(-) (limited to 'spaghetti-monster') 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<