156
156
///// "gradual tick" functions for smooth thermal regulation /////
158
void gradual_tick_red() {
159
GRADUAL_TICK_SETUP();
161
GRADUAL_ADJUST_1CH(pwm1_levels, RED_PWM_LVL);
163
if ((RED_PWM_LVL == PWM_GET(pwm1_levels, gt)))
158
///// bump each channel toward a target value /////
159
bool gradual_adjust(uint16_t red, uint16_t warm, uint16_t cool) {
160
GRADUAL_ADJUST_SIMPLE(red, RED_PWM_LVL );
161
GRADUAL_ADJUST_SIMPLE(warm, WARM_PWM_LVL);
162
GRADUAL_ADJUST_SIMPLE(cool, COOL_PWM_LVL);
164
// check for completion
165
if ((red == RED_PWM_LVL )
166
&& (warm == WARM_PWM_LVL)
167
&& (cool == COOL_PWM_LVL)) {
170
void gradual_tick_white_blend() {
171
uint8_t gt = gradual_target;
172
if (gt < actual_level) gt = actual_level - 1;
173
else if (gt > actual_level) gt = actual_level + 1;
170
return false; // not done yet
173
bool gradual_tick_red(uint8_t gt) {
174
uint16_t red = PWM_GET(pwm1_levels, gt);
175
return gradual_adjust(red, 0, 0);
179
bool gradual_tick_white_blend(uint8_t gt) {
176
180
// figure out what exact PWM levels we're aiming for
177
181
PWM_DATATYPE warm_PWM, cool_PWM;
178
182
PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt);
182
186
calc_2ch_blend(&warm_PWM, &cool_PWM, brightness, top, blend);
184
// move up/down if necessary
185
GRADUAL_ADJUST_SIMPLE(warm_PWM, WARM_PWM_LVL);
186
GRADUAL_ADJUST_SIMPLE(cool_PWM, COOL_PWM_LVL);
188
// check for completion
189
if ( (WARM_PWM_LVL == warm_PWM)
190
&& (COOL_PWM_LVL == cool_PWM)
188
return gradual_adjust(0, warm_PWM, cool_PWM);
198
192
// same as white blend, but tint is calculated from the ramp level
199
void gradual_tick_auto_2ch_blend() {
200
uint8_t gt = gradual_target;
201
if (gt < actual_level) gt = actual_level - 1;
202
else if (gt > actual_level) gt = actual_level + 1;
193
bool gradual_tick_auto_2ch_blend(uint8_t gt) {
205
194
// figure out what exact PWM levels we're aiming for
206
195
PWM_DATATYPE warm_PWM, cool_PWM;
207
196
PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt);
211
200
calc_2ch_blend(&warm_PWM, &cool_PWM, brightness, top, blend);
213
// move up/down if necessary
214
GRADUAL_ADJUST_SIMPLE(warm_PWM, WARM_PWM_LVL);
215
GRADUAL_ADJUST_SIMPLE(cool_PWM, COOL_PWM_LVL);
217
// check for completion
218
if ( (WARM_PWM_LVL == warm_PWM)
219
&& (COOL_PWM_LVL == cool_PWM)
202
return gradual_adjust(0, warm_PWM, cool_PWM);
227
void gradual_tick_auto_3ch_blend() {
228
uint8_t gt = gradual_target;
229
if (gt < actual_level) gt = actual_level - 1;
230
else if (gt > actual_level) gt = actual_level + 1;
206
bool gradual_tick_auto_3ch_blend(uint8_t gt) {
233
207
// figure out what exact PWM levels we're aiming for
234
208
PWM_DATATYPE red, warm, cool;
235
209
calc_auto_3ch_blend(&red, &warm, &cool, gt);
237
// move up/down if necessary
238
GRADUAL_ADJUST_SIMPLE(red, RED_PWM_LVL);
239
GRADUAL_ADJUST_SIMPLE(warm, WARM_PWM_LVL);
240
GRADUAL_ADJUST_SIMPLE(cool, COOL_PWM_LVL);
242
// check for completion
243
if ( (RED_PWM_LVL == red)
244
&& (WARM_PWM_LVL == warm)
245
&& (COOL_PWM_LVL == cool)
210
return gradual_adjust(red, warm, cool);
253
void gradual_tick_red_white_blend() {
254
// do the white blend thing...
255
cfg.channel_mode = CM_WHITE;
256
gradual_tick_white_blend();
257
cfg.channel_mode = CM_WHITE_RED;
258
// ... and then update red to the closest ramp level
259
// (coarse red adjustments aren't visible here anyway)
260
set_level_red(actual_level);
214
bool gradual_tick_red_white_blend(uint8_t gt) {
215
// figure out what exact PWM levels we're aiming for
216
PWM_DATATYPE red, warm, cool;
217
PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt);
218
PWM_DATATYPE top = PWM_GET(pwm_tops, gt);
219
uint8_t blend = cfg.channel_mode_args[CM_WHITE];
220
uint8_t ratio = cfg.channel_mode_args[cfg.channel_mode];
222
red = (((PWM_DATATYPE2)ratio * (PWM_DATATYPE2)brightness) + 127) / 255;
223
calc_2ch_blend(&warm, &cool, brightness, top, blend);
225
return gradual_adjust(red, warm, cool);