diff options
| author | Selene ToyKeeper | 2021-10-31 02:35:49 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2021-10-31 02:35:49 -0600 |
| commit | 4b4353ade4c026c196e2b6edacbb0dc437e3ddda (patch) | |
| tree | fdba5c77f4e8b703af0722ff64684f3ead40d8e6 /spaghetti-monster/fsm-ramping.c | |
| parent | Clarified Ramp->2C behavior a bit more. (diff) | |
| download | anduril-4b4353ade4c026c196e2b6edacbb0dc437e3ddda.tar.gz anduril-4b4353ade4c026c196e2b6edacbb0dc437e3ddda.tar.bz2 anduril-4b4353ade4c026c196e2b6edacbb0dc437e3ddda.zip | |
added "200%" turbo on tint-ramping lights: D4S and LT1
Normal ramp from 0% to 100% power on levels 1 to 130,
then 101% to 200% power at levels 131 to 150
using both channels at maximum for turbo.
When either channel would go over 100%, the extra
spills over to the other channel.
Diffstat (limited to '')
| -rw-r--r-- | spaghetti-monster/fsm-ramping.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 05c2e0e..ee72cd7 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -293,8 +293,14 @@ void update_tint() { // calculate actual PWM levels based on a single-channel ramp // and a global tint value //PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level); - PWM_DATATYPE brightness = PWM1_LVL; - PWM_DATATYPE warm_PWM, cool_PWM; + uint16_t brightness = PWM1_LVL; + uint16_t warm_PWM, cool_PWM; + #ifdef USE_DYN_PWM + uint16_t top = PWM1_TOP; + //uint16_t top = PWM_GET(pwm_tops, actual_level-1); + #else + const uint16_t top = PWM_TOP; + #endif // auto-tint modes uint8_t mytint; @@ -311,18 +317,37 @@ void update_tint() { // 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 PWM_DATATYPE2 base_PWM = brightness; - // correction is only necessary when PWM is fast #if defined(TINT_RAMPING_CORRECTION) && (TINT_RAMPING_CORRECTION > 0) + // middle tints sag, so correct for that effect + // by adding extra power which peaks at the middle tint + // (correction is only necessary when PWM is fast) if (level > HALFSPEED_LEVEL) { base_PWM = brightness + ((((PWM_DATATYPE2)brightness) * TINT_RAMPING_CORRECTION / 64) * triangle_wave(mytint) / 255); } + // fade the triangle wave out when above 100% power, + // so it won't go over 200% + if (brightness > top) { + base_PWM -= 2 * ( + ((brightness - top) * TINT_RAMPING_CORRECTION / 64) + * triangle_wave(mytint) / 255 + ); + } + // guarantee no more than 200% power + if (base_PWM > (top << 1)) { base_PWM = top << 1; } #endif cool_PWM = (((PWM_DATATYPE2)mytint * (PWM_DATATYPE2)base_PWM) + 127) / 255; warm_PWM = base_PWM - cool_PWM; + // when running at > 100% power, spill extra over to other channel + if (cool_PWM > top) { + warm_PWM += (cool_PWM - top); + cool_PWM = top; + } else if (warm_PWM > top) { + cool_PWM += (warm_PWM - top); + warm_PWM = top; + } TINT1_LVL = warm_PWM; TINT2_LVL = cool_PWM; |
