From 215a56b08586dcf4352b6eb2713f5238a4d5b360 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 13 Sep 2018 03:44:23 -0600 Subject: Added tint ramping. Not tested yet. Also added BLF Lantern build target. --- spaghetti-monster/fsm-ramping.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'spaghetti-monster/fsm-ramping.c') diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 6cdf5e6..0492943 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -25,9 +25,20 @@ void set_level(uint8_t level) { actual_level = level; + + #ifdef USE_TINT_RAMPING + // calculate actual PWM levels based on a single-channel ramp + // 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 * brightness / 255; + warm_PWM = brightness - cool_PWM; + #endif + #ifdef USE_SET_LEVEL_GRADUALLY gradual_target = level; #endif + #ifdef USE_INDICATOR_LED #ifdef USE_INDICATOR_LED_WHILE_RAMPING if (! go_to_standby) @@ -40,6 +51,7 @@ void set_level(uint8_t level) { indicator_led(0); #endif #endif + //TCCR0A = PHASE; if (level == 0) { #if PWM_CHANNELS >= 1 @@ -56,6 +68,12 @@ void set_level(uint8_t level) { #endif } else { level --; + + #ifdef USE_TINT_RAMPING + PWM1_LVL = warm_PWM; + PWM2_LVL = cool_PWM; + #else + #if PWM_CHANNELS >= 1 PWM1_LVL = pgm_read_byte(pwm1_levels + level); #endif @@ -68,6 +86,8 @@ void set_level(uint8_t level) { #if PWM_CHANNELS >= 4 PWM4_LVL = pgm_read_byte(pwm4_levels + level); #endif + + #endif // ifdef USE_TINT_RAMPING } #ifdef USE_DYNAMIC_UNDERCLOCKING auto_clock_speed(); -- cgit v1.2.3 From 4b93b02d6d966f4bda4ea90499601b52430c62f8 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 13 Sep 2018 04:30:02 -0600 Subject: fixed tint ramp brightness being off by one level, and eliminated bias toward first PWM channel --- spaghetti-monster/fsm-ramping.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'spaghetti-monster/fsm-ramping.c') diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 0492943..ee816dd 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -26,15 +26,6 @@ void set_level(uint8_t level) { actual_level = level; - #ifdef USE_TINT_RAMPING - // calculate actual PWM levels based on a single-channel ramp - // 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 * brightness / 255; - warm_PWM = brightness - cool_PWM; - #endif - #ifdef USE_SET_LEVEL_GRADUALLY gradual_target = level; #endif @@ -70,6 +61,13 @@ void set_level(uint8_t level) { level --; #ifdef USE_TINT_RAMPING + // calculate actual PWM levels based on a single-channel ramp + // 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; + PWM1_LVL = warm_PWM; PWM2_LVL = cool_PWM; #else -- cgit v1.2.3 From a337ca16cf33f9e7e0747a1ea0af53930ec47318 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 14 May 2019 00:25:18 -0600 Subject: added auto-tint modes, refactored some indicator blinks into "blip()", enabled blink at ceiling for lantern --- spaghetti-monster/fsm-ramping.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'spaghetti-monster/fsm-ramping.c') diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index ee816dd..27e3876 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -65,7 +65,19 @@ 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; + + // auto-tint modes + uint8_t mytint; + // linear with power level + //if (tint == 0) { mytint = brightness; } + //else if (tint == 255) { mytint = 255 - brightness; } + // 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 { mytint = (tint * 100 / 99) - 1; } + + cool_PWM = (((uint16_t)mytint * (uint16_t)brightness) + 127) / 255; warm_PWM = brightness - cool_PWM; PWM1_LVL = warm_PWM; -- cgit v1.2.3 From 310074c6cf46f3e76873c027b2235457ca35c151 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 14 May 2019 01:42:44 -0600 Subject: added tint ramping power correction for middle tints (it actually needs a surprisingly large correction factor) --- spaghetti-monster/fsm-ramping.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'spaghetti-monster/fsm-ramping.c') 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; -- cgit v1.2.3 From 1961c3a6950cefa05cdb6e4b0d1967371f7da9f4 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 14 May 2019 03:16:33 -0600 Subject: the lantern middle-tint power correction factor wasn't quite right... ... so I adjusted it to make the result closer to a flat curve --- spaghetti-monster/fsm-ramping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spaghetti-monster/fsm-ramping.c') diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 1dbb969..082f8c9 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -85,7 +85,7 @@ void set_level(uint8_t level) { // correction is only necessary when PWM is fast if (level > HALFSPEED_LEVEL) { base_PWM = brightness - + ((brightness>>1) * triangle_wave(mytint) / 255); + + ((((uint16_t)brightness) * 26 / 64) * triangle_wave(mytint) / 255); } cool_PWM = (((uint16_t)mytint * (uint16_t)base_PWM) + 127) / 255; -- cgit v1.2.3