From 402b2893e8fb19a05a3e5cca6b703faca8907b8b Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 6 Oct 2023 11:02:24 -0600 Subject: smooth steps: fixed a few corner cases - Off -> 1H - Off -> 2H and release - Off -> 2C - Off -> 3C or more - Ramp -> 2C (in smooth ramp mode) ... also reduced ROM size a bit. Now it does smooth animations for 2C turbo, regardless of the current ramp mode. Before, in smooth ramp mode, 2C turbo did a hard step. Hard steps were also eliminated for 1H from Off, momentary turbo from Off, regular turbo from Off, and anything longer than 2C from Off. --- spaghetti-monster/anduril/off-mode.c | 40 +++++++++++++++++++++-------------- spaghetti-monster/anduril/ramp-mode.c | 6 +++++- 2 files changed, 29 insertions(+), 17 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/off-mode.c b/spaghetti-monster/anduril/off-mode.c index af09d70..0a381b7 100644 --- a/spaghetti-monster/anduril/off-mode.c +++ b/spaghetti-monster/anduril/off-mode.c @@ -10,17 +10,20 @@ #include "sunset-timer.h" #endif +// set level smooth maybe +void off_state_set_level(uint8_t level); + + uint8_t off_state(Event event, uint16_t arg) { // turn emitter off when entering state if (event == EV_enter_state) { + // turn off + off_state_set_level(0); #ifdef USE_SMOOTH_STEPS - if (cfg.smooth_steps_style && actual_level) { - set_level_smooth(0, 8); - arg = 1; // don't go to sleep immediately - } else + // don't go to sleep while animating + arg |= smooth_steps_in_progress; #endif - set_level(0); ticks_since_on = 0; #if NUM_CHANNEL_MODES > 1 // reset to ramp mode's channel when light turns off @@ -92,7 +95,7 @@ uint8_t off_state(Event event, uint16_t arg) { #if (B_TIMING_ON == B_PRESS_T) // hold (initially): go to lowest level (floor), but allow abort for regular click else if (event == EV_click1_press) { - set_level(nearest_level(1)); + off_state_set_level(nearest_level(1)); return EVENT_HANDLED; } #endif // B_TIMING_ON == B_PRESS_T @@ -107,7 +110,7 @@ uint8_t off_state(Event event, uint16_t arg) { } else #endif #else // B_RELEASE_T or B_TIMEOUT_T - set_level(nearest_level(1)); + off_state_set_level(nearest_level(1)); #endif #ifdef USE_RAMP_AFTER_MOON_CONFIG if (cfg.dont_ramp_after_moon) { @@ -139,12 +142,7 @@ uint8_t off_state(Event event, uint16_t arg) { manual_memory_restore(); } #endif - #ifdef USE_SMOOTH_STEPS - if (cfg.smooth_steps_style) - set_level_smooth(nearest_level(memorized_level), 8); - else - #endif - set_level(nearest_level(memorized_level)); + off_state_set_level(nearest_level(memorized_level)); return EVENT_HANDLED; } #endif // if (B_TIMING_ON != B_TIMEOUT_T) @@ -186,11 +184,11 @@ uint8_t off_state(Event event, uint16_t arg) { turbo_level = MAX_LEVEL; #endif - set_level(turbo_level); + off_state_set_level(turbo_level); return EVENT_HANDLED; } else if (event == EV_click2_hold_release) { - set_level(0); + off_state_set_level(0); return EVENT_HANDLED; } @@ -206,7 +204,7 @@ uint8_t off_state(Event event, uint16_t arg) { // immediately cancel any animations in progress smooth_steps_in_progress = 0; #endif - set_level(0); + off_state_set_level(0); return EVENT_HANDLED; } @@ -374,3 +372,13 @@ uint8_t off_state(Event event, uint16_t arg) { return EVENT_NOT_HANDLED; } + +void off_state_set_level(uint8_t level) { + // this pattern gets used a few times, so reduce duplication + #ifdef USE_SMOOTH_STEPS + if (cfg.smooth_steps_style) set_level_smooth(level, 8); + else + #endif + set_level(level); +} + diff --git a/spaghetti-monster/anduril/ramp-mode.c b/spaghetti-monster/anduril/ramp-mode.c index 87bfe63..019fa2a 100644 --- a/spaghetti-monster/anduril/ramp-mode.c +++ b/spaghetti-monster/anduril/ramp-mode.c @@ -680,8 +680,12 @@ void set_level_and_therm_target(uint8_t level) { target_level = level; #endif #ifdef USE_SMOOTH_STEPS + // if adjusting by more than 1 ramp level, + // animate the step change (if smooth steps enabled) + uint8_t diff = (level > actual_level) + ? (level - actual_level) : (actual_level - level); if (smooth_steps_in_progress - || (cfg.smooth_steps_style && cfg.ramp_style)) + || (cfg.smooth_steps_style && (diff > 1))) set_level_smooth(level, 4); else #endif -- cgit v1.2.3