diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index ab43df6d..eeecca95 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -226,7 +226,7 @@ void setup() { #if defined(USE_MANUAL_MEMORY) && defined(USE_MANUAL_MEMORY_TIMER) // without this, initial boot-up brightness is wrong // when manual mem is enabled with a non-zero timer - if (cfg.manual_memory) manual_memory_restore(); + if (cfg.manual_memory_simple) manual_memory_restore(); #endif #if defined(USE_CHANNEL_MODES) diff --git a/spaghetti-monster/anduril/build-all.sh b/spaghetti-monster/anduril/build-all.sh index 768559c1..11355db2 100755 --- a/spaghetti-monster/anduril/build-all.sh +++ b/spaghetti-monster/anduril/build-all.sh @@ -33,8 +33,8 @@ for TARGET in cfg-*.h ; do if [ -z "$ATTINY" ]; then ATTINY=85 ; fi # try to compile - echo ../../../bin/build.sh $ATTINY "$UI" "-DCFG_H=${TARGET}" - ../../../bin/build.sh $ATTINY "$UI" "-DCFG_H=${TARGET}" + echo ../../bin/build.sh $ATTINY "$UI" "-DCFG_H=${TARGET}" + ../../bin/build.sh $ATTINY "$UI" "-DCFG_H=${TARGET}" # track result, and rename compiled files if [ 0 = $? ] ; then diff --git a/spaghetti-monster/anduril/load-save-config-fsm.h b/spaghetti-monster/anduril/load-save-config-fsm.h index 862cf268..51921abd 100644 --- a/spaghetti-monster/anduril/load-save-config-fsm.h +++ b/spaghetti-monster/anduril/load-save-config-fsm.h @@ -39,7 +39,9 @@ typedef struct Config { uint8_t dont_ramp_after_moon; #endif #ifdef USE_MANUAL_MEMORY - uint8_t manual_memory; + uint8_t manual_memory_simple; + uint8_t manual_memory_stepped; + uint8_t manual_memory_smooth; #ifdef USE_MANUAL_MEMORY_TIMER uint8_t manual_memory_timer; #endif @@ -50,7 +52,9 @@ typedef struct Config { uint8_t channel_mode; uint8_t channel_modes_enabled; #ifdef USE_MANUAL_MEMORY - uint8_t manual_memory_channel_mode; + uint8_t manual_memory_channel_mode_simple; + uint8_t manual_memory_channel_mode_smooth; + uint8_t manual_memory_channel_mode_stepped; #endif #ifdef DEFAULT_BLINK_CHANNEL uint8_t blink_channel; diff --git a/spaghetti-monster/anduril/load-save-config.h b/spaghetti-monster/anduril/load-save-config.h index 8ae9d960..8fc8cac8 100644 --- a/spaghetti-monster/anduril/load-save-config.h +++ b/spaghetti-monster/anduril/load-save-config.h @@ -60,7 +60,9 @@ Config cfg = { .dont_ramp_after_moon = DEFAULT_DONT_RAMP_AFTER_MOON, #ifdef USE_MANUAL_MEMORY - .manual_memory = DEFAULT_MANUAL_MEMORY, + .manual_memory_simple = DEFAULT_MANUAL_MEMORY, + .manual_memory_smooth = DEFAULT_MANUAL_MEMORY, + .manual_memory_stepped = DEFAULT_MANUAL_MEMORY, #ifdef USE_MANUAL_MEMORY_TIMER .manual_memory_timer = DEFAULT_MANUAL_MEMORY_TIMER, #endif @@ -75,7 +77,9 @@ Config cfg = { .channel_modes_enabled = CHANNEL_MODES_ENABLED, #ifdef USE_MANUAL_MEMORY // reset w/ manual memory - .manual_memory_channel_mode = DEFAULT_CHANNEL_MODE, + .manual_memory_channel_mode_simple = DEFAULT_CHANNEL_MODE, + .manual_memory_channel_mode_stepped = DEFAULT_CHANNEL_MODE, + .manual_memory_channel_mode_smooth = DEFAULT_CHANNEL_MODE, #endif #ifdef DEFAULT_BLINK_CHANNEL // blink numbers in a specific channel (user configurable) diff --git a/spaghetti-monster/anduril/lockout-mode.c b/spaghetti-monster/anduril/lockout-mode.c index 3df9e7a7..a66cf452 100644 --- a/spaghetti-monster/anduril/lockout-mode.c +++ b/spaghetti-monster/anduril/lockout-mode.c @@ -23,7 +23,8 @@ uint8_t lockout_state(Event event, uint16_t arg) { } else { // 2nd click or later if (cfg.ramp_floors[1] > lvl) lvl = cfg.ramp_floors[1]; #ifdef USE_MANUAL_MEMORY - if (cfg.manual_memory) lvl = cfg.manual_memory; + uint8_t manual_mem = (get_manual_mem_level()); + if (manual_mem) { lvl = manual_mem; } #endif } set_level(lvl); @@ -67,7 +68,9 @@ uint8_t lockout_state(Event event, uint16_t arg) { if (ticks_since_on < 255) ticks_since_on ++; #ifdef USE_MANUAL_MEMORY_TIMER // reset to manual memory level when timer expires - if (cfg.manual_memory && + uint8_t manual_mem = (get_manual_mem_level()); + + if (manual_mem && (arg >= (cfg.manual_memory_timer * SLEEP_TICKS_PER_MINUTE))) { manual_memory_restore(); } @@ -93,8 +96,9 @@ uint8_t lockout_state(Event event, uint16_t arg) { #if defined(USE_MANUAL_MEMORY) && !defined(USE_MANUAL_MEMORY_TIMER) // this clause probably isn't used by any configs any more // but is included just in case someone configures it this way - if (cfg.manual_memory) - set_state(steady_state, cfg.manual_memory); + uint8_t manual_mem = get_manual_mem_level(); + if (manual_mem) + set_state(steady_state, manual_mem); else #endif set_state(steady_state, memorized_level); @@ -206,6 +210,19 @@ uint8_t lockout_state(Event event, uint16_t arg) { return EVENT_NOT_HANDLED; } +#ifdef USE_MANUAL_MEMORY +uint8_t get_manual_mem_level(){ + if (cfg.simple_ui_active){ + if (cfg.manual_memory_simple) { return cfg.manual_memory_simple; } + } else + if (cfg.ramp_style){ + if (cfg.manual_memory_stepped) { return cfg.manual_memory_stepped; } + } else + if (cfg.manual_memory_smooth) { return cfg.manual_memory_smooth; } + return 0; +} +#endif + #ifdef USE_AUTOLOCK // set the auto-lock timer to N minutes, where N is the number of clicks void autolock_config_save(uint8_t step, uint8_t value) { diff --git a/spaghetti-monster/anduril/lockout-mode.h b/spaghetti-monster/anduril/lockout-mode.h index c2703a0c..9b99ba7f 100644 --- a/spaghetti-monster/anduril/lockout-mode.h +++ b/spaghetti-monster/anduril/lockout-mode.h @@ -4,6 +4,10 @@ #pragma once +#ifdef USE_MANUAL_MEMORY +uint8_t get_manual_mem_level(); +#endif + // soft lockout uint8_t lockout_state(Event event, uint16_t arg); diff --git a/spaghetti-monster/anduril/off-mode.c b/spaghetti-monster/anduril/off-mode.c index 1c7ccc3b..2754b6ee 100644 --- a/spaghetti-monster/anduril/off-mode.c +++ b/spaghetti-monster/anduril/off-mode.c @@ -51,7 +51,9 @@ uint8_t off_state(Event event, uint16_t arg) { if (ticks_since_on < 255) ticks_since_on ++; #ifdef USE_MANUAL_MEMORY_TIMER // reset to manual memory level when timer expires - if (cfg.manual_memory && + //if (cfg.manual_memory && + uint8_t manual_mem = get_manual_mem_level(); + if (manual_mem && (arg >= (cfg.manual_memory_timer * SLEEP_TICKS_PER_MINUTE))) { manual_memory_restore(); } @@ -119,7 +121,8 @@ uint8_t off_state(Event event, uint16_t arg) { #if defined(USE_MANUAL_MEMORY) && !defined(USE_MANUAL_MEMORY_TIMER) // this clause probably isn't used by any configs any more // but is included just in case someone configures it this way - if (cfg.manual_memory) { + uint8_t manual_mem = get_manual_mem_level(); + if (manual_mem) { manual_memory_restore(); } #endif @@ -225,6 +228,7 @@ uint8_t off_state(Event event, uint16_t arg) { if (cfg.simple_ui_active) { // turn off simple UI blink_once(); cfg.simple_ui_active = 0; + manual_memory_restore(); //necessary as otherwise the first use of manual mem when switching in/out of simple is wrong save_config(); } else { // configure simple UI ramp @@ -316,6 +320,7 @@ uint8_t off_state(Event event, uint16_t arg) { else if (event == EV_10clicks) { blink_once(); cfg.simple_ui_active = 1; + manual_memory_restore(); //necessary as otherwise the first use of manual mem when switching in/out of simple is wrong save_config(); return TRANS_RIGHTS_ARE_HUMAN_RIGHTS; } diff --git a/spaghetti-monster/anduril/ramp-mode.c b/spaghetti-monster/anduril/ramp-mode.c index cd6c7918..acdd9ac2 100644 --- a/spaghetti-monster/anduril/ramp-mode.c +++ b/spaghetti-monster/anduril/ramp-mode.c @@ -357,6 +357,16 @@ uint8_t steady_state(Event event, uint16_t arg) { #endif // ifdef USE_SET_LEVEL_GRADUALLY #endif // ifdef USE_THERMAL_REGULATION + #ifdef USE_MANUAL_MEMORY + else if (((cfg.simple_ui_active) && (event == EV_8clicks)) || (event == EV_10clicks)) { + // turn on manual memory and save current brightness + manual_memory_save(); + save_config(); + blink_once(); + return TRANS_RIGHTS_ARE_HUMAN_RIGHTS; + } + #endif + ////////// Every action below here is blocked in the simple UI ////////// // That is, unless we specifically want to enable 3C for smooth/stepped selection in Simple UI #if defined(USE_SIMPLE_UI) && !defined(USE_SIMPLE_UI_RAMPING_TOGGLE) @@ -463,13 +473,6 @@ uint8_t steady_state(Event event, uint16_t arg) { #endif #ifdef USE_MANUAL_MEMORY - else if (event == EV_10clicks) { - // turn on manual memory and save current brightness - manual_memory_save(); - save_config(); - blink_once(); - return TRANS_RIGHTS_ARE_HUMAN_RIGHTS; - } else if (event == EV_click10_hold) { #ifdef USE_RAMP_EXTRAS_CONFIG // let user configure a bunch of extra ramp options @@ -550,7 +553,11 @@ uint8_t simple_ui_config_state(Event event, uint16_t arg) { #ifdef USE_RAMP_EXTRAS_CONFIG void ramp_extras_config_save(uint8_t step, uint8_t value) { // item 1: disable manual memory, go back to automatic - if (1 == step) { cfg.manual_memory = 0; } + if (1 == step) { + if (cfg.simple_ui_active){ cfg.manual_memory_simple = 0;} else + if (cfg.ramp_style){ cfg.manual_memory_stepped = 0;} else { + cfg.manual_memory_smooth = 0; } +} #ifdef USE_MANUAL_MEMORY_TIMER // item 2: set manual memory timer duration @@ -663,9 +670,12 @@ void set_level_and_therm_target(uint8_t level) { #endif void manual_memory_restore() { - memorized_level = cfg.manual_memory; + memorized_level = get_manual_mem_level(); #if NUM_CHANNEL_MODES > 1 - cfg.channel_mode = cfg.manual_memory_channel_mode; + if (cfg.simple_ui_active){ cfg.channel_mode = cfg.manual_memory_channel_mode_simple; } else + if (cfg.ramp_style) { cfg.channel_mode = cfg.manual_memory_channel_mode_stepped; } else + { cfg.channel_mode = cfg.manual_memory_channel_mode_smooth; } + //cfg.channel_mode = cfg.manual_memory_channel_mode; #endif #ifdef USE_CHANNEL_MODE_ARGS for (uint8_t i=0; i 1 - cfg.manual_memory_channel_mode = cfg.channel_mode; + if (cfg.simple_ui_active){ cfg.manual_memory_channel_mode_simple = cfg.channel_mode; } else + if (cfg.ramp_style) { cfg.manual_memory_channel_mode_stepped = cfg.channel_mode; } else + { cfg.manual_memory_channel_mode_smooth = cfg.channel_mode; } #endif #ifdef USE_CHANNEL_MODE_ARGS for (uint8_t i=0; i