aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-ramping.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2019-05-22 21:08:04 -0600
committerSelene ToyKeeper2019-05-22 21:08:04 -0600
commitb17fb36ccf2daec18894e9cb555615019589c5c4 (patch)
tree728ed9facd86ccc2527e1555e4fa8acbfd66c5de /spaghetti-monster/fsm-ramping.c
parentsmoothed out MF01S tint "pop" a little more by making a few steps which are s... (diff)
parentD4S actually steps down a bit too fast, so... minimize that (diff)
downloadanduril-b17fb36ccf2daec18894e9cb555615019589c5c4.tar.gz
anduril-b17fb36ccf2daec18894e9cb555615019589c5c4.tar.bz2
anduril-b17fb36ccf2daec18894e9cb555615019589c5c4.zip
merged from fsm branch to get a bunch of new updates
Diffstat (limited to 'spaghetti-monster/fsm-ramping.c')
-rw-r--r--spaghetti-monster/fsm-ramping.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c
index ee816dd..082f8c9 100644
--- a/spaghetti-monster/fsm-ramping.c
+++ b/spaghetti-monster/fsm-ramping.c
@@ -65,8 +65,31 @@ void set_level(uint8_t level) {
// and a global tint value
uint8_t brightness = pgm_read_byte(pwm1_levels + level);
uint8_t warm_PWM, cool_PWM;
- cool_PWM = (((uint16_t)tint * (uint16_t)brightness) + 127) / 255;
- warm_PWM = brightness - cool_PWM;
+
+ // auto-tint modes
+ uint8_t mytint;
+ #if 1
+ // perceptual by ramp level
+ if (tint == 0) { mytint = 255 * (uint16_t)level / RAMP_SIZE; }
+ else if (tint == 255) { mytint = 255 - (255 * (uint16_t)level / RAMP_SIZE); }
+ #else
+ // linear with power level
+ //if (tint == 0) { mytint = brightness; }
+ //else if (tint == 255) { mytint = 255 - brightness; }
+ #endif
+ // stretch 1-254 to fit 0-255 range (hits every value except 98 and 198)
+ else { mytint = (tint * 100 / 99) - 1; }
+
+ // middle tints sag, so correct for that effect
+ uint16_t base_PWM = brightness;
+ // correction is only necessary when PWM is fast
+ if (level > HALFSPEED_LEVEL) {
+ base_PWM = brightness
+ + ((((uint16_t)brightness) * 26 / 64) * triangle_wave(mytint) / 255);
+ }
+
+ cool_PWM = (((uint16_t)mytint * (uint16_t)base_PWM) + 127) / 255;
+ warm_PWM = base_PWM - cool_PWM;
PWM1_LVL = warm_PWM;
PWM2_LVL = cool_PWM;