From f8f9dd584fd466dbf1a5726c2a60de8653c03d4f Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 23 Aug 2021 03:54:09 -0600 Subject: made jump start level configurable at runtime, and made it activate in more places --- spaghetti-monster/anduril/load-save-config-fsm.h | 3 +++ spaghetti-monster/anduril/load-save-config.c | 6 ++++++ spaghetti-monster/anduril/lockout-mode.c | 3 +++ spaghetti-monster/anduril/off-mode.c | 17 +++++++++++++---- spaghetti-monster/anduril/ramp-mode-fsm.h | 5 +++++ spaghetti-monster/anduril/ramp-mode.c | 24 ++++++++++++++++++++++++ spaghetti-monster/anduril/ramp-mode.h | 10 ++++++++++ 7 files changed, 64 insertions(+), 4 deletions(-) diff --git a/spaghetti-monster/anduril/load-save-config-fsm.h b/spaghetti-monster/anduril/load-save-config-fsm.h index 9d3dd86..0a62380 100644 --- a/spaghetti-monster/anduril/load-save-config-fsm.h +++ b/spaghetti-monster/anduril/load-save-config-fsm.h @@ -43,6 +43,9 @@ typedef enum { #ifdef USE_TINT_RAMPING tint_e, #endif + #ifdef JUMP_START_MOON + jump_start_moon_e, + #endif #ifdef USE_STROBE_STATE strobe_type_e, #endif diff --git a/spaghetti-monster/anduril/load-save-config.c b/spaghetti-monster/anduril/load-save-config.c index 3823521..cdeaeea 100644 --- a/spaghetti-monster/anduril/load-save-config.c +++ b/spaghetti-monster/anduril/load-save-config.c @@ -45,6 +45,9 @@ void load_config() { #ifdef USE_TINT_RAMPING tint = eeprom[tint_e]; #endif + #ifdef JUMP_START_MOON + jump_start_moon = eeprom[jump_start_moon_e], + #endif #if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE) strobe_type = eeprom[strobe_type_e]; // TODO: move this to eeprom_wl? strobe_delays[0] = eeprom[strobe_delays_0_e]; @@ -108,6 +111,9 @@ void save_config() { #ifdef USE_TINT_RAMPING eeprom[tint_e] = tint; #endif + #ifdef JUMP_START_MOON + eeprom[jump_start_moon_e] = jump_start_moon, + #endif #if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE) eeprom[strobe_type_e] = strobe_type; // TODO: move this to eeprom_wl? eeprom[strobe_delays_0_e] = strobe_delays[0]; diff --git a/spaghetti-monster/anduril/lockout-mode.c b/spaghetti-monster/anduril/lockout-mode.c index 8c83cff..4e2196f 100644 --- a/spaghetti-monster/anduril/lockout-mode.c +++ b/spaghetti-monster/anduril/lockout-mode.c @@ -42,6 +42,9 @@ uint8_t lockout_state(Event event, uint16_t arg) { } else { // anything except second click if (ramp_floors[1] < lvl) lvl = ramp_floors[1]; } + #ifdef JUMP_START_MOON + if (! actual_level) jump_start_func(); + #endif set_level(lvl); } // button was released diff --git a/spaghetti-monster/anduril/off-mode.c b/spaghetti-monster/anduril/off-mode.c index b1faf47..4472f74 100644 --- a/spaghetti-monster/anduril/off-mode.c +++ b/spaghetti-monster/anduril/off-mode.c @@ -98,8 +98,7 @@ uint8_t off_state(Event event, uint16_t arg) { else if (event == EV_click1_press) { #ifdef JUMP_START_MOON if (!arg) { - set_level(JUMP_START_MOON); - delay_4ms(3); + jump_start_func(); } #endif set_level(nearest_level(1)); @@ -119,8 +118,7 @@ uint8_t off_state(Event event, uint16_t arg) { #ifdef JUMP_START_MOON // pulse the output for a moment to wake up the power regulator if (!arg) { - set_level(JUMP_START_MOON); - delay_4ms(3); + jump_start_func(); } #endif set_level(nearest_level(1)); @@ -151,6 +149,9 @@ uint8_t off_state(Event event, uint16_t arg) { #endif } #endif + #ifdef JUMP_START_MOON + jump_start_func(); + #endif set_level(nearest_level(memorized_level)); return MISCHIEF_MANAGED; } @@ -316,6 +317,14 @@ uint8_t off_state(Event event, uint16_t arg) { return MISCHIEF_MANAGED; } #endif // end 7 clicks + + #ifdef USE_GLOBALS_CONFIG + // 9 clicks, but hold last click: configure misc global settings + else if ((event == EV_click9_hold) && (!arg)) { + push_state(globals_config_state, 0); + return MISCHIEF_MANAGED; + } + #endif return EVENT_NOT_HANDLED; } diff --git a/spaghetti-monster/anduril/ramp-mode-fsm.h b/spaghetti-monster/anduril/ramp-mode-fsm.h index 997e80d..c6ef4c8 100644 --- a/spaghetti-monster/anduril/ramp-mode-fsm.h +++ b/spaghetti-monster/anduril/ramp-mode-fsm.h @@ -41,5 +41,10 @@ #define TICK_DURING_STANDBY #endif +// include an extra config mode for random stuff which doesn't fit elsewhere +#if defined(JUMP_START_MOON) || defined(USE_2C_STYLE_CONFIG) +#define USE_GLOBALS_CONFIG +#endif + #endif diff --git a/spaghetti-monster/anduril/ramp-mode.c b/spaghetti-monster/anduril/ramp-mode.c index 8ab4ec4..f4eba59 100644 --- a/spaghetti-monster/anduril/ramp-mode.c +++ b/spaghetti-monster/anduril/ramp-mode.c @@ -473,6 +473,24 @@ uint8_t manual_memory_timer_config_state(Event event, uint16_t arg) { } #endif +#ifdef USE_GLOBALS_CONFIG +void globals_config_save(uint8_t step, uint8_t value) { + if (0) {} + #ifdef USE_2C_STYLE_CONFIG + // TODO: make double-click style configurable (turbo or ceil) + else if (1 == step) {} + #endif + #ifdef JUMP_START_MOON + else { jump_start_moon = value; } + #endif +} + +uint8_t globals_config_state(Event event, uint16_t arg) { + // TODO: set number of steps based on how many configurable options + return config_state_base(event, arg, 1, globals_config_save); +} +#endif + // find the ramp level closest to the target, // using only the levels which are allowed in the current state uint8_t nearest_level(int16_t target) { @@ -534,6 +552,12 @@ void set_level_and_therm_target(uint8_t level) { #define set_level_and_therm_target(level) set_level(level) #endif +#ifdef JUMP_START_MOON +void jump_start_func() { + set_level(jump_start_moon); + delay_4ms(3); +} +#endif #endif diff --git a/spaghetti-monster/anduril/ramp-mode.h b/spaghetti-monster/anduril/ramp-mode.h index ed806bd..efc77d3 100644 --- a/spaghetti-monster/anduril/ramp-mode.h +++ b/spaghetti-monster/anduril/ramp-mode.h @@ -192,5 +192,15 @@ uint8_t ramp_stepss[] = { }; uint8_t ramp_discrete_step_size; // don't set this +#ifdef JUMP_START_MOON +uint8_t jump_start_moon = JUMP_START_MOON; +void jump_start_func(); +#endif + +#ifdef USE_GLOBALS_CONFIG +void globals_config_save(uint8_t step, uint8_t value); +uint8_t globals_config_state(Event event, uint16_t arg); +#endif + #endif -- cgit v1.2.3