diff options
| author | Selene ToyKeeper | 2019-05-14 01:42:44 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2019-05-14 01:42:44 -0600 |
| commit | 310074c6cf46f3e76873c027b2235457ca35c151 (patch) | |
| tree | a2d97f4c55390a80261ec38284b6359e79c29d16 /spaghetti-monster | |
| parent | moved triangle_wave into fsm-misc, because I need it for power correction in ... (diff) | |
| download | anduril-310074c6cf46f3e76873c027b2235457ca35c151.tar.gz anduril-310074c6cf46f3e76873c027b2235457ca35c151.tar.bz2 anduril-310074c6cf46f3e76873c027b2235457ca35c151.zip | |
added tint ramping power correction for middle tints
(it actually needs a surprisingly large correction factor)
Diffstat (limited to 'spaghetti-monster')
| -rw-r--r-- | spaghetti-monster/fsm-ramping.c | 23 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-ramping.h | 1 |
2 files changed, 18 insertions, 6 deletions
diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 27e3876..1dbb969 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -68,17 +68,28 @@ void set_level(uint8_t level) { // auto-tint modes uint8_t mytint; - // linear with power level - //if (tint == 0) { mytint = brightness; } - //else if (tint == 255) { mytint = 255 - brightness; } + #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); } - // stretch 1-254 to fit 0-255 range + #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; } - cool_PWM = (((uint16_t)mytint * (uint16_t)brightness) + 127) / 255; - warm_PWM = brightness - cool_PWM; + // 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 + + ((brightness>>1) * 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; diff --git a/spaghetti-monster/fsm-ramping.h b/spaghetti-monster/fsm-ramping.h index 4ce8015..dcc3b74 100644 --- a/spaghetti-monster/fsm-ramping.h +++ b/spaghetti-monster/fsm-ramping.h @@ -28,6 +28,7 @@ volatile uint8_t actual_level = 0; #ifdef USE_TINT_RAMPING uint8_t tint = 128; +#define USE_TRIANGLE_WAVE #endif #ifdef USE_SET_LEVEL_GRADUALLY |
