~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/fsm-ramping.c

  • Committer: Selene ToyKeeper
  • Date: 2023-04-15 02:51:40 UTC
  • mto: (483.1.175 anduril2)
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: bzr@toykeeper.net-20230415025140-w9jhr98lug222las
LT1S: added thermal regulation
... and a bunch of gradual_tick functions
... and abstracted out some of the tint calculations
... and moved some UI settings into cfg.h

Show diffs side-by-side

added added

removed removed

Lines of Context:
344
344
}
345
345
 
346
346
 
347
 
// reduce repetition with macros
348
 
// common code at the beginning of every gradual tick handler
349
 
#define GRADUAL_TICK_SETUP()  \
350
 
    uint8_t gt = gradual_target;  \
351
 
    if (gt < actual_level) gt = actual_level - 1;  \
352
 
    else if (gt > actual_level) gt = actual_level + 1;  \
353
 
    gt --;  \
354
 
    PWM_DATATYPE target;
355
 
 
356
 
// tick the top layer of the stack
357
 
#define GRADUAL_ADJUST_1CH(TABLE,PWM)  \
358
 
    target = PWM_GET(TABLE, gt);  \
359
 
    if (PWM < target) PWM ++;  \
360
 
    else if (PWM > target) PWM --;
361
 
 
362
 
// tick a base level of the stack
363
 
// (with support for special DD FET behavior
364
 
//  like "low=0, high=255" --> "low=255, high=254")
365
 
#define GRADUAL_ADJUST(TABLE,PWM,TOP)  \
366
 
    target = PWM_GET(TABLE, gt);  \
367
 
    if ((gt < actual_level)  \
368
 
        && (PWM == 0)  \
369
 
        && (target == TOP)) PWM = TOP;  \
370
 
    else  \
371
 
    if (PWM < target) PWM ++;  \
372
 
    else if (PWM > target) PWM --;
373
 
 
374
 
// do this when output exactly matches a ramp level
375
 
#define GRADUAL_IS_ACTUAL()  \
376
 
    uint8_t orig = gradual_target;  \
377
 
    set_level(gt + 1);  \
378
 
    gradual_target = orig;
379
 
 
380
347
#ifdef USE_GRADUAL_TICK_1CH
381
348
void gradual_tick_1ch() {
382
349
    GRADUAL_TICK_SETUP();