diff options
| author | Selene ToyKeeper | 2023-08-26 19:42:04 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2023-08-26 19:42:04 -0600 |
| commit | f245a903db3ff4a693f2874957cd9a671c5e2331 (patch) | |
| tree | 24811f92905c023fcf279c03b33e06191597d816 /spaghetti-monster/anduril/smooth-steps.c | |
| parent | made bike strobe ontime configurable per build, (diff) | |
| download | anduril-f245a903db3ff4a693f2874957cd9a671c5e2331.tar.gz anduril-f245a903db3ff4a693f2874957cd9a671c5e2331.tar.bz2 anduril-f245a903db3ff4a693f2874957cd9a671c5e2331.zip | |
added "smooth steps" a.k.a. "soft start", to make brightness steps smoother
(also made ramp extras config menu count its own steps)
Diffstat (limited to 'spaghetti-monster/anduril/smooth-steps.c')
| -rw-r--r-- | spaghetti-monster/anduril/smooth-steps.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/spaghetti-monster/anduril/smooth-steps.c b/spaghetti-monster/anduril/smooth-steps.c new file mode 100644 index 0000000..9a09228 --- /dev/null +++ b/spaghetti-monster/anduril/smooth-steps.c @@ -0,0 +1,45 @@ +// smooth-steps.c: Smooth step adjustments for Anduril. +// Copyright (C) 2023 Selene ToyKeeper +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "smooth-steps.h" + +#ifdef USE_SMOOTH_STEPS + +// one iteration of main loop() +void smooth_steps_iter() { + if (actual_level == smooth_steps_target) { + smooth_steps_in_progress = 0; + // restore prev_level when animation ends + prev_level = smooth_steps_start; + return; + } + + if (actual_level < smooth_steps_target) { + uint8_t diff = smooth_steps_target - actual_level; + uint8_t this = diff / smooth_steps_speed; + if (!this) this = 1; + set_level(actual_level + this); + } else if (actual_level > smooth_steps_target) { + uint8_t diff = actual_level - smooth_steps_target; + uint8_t this = diff / smooth_steps_speed; + if (!this) this = 1; + set_level(actual_level - this); + } + // TODO: maybe change the delay based on the speed var? + nice_delay_ms(10); +} + +void set_level_smooth(uint8_t level, uint8_t speed) { + smooth_steps_target = level; + // TODO: maybe speed should be a desired total time for the animation? + smooth_steps_speed = speed; + smooth_steps_in_progress = 1; + // for setting prev_level after animation ends + smooth_steps_start = actual_level; +} + +#endif + |
