~toykeeper/flashlight-firmware/trunk

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/werner/werner.c

  • Committer: Selene Scriven
  • Date: 2020-07-06 20:24:28 UTC
  • mfrom: (188.1.294 fsm)
  • Revision ID: bzr@toykeeper.net-20200706202428-7pyen2ow9q2rtd9p
merged nearly a year of updates from the fsm branch, including the new product map

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
//#define BATTCHECK_8bars  // FIXME: breaks build
34
34
//#define BATTCHECK_4bars  // FIXME: breaks build
35
35
 
 
36
// cut clock speed at very low modes for better efficiency
 
37
// (defined here so config files can override it)
 
38
#define USE_DYNAMIC_UNDERCLOCKING
 
39
 
36
40
/***** specific settings for known driver types *****/
37
41
#ifdef CONFIGFILE
38
42
#include "tk.h"
63
67
#define RAMP_LENGTH 150  // default, if not overridden in a driver cfg file
64
68
#define USE_BATTCHECK
65
69
#define USE_IDLE_MODE  // reduce power use while awake and no tasks are pending
66
 
#define USE_DYNAMIC_UNDERCLOCKING  // cut clock speed at very low modes for better efficiency
67
70
 
68
71
// auto-detect how many eeprom bytes
69
72
#define USE_EEPROM
369
372
        set_state(off_state, 0);
370
373
        return MISCHIEF_MANAGED;
371
374
    }
 
375
    #ifdef USE_THERMAL_REGULATION
372
376
    // 2 clicks: tempcheck mode
373
377
    else if (event == EV_2clicks) {
374
378
        blink_confirm(2);
375
379
        set_state(tempcheck_state, 0);
376
380
        return MISCHIEF_MANAGED;
377
381
    }
 
382
    #endif
378
383
    return EVENT_NOT_HANDLED;
379
384
}
380
385
#endif
467
472
    // calibrate room temperature
468
473
    val = config_state_values[0];
469
474
    if (val) {
470
 
        int8_t rawtemp = (temperature >> 1) - therm_cal_offset;
 
475
        int8_t rawtemp = temperature - therm_cal_offset;
471
476
        therm_cal_offset = val - rawtemp;
 
477
        reset_thermal_history = 1;  // invalidate all recent temperature data
472
478
    }
473
479
 
474
480
    val = config_state_values[1];
475
481
    if (val) {
476
482
        // set maximum heat limit
477
 
        therm_ceil = 30 + val;
 
483
        therm_ceil = 30 + val - 1;
478
484
    }
479
485
    if (therm_ceil > MAX_THERM_CEIL) therm_ceil = MAX_THERM_CEIL;
480
486
}
589
595
 
590
596
    for(uint8_t i=0; i<ramp_discrete_steps; i++) {
591
597
        this_level = ramp_discrete_floor + (i * (uint16_t)ramp_range / (ramp_discrete_steps-1));
592
 
        int8_t diff = target - this_level;
 
598
        int16_t diff = target - this_level;
593
599
        if (diff < 0) diff = -diff;
594
600
        if (diff <= (ramp_discrete_step_size>>1))
595
601
            return this_level;
684
690
 
685
691
    StatePtr state = current_state;
686
692
 
687
 
    #ifdef USE_DYNAMIC_UNDERCLOCKING
688
 
    auto_clock_speed();
689
 
    #endif
690
693
    if (0) {}
691
694
 
692
695
    #ifdef USE_BATTCHECK
697
700
    #ifdef USE_THERMAL_REGULATION
698
701
    // TODO: blink out therm_ceil during thermal_config_state
699
702
    else if (state == tempcheck_state) {
700
 
        blink_num(temperature>>1);
 
703
        blink_num(temperature);
701
704
        nice_delay_ms(1000);
702
705
    }
703
706
    #endif