Skip to content

Commit

Permalink
[WIP] [Anduril] Automatically lock after inactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
SammysHP committed Aug 23, 2019
1 parent a73df6d commit 3e0d6d8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
46 changes: 45 additions & 1 deletion ToyKeeper/spaghetti-monster/anduril/anduril.c
Expand Up @@ -192,6 +192,9 @@ typedef enum {
rgb_led_off_mode_e,
rgb_led_lockout_mode_e,
#endif
#if defined(USE_AUTOLOCK) && defined(TICK_DURING_STANDBY)
autolock_e,
#endif
eeprom_indexes_e_END
} eeprom_indexes_e;
#define EEPROM_BYTES eeprom_indexes_e_END
Expand All @@ -216,6 +219,10 @@ typedef enum {
#define USE_REBOOT
#endif

#if defined(USE_AUTOLOCK) && !defined(TICK_DURING_STANDBY)
#warning "USE_AUTOLOCK requires TICK_DURING_STANDBY."
#endif

#include "spaghetti-monster.h"


Expand Down Expand Up @@ -294,6 +301,11 @@ uint8_t momentary_active = 0; // boolean, true if active *right now*
uint8_t muggle_state(Event event, uint16_t arg);
uint8_t muggle_mode_active = 0;
#endif
#if defined(USE_AUTOLOCK) && defined(TICK_DURING_STANDBY)
uint8_t autolock_state(Event event, uint16_t arg);
uint8_t autolock_config_state(Event event, uint16_t arg);
uint8_t autolock = 0;
#endif

// general helper function for config modes
uint8_t number_entry_state(Event event, uint16_t arg);
Expand Down Expand Up @@ -510,7 +522,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) && (defined(USE_INDICATOR_LED) || defined(USE_AUX_RGB_LEDS) || defined(USE_AUTOLOCK))
// blink the indicator LED, maybe
else if (event == EV_sleep_tick) {
#ifdef USE_INDICATOR_LED
Expand All @@ -520,6 +532,13 @@ 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
// TODO Handle rollover
uint16_t locktime = autolock * (uint16_t)(SLEEP_TICKS_PER_SECOND * 60);
if (autolock && arg > locktime) {
set_state(lockout_state, 0);
}
#endif
return MISCHIEF_MANAGED;
}
#endif
Expand Down Expand Up @@ -1746,6 +1765,13 @@ uint8_t lockout_state(Event event, uint16_t arg) {
set_state(off_state, 0);
return MISCHIEF_MANAGED;
}
#if defined(USE_AUTOLOCK) && defined(TICK_DURING_STANDBY)
// 5 clicks: enable autolock
else if (event == EV_5clicks) {
push_state(autolock_config_state, 0);
return MISCHIEF_MANAGED;
}
#endif

return EVENT_NOT_HANDLED;
}
Expand Down Expand Up @@ -2078,6 +2104,18 @@ static inline void beacon_mode_iter() {
#endif // #ifdef USE_BEACON_MODE


#if defined(USE_AUTOLOCK) && defined(TICK_DURING_STANDBY)
void autolock_config_save() {
autolock = 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 // #if defined(USE_AUTOLOCK) && defined(TICK_DURING_STANDBY)


uint8_t number_entry_state(Event event, uint16_t arg) {
static uint8_t value;
static uint8_t blinks_left;
Expand Down Expand Up @@ -2412,6 +2450,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
#if defined(USE_AUTOLOCK) && defined(TICK_DURING_STANDBY)
autolock = eeprom[autolock_e];
#endif
}
#ifdef START_AT_MEMORIZED_LEVEL
if (load_eeprom_wl()) {
Expand Down Expand Up @@ -2460,6 +2501,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
#if defined(USE_AUTOLOCK) && defined(TICK_DURING_STANDBY)
eeprom[autolock_e] = autolock;
#endif

save_eeprom();
}
Expand Down
3 changes: 3 additions & 0 deletions ToyKeeper/spaghetti-monster/anduril/cfg-emisar-d4s.h
Expand Up @@ -10,6 +10,7 @@
// enable blinking indicator LED while off
#define TICK_DURING_STANDBY
#define STANDBY_TICK_SPEED 3 // every 0.128 s
#define SLEEP_TICKS_PER_SECOND 7.8125
#define USE_FANCIER_BLINKING_INDICATOR

#ifdef RAMP_LENGTH
Expand Down Expand Up @@ -46,3 +47,5 @@
#define THERMAL_WARNING_SECONDS 3
#define THERMAL_UPDATE_SPEED 2
#define THERM_PREDICTION_STRENGTH 4

#define USE_AUTOLOCK

0 comments on commit 3e0d6d8

Please sign in to comment.