diff options
| author | Selene ToyKeeper | 2020-07-31 20:10:07 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2020-07-31 20:10:07 -0600 |
| commit | 5c4706536acaa86e8fa49e58b6e1e7b8cd21026a (patch) | |
| tree | 421b180084beb4db50faaefb8c1417f671a76c06 | |
| parent | made ramping "bump" the sunset timer up a little if it's near the deadline (diff) | |
| download | anduril-5c4706536acaa86e8fa49e58b6e1e7b8cd21026a.tar.gz anduril-5c4706536acaa86e8fa49e58b6e1e7b8cd21026a.tar.bz2 anduril-5c4706536acaa86e8fa49e58b6e1e7b8cd21026a.zip | |
added auto-lock function, mostly contributed by SammysHP
(5C in lockout mode to configure it, 5H to turn it off,
similar to UI for manual memory)
| -rw-r--r-- | spaghetti-monster/anduril/anduril.c | 4 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/config-default.h | 2 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/load-save-config-fsm.h | 3 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/load-save-config.c | 6 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/lockout-mode-fsm.h | 29 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/lockout-mode.c | 29 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/lockout-mode.h | 5 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/off-mode.c | 10 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-standby.h | 21 |
9 files changed, 104 insertions, 5 deletions
diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index 9fe8aee..fdc5b54 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -73,6 +73,10 @@ #include "battcheck-mode-fsm.h" #endif +#ifdef USE_LOCKOUT_MODE +#include "lockout-mode-fsm.h" +#endif + // enable FSM features needed by strobe modes #include "strobe-modes-fsm.h" diff --git a/spaghetti-monster/anduril/config-default.h b/spaghetti-monster/anduril/config-default.h index f037648..c68e869 100644 --- a/spaghetti-monster/anduril/config-default.h +++ b/spaghetti-monster/anduril/config-default.h @@ -115,6 +115,8 @@ #define MOON_DURING_LOCKOUT_MODE // if enabled, 2nd lockout click goes to the other ramp's floor level #define LOCKOUT_MOON_FANCY +// add an optional setting to lock the light after being off for a while +#define USE_AUTOLOCK // enable momentary mode #define USE_MOMENTARY_MODE diff --git a/spaghetti-monster/anduril/load-save-config-fsm.h b/spaghetti-monster/anduril/load-save-config-fsm.h index 7760048..d9c5f4c 100644 --- a/spaghetti-monster/anduril/load-save-config-fsm.h +++ b/spaghetti-monster/anduril/load-save-config-fsm.h @@ -67,6 +67,9 @@ typedef enum { rgb_led_off_mode_e, rgb_led_lockout_mode_e, #endif + #ifdef USE_AUTOLOCK + autolock_time_e, + #endif eeprom_indexes_e_END } eeprom_indexes_e; #define EEPROM_BYTES eeprom_indexes_e_END diff --git a/spaghetti-monster/anduril/load-save-config.c b/spaghetti-monster/anduril/load-save-config.c index 8cfb69d..7268dc9 100644 --- a/spaghetti-monster/anduril/load-save-config.c +++ b/spaghetti-monster/anduril/load-save-config.c @@ -67,6 +67,9 @@ void load_config() { rgb_led_off_mode = eeprom[rgb_led_off_mode_e]; rgb_led_lockout_mode = eeprom[rgb_led_lockout_mode_e]; #endif + #ifdef USE_AUTOLOCK + autolock_time = eeprom[autolock_time_e]; + #endif } #ifdef START_AT_MEMORIZED_LEVEL if (load_eeprom_wl()) { @@ -118,6 +121,9 @@ void save_config() { eeprom[rgb_led_off_mode_e] = rgb_led_off_mode; eeprom[rgb_led_lockout_mode_e] = rgb_led_lockout_mode; #endif + #ifdef USE_AUTOLOCK + eeprom[autolock_time_e] = autolock_time; + #endif save_eeprom(); } diff --git a/spaghetti-monster/anduril/lockout-mode-fsm.h b/spaghetti-monster/anduril/lockout-mode-fsm.h new file mode 100644 index 0000000..bc18ed3 --- /dev/null +++ b/spaghetti-monster/anduril/lockout-mode-fsm.h @@ -0,0 +1,29 @@ +/* + * lockout-mode-fsm.h: FSM config for lockout mode in Anduril. + * + * Copyright (C) 2017 Selene ToyKeeper + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef LOCKOUT_MODE_FSM_H +#define LOCKOUT_MODE_FSM_H + +// autolock function requires the ability to measure time while "off" +#ifdef USE_AUTOLOCK +#define TICK_DURING_STANDBY +#endif + + +#endif diff --git a/spaghetti-monster/anduril/lockout-mode.c b/spaghetti-monster/anduril/lockout-mode.c index 40bb6cf..e2a6f40 100644 --- a/spaghetti-monster/anduril/lockout-mode.c +++ b/spaghetti-monster/anduril/lockout-mode.c @@ -113,6 +113,23 @@ uint8_t lockout_state(Event event, uint16_t arg) { } #endif + #ifdef USE_AUTOLOCK + // 5 clicks: configure the autolock option + else if (event == EV_5clicks) { + push_state(autolock_config_state, 0); + return MISCHIEF_MANAGED; + } + // 5H: turn off autolock + else if (event == EV_click5_hold) { + if (0 == arg) { + autolock_time = 0; + save_config(); + blip(); + } + return MISCHIEF_MANAGED; + } + #endif + #if defined(USE_INDICATOR_LED) // 7 clicks: rotate through indicator LED modes (lockout mode) else if (event == EV_7clicks) { @@ -167,6 +184,18 @@ uint8_t lockout_state(Event event, uint16_t arg) { return EVENT_NOT_HANDLED; } +#ifdef USE_AUTOLOCK +// set the auto-lock timer to N minutes, where N is the number of clicks +void autolock_config_save() { + uint8_t foo = config_state_values[0]; + if (foo) autolock_time = config_state_values[0]; +} + +uint8_t autolock_config_state(Event event, uint16_t arg) { + return config_state_base(event, arg, 1, autolock_config_save); +} +#endif // #ifdef USE_AUTOLOCK + #endif diff --git a/spaghetti-monster/anduril/lockout-mode.h b/spaghetti-monster/anduril/lockout-mode.h index c933b30..021d34a 100644 --- a/spaghetti-monster/anduril/lockout-mode.h +++ b/spaghetti-monster/anduril/lockout-mode.h @@ -23,5 +23,10 @@ // soft lockout uint8_t lockout_state(Event event, uint16_t arg); +#ifdef USE_AUTOLOCK +uint8_t autolock_time = 0; +uint8_t autolock_config_state(Event event, uint16_t arg); +#endif + #endif diff --git a/spaghetti-monster/anduril/off-mode.c b/spaghetti-monster/anduril/off-mode.c index 2defc27..9218752 100644 --- a/spaghetti-monster/anduril/off-mode.c +++ b/spaghetti-monster/anduril/off-mode.c @@ -55,7 +55,7 @@ uint8_t off_state(Event event, uint16_t arg) { } return MISCHIEF_MANAGED; } - #if defined(TICK_DURING_STANDBY) && (defined(USE_INDICATOR_LED) || defined(USE_AUX_RGB_LEDS)) + #if defined(TICK_DURING_STANDBY) // blink the indicator LED, maybe else if (event == EV_sleep_tick) { #ifdef USE_INDICATOR_LED @@ -65,6 +65,14 @@ uint8_t off_state(Event event, uint16_t arg) { #elif defined(USE_AUX_RGB_LEDS) rgb_led_update(rgb_led_off_mode, arg); #endif + + #ifdef USE_AUTOLOCK + // lock the light after being off for N minutes + uint16_t ticks = autolock_time * SLEEP_TICKS_PER_SECOND * 60; + if ((autolock_time > 0) && (arg > ticks)) { + set_state(lockout_state, 0); + } + #endif return MISCHIEF_MANAGED; } #endif diff --git a/spaghetti-monster/fsm-standby.h b/spaghetti-monster/fsm-standby.h index 2cea080..9f411be 100644 --- a/spaghetti-monster/fsm-standby.h +++ b/spaghetti-monster/fsm-standby.h @@ -27,15 +27,15 @@ volatile uint8_t go_to_standby = 0; #ifdef TICK_DURING_STANDBY #ifndef STANDBY_TICK_SPEED -#define STANDBY_TICK_SPEED 5 // every 0.512 s +#define STANDBY_TICK_SPEED 3 // every 0.128 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 + * 3: 0.128 s + * 4: 0.256 s + * 5: 0.512 s * 6: 1.0 s * 7: 2.0 s * 32: 4.0 s @@ -45,6 +45,19 @@ volatile uint8_t go_to_standby = 0; * how it is) */ #endif +#if (STANDBY_TICK_SPEED == 1) +#define SLEEP_TICKS_PER_SECOND 31 +#elif (STANDBY_TICK_SPEED == 2) +#define SLEEP_TICKS_PER_SECOND 16 +#elif (STANDBY_TICK_SPEED == 3) +#define SLEEP_TICKS_PER_SECOND 8 +#elif (STANDBY_TICK_SPEED == 4) +#define SLEEP_TICKS_PER_SECOND 4 +#elif (STANDBY_TICK_SPEED == 5) +#define SLEEP_TICKS_PER_SECOND 2 +#elif (STANDBY_TICK_SPEED == 6) +#define SLEEP_TICKS_PER_SECOND 1 +#endif #endif #define standby_mode sleep_until_eswitch_pressed |
