aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-ramping.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2017-09-10 16:38:40 -0600
committerSelene ToyKeeper2017-09-10 16:38:40 -0600
commite5864361c5e05aa5356d06cba6a19441ea0dc996 (patch)
tree93309c8dafc981338a15018dcbddbcae80f3532f /spaghetti-monster/fsm-ramping.c
parentApplied recent changes to UI description text. (diff)
downloadanduril-e5864361c5e05aa5356d06cba6a19441ea0dc996.tar.gz
anduril-e5864361c5e05aa5356d06cba6a19441ea0dc996.tar.bz2
anduril-e5864361c5e05aa5356d06cba6a19441ea0dc996.zip
Fixed a bug in gradual_tick(), I think.
It was off by one, and caused actual_level to be off by one, which caused other parts of the code to do weird things... - end-of-ramp blink would happen repeatedly. - ramping up went slower (or not at all, with gradual_tick on each tick) - would sometimes trigger underheating code at moon level, and then glide up to the minimum regulation floor
Diffstat (limited to 'spaghetti-monster/fsm-ramping.c')
-rw-r--r--spaghetti-monster/fsm-ramping.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c
index 092c242..cc5f486 100644
--- a/spaghetti-monster/fsm-ramping.c
+++ b/spaghetti-monster/fsm-ramping.c
@@ -67,10 +67,12 @@ inline void set_level_gradually(uint8_t lvl) {
// call this every frame or every few frames to change brightness very smoothly
void gradual_tick() {
// go by only one ramp level at a time instead of directly to the target
- uint8_t gt = gradual_target - 1;
+ uint8_t gt = gradual_target;
if (gt < actual_level) gt = actual_level - 1;
else if (gt > actual_level) gt = actual_level + 1;
+ gt --; // convert 1-based number to 0-based
+
uint8_t target;
#if PWM_CHANNELS >= 1
@@ -111,7 +113,7 @@ void gradual_tick() {
#endif
)
{
- actual_level = gt;
+ actual_level = gt + 1;
}
}
#endif