~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

Viewing changes to ToyKeeper/hwdef-Sofirn_LT1S-Pro.c

  • Committer: Selene ToyKeeper
  • Date: 2023-04-25 07:07:15 UTC
  • mto: (483.1.175 anduril2)
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: bzr@toykeeper.net-20230425070715-yi80xgfowxmbfl6n
updated D4Sv2-tintramp -> Emisar 2-channel build target ...
... and reworked how gradual_tick() works
... and updated LT1S Pro to use new method

Show diffs side-by-side

added added

removed removed

Lines of Context:
155
155
 
156
156
///// "gradual tick" functions for smooth thermal regulation /////
157
157
 
158
 
void gradual_tick_red() {
159
 
    GRADUAL_TICK_SETUP();
160
 
 
161
 
    GRADUAL_ADJUST_1CH(pwm1_levels, RED_PWM_LVL);
162
 
 
163
 
    if ((RED_PWM_LVL  == PWM_GET(pwm1_levels,  gt)))
164
 
    {
165
 
        GRADUAL_IS_ACTUAL();
 
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);
 
163
 
 
164
    // check for completion
 
165
    if ((red  == RED_PWM_LVL )
 
166
     && (warm == WARM_PWM_LVL)
 
167
     && (cool == COOL_PWM_LVL)) {
 
168
        return true;  // done
166
169
    }
167
 
}
168
 
 
169
 
 
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;
174
 
    gt --;
175
 
 
 
170
    return false;  // not done yet
 
171
}
 
172
 
 
173
bool gradual_tick_red(uint8_t gt) {
 
174
    uint16_t red = PWM_GET(pwm1_levels, gt);
 
175
    return gradual_adjust(red, 0, 0);
 
176
}
 
177
 
 
178
 
 
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);
181
185
 
182
186
    calc_2ch_blend(&warm_PWM, &cool_PWM, brightness, top, blend);
183
187
 
184
 
    // move up/down if necessary
185
 
    GRADUAL_ADJUST_SIMPLE(warm_PWM, WARM_PWM_LVL);
186
 
    GRADUAL_ADJUST_SIMPLE(cool_PWM, COOL_PWM_LVL);
187
 
 
188
 
    // check for completion
189
 
    if (   (WARM_PWM_LVL == warm_PWM)
190
 
        && (COOL_PWM_LVL == cool_PWM)
191
 
       )
192
 
    {
193
 
        GRADUAL_IS_ACTUAL();
194
 
    }
 
188
    return gradual_adjust(0, warm_PWM, cool_PWM);
195
189
}
196
190
 
197
191
 
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;
203
 
    gt --;
204
 
 
 
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);
210
199
 
211
200
    calc_2ch_blend(&warm_PWM, &cool_PWM, brightness, top, blend);
212
201
 
213
 
    // move up/down if necessary
214
 
    GRADUAL_ADJUST_SIMPLE(warm_PWM, WARM_PWM_LVL);
215
 
    GRADUAL_ADJUST_SIMPLE(cool_PWM, COOL_PWM_LVL);
216
 
 
217
 
    // check for completion
218
 
    if (   (WARM_PWM_LVL == warm_PWM)
219
 
        && (COOL_PWM_LVL == cool_PWM)
220
 
       )
221
 
    {
222
 
        GRADUAL_IS_ACTUAL();
223
 
    }
 
202
    return gradual_adjust(0, warm_PWM, cool_PWM);
224
203
}
225
204
 
226
205
 
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;
231
 
    gt --;
232
 
 
 
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);
236
 
 
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);
241
 
 
242
 
    // check for completion
243
 
    if (   (RED_PWM_LVL  == red)
244
 
        && (WARM_PWM_LVL == warm)
245
 
        && (COOL_PWM_LVL == cool)
246
 
       )
247
 
    {
248
 
        GRADUAL_IS_ACTUAL();
249
 
    }
 
210
    return gradual_adjust(red, warm, cool);
250
211
}
251
212
 
252
213
 
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];
 
221
 
 
222
    red = (((PWM_DATATYPE2)ratio * (PWM_DATATYPE2)brightness) + 127) / 255;
 
223
    calc_2ch_blend(&warm, &cool, brightness, top, blend);
 
224
 
 
225
    return gradual_adjust(red, warm, cool);
261
226
}
262
227