From e5864361c5e05aa5356d06cba6a19441ea0dc996 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 10 Sep 2017 16:38:40 -0600 Subject: 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 --- spaghetti-monster/anduril/anduril.c | 1 - spaghetti-monster/fsm-ramping.c | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index 6cc0095..3d08b26 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -320,7 +320,6 @@ uint8_t steady_state(EventPtr event, uint16_t arg) { } #endif #ifdef USE_THERMAL_REGULATION - // TODO: test this on a real light // overheating: drop by an amount proportional to how far we are above the ceiling else if (event == EV_temperature_high) { /* 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 -- cgit v1.2.3