diff options
Diffstat (limited to '')
| -rw-r--r-- | spaghetti-monster/anduril/aux-leds.c | 52 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/aux-leds.h | 2 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/lockout-mode.c | 17 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/off-mode.c | 13 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-adc.h | 4 |
5 files changed, 54 insertions, 34 deletions
diff --git a/spaghetti-monster/anduril/aux-leds.c b/spaghetti-monster/anduril/aux-leds.c index a0a6d7a..a3b905e 100644 --- a/spaghetti-monster/anduril/aux-leds.c +++ b/spaghetti-monster/anduril/aux-leds.c @@ -23,30 +23,44 @@ #include "aux-leds.h" -#if defined(USE_INDICATOR_LED) && defined(TICK_DURING_STANDBY) -// beacon-like mode for the indicator LED -void indicator_blink(uint8_t arg) { - // turn off aux LEDs when battery is empty - if (voltage < VOLTAGE_LOW) { indicator_led(0); return; } - - #ifdef USE_OLD_BLINKING_INDICATOR - - // basic blink, 1/8th duty cycle - if (! (arg & 7)) { - indicator_led(2); - } - else { +#if defined(USE_INDICATOR_LED) +void indicator_led_update(uint8_t mode, uint8_t tick) { + //uint8_t volts = voltage; // save a few bytes by caching volatile value + // turn off when battery is too low + if (voltage < VOLTAGE_LOW) { indicator_led(0); } + //#ifdef USE_INDICATOR_LOW_BAT_WARNING + // fast blink a warning when battery is low but not critical + else if (voltage < VOLTAGE_RED) { + indicator_led(mode & (((tick & 0b0010)>>1) - 3)); + } + //#endif + // normal steady output, 0/1/2 = off / low / high + else if ((mode & 0b00001111) < 3) { + indicator_led(mode); + } + // beacon-like blinky mode + else { + #ifdef USE_OLD_BLINKING_INDICATOR + + // basic blink, 1/8th duty cycle + if (! (tick & 7)) { + indicator_led(2); + } + else { + indicator_led(0); + } - #else + #else - // fancy blink, set off/low/high levels here: - static const uint8_t seq[] = {0, 1, 2, 1, 0, 0, 0, 0, - 0, 0, 1, 0, 0, 0, 0, 0}; - indicator_led(seq[arg & 15]); + // fancy blink, set off/low/high levels here: + static const uint8_t seq[] = {0, 1, 2, 1, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, 0, 0}; + indicator_led(seq[tick & 15]); - #endif // ifdef USE_OLD_BLINKING_INDICATOR + #endif // ifdef USE_OLD_BLINKING_INDICATOR + } } #endif diff --git a/spaghetti-monster/anduril/aux-leds.h b/spaghetti-monster/anduril/aux-leds.h index 664cbf1..71a14e3 100644 --- a/spaghetti-monster/anduril/aux-leds.h +++ b/spaghetti-monster/anduril/aux-leds.h @@ -21,7 +21,7 @@ #define AUX_LEDS_H #if defined(USE_INDICATOR_LED) && defined(TICK_DURING_STANDBY) -void indicator_blink(uint8_t arg); +void indicator_led_update(uint8_t mode, uint8_t tick); #endif #if defined(USE_AUX_RGB_LEDS) && defined(TICK_DURING_STANDBY) uint8_t setting_rgb_mode_now = 0; diff --git a/spaghetti-monster/anduril/lockout-mode.c b/spaghetti-monster/anduril/lockout-mode.c index e3e3fed..13d3c0a 100644 --- a/spaghetti-monster/anduril/lockout-mode.c +++ b/spaghetti-monster/anduril/lockout-mode.c @@ -56,9 +56,10 @@ uint8_t lockout_state(Event event, uint16_t arg) { // be persistent about going back to sleep every few seconds // even if the user keeps pressing the button) #ifdef USE_INDICATOR_LED - if (event == EV_enter_state) { - indicator_led(indicator_led_mode >> 2); - } else + // redundant, sleep tick does the same thing + //if (event == EV_enter_state) { + // indicator_led_update(indicator_led_mode >> 2, 0); + //} else #elif defined(USE_AUX_RGB_LEDS) if (event == EV_enter_state) { rgb_led_update(rgb_led_lockout_mode, 0); @@ -68,7 +69,8 @@ uint8_t lockout_state(Event event, uint16_t arg) { if (arg > HOLD_TIMEOUT) { go_to_standby = 1; #ifdef USE_INDICATOR_LED - indicator_led(indicator_led_mode >> 2); + // redundant, sleep tick does the same thing + //indicator_led_update(indicator_led_mode >> 2, arg); #elif defined(USE_AUX_RGB_LEDS) rgb_led_update(rgb_led_lockout_mode, arg); #endif @@ -78,9 +80,7 @@ uint8_t lockout_state(Event event, uint16_t arg) { #if defined(TICK_DURING_STANDBY) && (defined(USE_INDICATOR_LED) || defined(USE_AUX_RGB_LEDS)) else if (event == EV_sleep_tick) { #if defined(USE_INDICATOR_LED) - if ((indicator_led_mode & 0b00001100) == 0b00001100) { - indicator_blink(arg); - } + indicator_led_update(indicator_led_mode >> 2, arg); #elif defined(USE_AUX_RGB_LEDS) rgb_led_update(rgb_led_lockout_mode, arg); #endif @@ -150,7 +150,8 @@ uint8_t lockout_state(Event event, uint16_t arg) { if (mode == 1) { mode ++; } #endif indicator_led_mode = (mode << 2) + (indicator_led_mode & 0x03); - indicator_led(mode); + // redundant, sleep tick does the same thing + //indicator_led_update(indicator_led_mode >> 2, arg); #elif defined(USE_AUX_RGB_LEDS) #endif save_config(); diff --git a/spaghetti-monster/anduril/off-mode.c b/spaghetti-monster/anduril/off-mode.c index 236ad7e..c879e56 100644 --- a/spaghetti-monster/anduril/off-mode.c +++ b/spaghetti-monster/anduril/off-mode.c @@ -32,7 +32,8 @@ uint8_t off_state(Event event, uint16_t arg) { if (event == EV_enter_state) { set_level(0); #ifdef USE_INDICATOR_LED - indicator_led(indicator_led_mode & 0x03); + // redundant, sleep tick does the same thing + //indicator_led_update(indicator_led_mode & 0x03, 0); #elif defined(USE_AUX_RGB_LEDS) rgb_led_update(rgb_led_off_mode, 0); #endif @@ -49,7 +50,8 @@ uint8_t off_state(Event event, uint16_t arg) { if (arg > HOLD_TIMEOUT) { go_to_standby = 1; #ifdef USE_INDICATOR_LED - indicator_led(indicator_led_mode & 0x03); + // redundant, sleep tick does the same thing + //indicator_led_update(indicator_led_mode & 0x03, arg); #elif defined(USE_AUX_RGB_LEDS) rgb_led_update(rgb_led_off_mode, arg); #endif @@ -70,9 +72,7 @@ uint8_t off_state(Event event, uint16_t arg) { } #endif #ifdef USE_INDICATOR_LED - if ((indicator_led_mode & 0b00000011) == 0b00000011) { - indicator_blink(arg); - } + indicator_led_update(indicator_led_mode & 0x03, arg); #elif defined(USE_AUX_RGB_LEDS) rgb_led_update(rgb_led_off_mode, arg); #endif @@ -284,7 +284,8 @@ uint8_t off_state(Event event, uint16_t arg) { if (mode == 1) { mode ++; } #endif indicator_led_mode = (indicator_led_mode & 0b11111100) | mode; - indicator_led(mode); + // redundant, sleep tick does the same thing + //indicator_led_update(indicator_led_mode & 0x03, arg); save_config(); return MISCHIEF_MANAGED; } diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h index fc24712..db2bb7b 100644 --- a/spaghetti-monster/fsm-adc.h +++ b/spaghetti-monster/fsm-adc.h @@ -36,6 +36,10 @@ volatile uint8_t adc_reset = 2; #ifndef VOLTAGE_LOW #define VOLTAGE_LOW 29 #endif +// battery is low but not critical +#ifndef VOLTAGE_RED +#define VOLTAGE_RED 33 +#endif // MCU sees voltage 0.X volts lower than actual, add X/2 to readings #ifndef VOLTAGE_FUDGE_FACTOR #ifdef USE_VOLTAGE_DIVIDER |
