diff options
Diffstat (limited to 'hwdef-Sofirn_LT1S-Pro.c')
| -rw-r--r-- | hwdef-Sofirn_LT1S-Pro.c | 74 |
1 files changed, 7 insertions, 67 deletions
diff --git a/hwdef-Sofirn_LT1S-Pro.c b/hwdef-Sofirn_LT1S-Pro.c index a6d2b8f..f617933 100644 --- a/hwdef-Sofirn_LT1S-Pro.c +++ b/hwdef-Sofirn_LT1S-Pro.c @@ -5,66 +5,6 @@ #pragma once -// calculate a "tint ramp" blend between 2 channels -// results are placed in *warm and *cool vars -// brightness : total amount of light units to distribute -// top : maximum allowed brightness per channel -// blend : ratio between warm and cool (0 = warm, 128 = 50%, 255 = cool) -void calc_2ch_blend( - PWM_DATATYPE *warm, - PWM_DATATYPE *cool, - PWM_DATATYPE brightness, - PWM_DATATYPE top, - uint8_t blend) { - - #ifndef TINT_RAMPING_CORRECTION - #define TINT_RAMPING_CORRECTION 26 // 140% brightness at middle tint - #endif - - // calculate actual PWM levels based on a single-channel ramp - // and a blend value - PWM_DATATYPE warm_PWM, cool_PWM; - PWM_DATATYPE2 base_PWM = brightness; - - #if defined(TINT_RAMPING_CORRECTION) && (TINT_RAMPING_CORRECTION > 0) - uint8_t level = actual_level - 1; - - // 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(blend) / 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(blend) / 255 - ); - } - // guarantee no more than 200% power - if (base_PWM > (top << 1)) { base_PWM = top << 1; } - #endif - - cool_PWM = (((PWM_DATATYPE2)blend * (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; - } - - *warm = warm_PWM; - *cool = cool_PWM; -} - - // calculate a 3-channel "auto tint" blend // (like red -> warm white -> cool white) // results are placed in *a, *b, and *c vars @@ -126,7 +66,7 @@ void set_level_white_blend(uint8_t level) { PWM_DATATYPE warm_PWM, cool_PWM; PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level); PWM_DATATYPE top = PWM_GET(pwm_tops, level); - uint8_t blend = channel_mode_args[channel_mode]; + uint8_t blend = cfg.channel_mode_args[cfg.channel_mode]; calc_2ch_blend(&warm_PWM, &cool_PWM, brightness, top, blend); @@ -166,9 +106,9 @@ void set_level_auto_3ch_blend(uint8_t level) { // "white + red" channel mode void set_level_red_white_blend(uint8_t level) { // set the warm+cool white LEDs first - channel_mode = CM_WHITE; + cfg.channel_mode = CM_WHITE; set_level_white_blend(level); - channel_mode = CM_WHITE_RED; + cfg.channel_mode = CM_WHITE_RED; if (level == 0) { RED_PWM_LVL = 0; @@ -182,7 +122,7 @@ void set_level_red_white_blend(uint8_t level) { // set the red LED as a ratio of the white output level // 0 = no red // 255 = red at 100% of white channel PWM - uint8_t ratio = channel_mode_args[channel_mode]; + uint8_t ratio = cfg.channel_mode_args[cfg.channel_mode]; RED_PWM_LVL = (((PWM_DATATYPE2)ratio * (PWM_DATATYPE2)vpwm) + 127) / 255; if (! actual_level) PWM_CNT = 0; // reset phase @@ -213,7 +153,7 @@ void gradual_tick_white_blend() { PWM_DATATYPE warm_PWM, cool_PWM; PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt); PWM_DATATYPE top = PWM_GET(pwm_tops, gt); - uint8_t blend = channel_mode_args[channel_mode]; + uint8_t blend = cfg.channel_mode_args[cfg.channel_mode]; calc_2ch_blend(&warm_PWM, &cool_PWM, brightness, top, blend); @@ -259,9 +199,9 @@ void gradual_tick_auto_3ch_blend() { void gradual_tick_red_white_blend() { // do the white blend thing... - channel_mode = CM_WHITE; + cfg.channel_mode = CM_WHITE; gradual_tick_white_blend(); - channel_mode = CM_WHITE_RED; + cfg.channel_mode = CM_WHITE_RED; // ... and then update red to the closest ramp level // (coarse red adjustments aren't visible here anyway) set_level_red(actual_level); |
