diff options
| author | Selene ToyKeeper | 2019-12-17 18:35:30 -0700 |
|---|---|---|
| committer | Selene ToyKeeper | 2019-12-17 18:35:30 -0700 |
| commit | 6fb89b14ecae8e629b9d8ad754f988804d273828 (patch) | |
| tree | b5cd330aed040cde14056c1788e72c41446976a4 /spaghetti-monster | |
| parent | changed voltage colors to better match Noctigon K1 (diff) | |
| parent | fixed too-slow thermal response (was introduced in the irq-refactor branch) (diff) | |
| download | anduril-6fb89b14ecae8e629b9d8ad754f988804d273828.tar.gz anduril-6fb89b14ecae8e629b9d8ad754f988804d273828.tar.bz2 anduril-6fb89b14ecae8e629b9d8ad754f988804d273828.zip | |
merged from fsm, mostly to get thermal regulation updates
Diffstat (limited to '')
| -rw-r--r-- | spaghetti-monster/anduril/anduril.c | 29 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-blf-lantern.h | 4 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-ff-pl47g2.h | 60 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-ff-rot66g2.h | 49 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-fw3a-nofet.h | 36 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-adc.c | 13 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-ramping.c | 5 |
7 files changed, 187 insertions, 9 deletions
diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index c3a1d8a..9348262 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -79,6 +79,9 @@ // enable beacon mode #define USE_BEACON_MODE +// enable momentary mode +#define USE_MOMENTARY_MODE + //Muggle mode for easy UI #define USE_MUGGLE_MODE @@ -296,10 +299,12 @@ uint8_t sos_state(Event event, uint16_t arg); // if enabled, 2nd lockout click goes to the other ramp's floor level #define LOCKOUT_MOON_FANCY uint8_t lockout_state(Event event, uint16_t arg); +#ifdef USE_MOMENTARY_MODE // momentary / signalling mode uint8_t momentary_state(Event event, uint16_t arg); uint8_t momentary_mode = 0; // 0 = ramping, 1 = strobe uint8_t momentary_active = 0; // boolean, true if active *right now* +#endif #ifdef USE_MUGGLE_MODE // muggle mode, super-simple, hard to exit uint8_t muggle_state(Event event, uint16_t arg); @@ -644,12 +649,14 @@ uint8_t off_state(Event event, uint16_t arg) { set_state(lockout_state, 0); return MISCHIEF_MANAGED; } + #ifdef USE_MOMENTARY_MODE // 5 clicks: momentary mode else if (event == EV_5clicks) { blink_confirm(1); set_state(momentary_state, 0); return MISCHIEF_MANAGED; } + #endif #ifdef USE_MUGGLE_MODE // 6 clicks: muggle mode else if (event == EV_6clicks) { @@ -704,7 +711,7 @@ uint8_t off_state(Event event, uint16_t arg) { return MISCHIEF_MANAGED; } #endif // end 7 clicks - #ifdef USE_TENCLICK_THERMAL_CONFIG + #if defined(USE_TENCLICK_THERMAL_CONFIG) && defined(USE_THERMAL_REGULATION) // 10 clicks: thermal config mode else if (event == EV_10clicks) { push_state(thermal_config_state, 0); @@ -749,7 +756,9 @@ uint8_t steady_state(Event event, uint16_t arg) { // turn LED on when we first enter the mode if ((event == EV_enter_state) || (event == EV_reenter_state)) { + #if defined(USE_MOMENTARY_MODE) && defined(USE_STROBE_STATE) momentary_mode = 0; // 0 = ramping, 1 = strobes + #endif // if we just got back from config mode, go back to memorized level if (event == EV_reenter_state) { arg = memorized_level; @@ -1145,7 +1154,9 @@ uint8_t strobe_state(Event event, uint16_t arg) { // (maybe I should just make it nonvolatile?) strobe_mode_te st = strobe_type; + #ifdef USE_MOMENTARY_MODE momentary_mode = 1; // 0 = ramping, 1 = strobes + #endif #ifdef USE_CANDLE_MODE // pass all events to candle mode, when it's active @@ -1668,9 +1679,15 @@ uint8_t goodnight_state(Event event, uint16_t arg) { set_state(off_state, 0); return MISCHIEF_MANAGED; } - // 2 clicks: beacon mode + // 2 clicks: next mode else if (event == EV_2clicks) { + #ifdef USE_BEACON_MODE set_state(beacon_state, 0); + #elif defined(USE_SOS_MODE_IN_BLINKY_GROUP) + set_state(sos_state, 0); + #elif defined(USE_THERMAL_REGULATION) + set_state(tempcheck_state, 0); + #endif return MISCHIEF_MANAGED; } // tick: step down (maybe) or off (maybe) @@ -1824,6 +1841,7 @@ uint8_t lockout_state(Event event, uint16_t arg) { } +#ifdef USE_MOMENTARY_MODE uint8_t momentary_state(Event event, uint16_t arg) { // TODO: momentary strobe here? (for light painting) @@ -1878,6 +1896,7 @@ uint8_t momentary_state(Event event, uint16_t arg) { return EVENT_NOT_HANDLED; } +#endif #ifdef USE_MUGGLE_MODE @@ -2713,7 +2732,11 @@ void loop() { #ifdef USE_STROBE_STATE else if ((state == strobe_state) - || ((state == momentary_state) && (momentary_mode == 1) && (momentary_active)) ) { // also handle momentary strobes + #ifdef USE_MOMENTARY_MODE + // also handle momentary strobes + || ((state == momentary_state) && (momentary_mode == 1) && (momentary_active)) + #endif + ) { uint8_t st = strobe_type; switch(st) { diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h index bdcd893..e12a453 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -27,6 +27,10 @@ // (one channel for warm emitters, one channel for cold) // so enable a special ramping mode which changes tint instead of brightness #define USE_TINT_RAMPING +// how much to increase total brightness at middle tint +// (0 = 100% brightness, 64 = 200% brightness) +//#define TINT_RAMPING_CORRECTION 26 // prototype, 140% +#define TINT_RAMPING_CORRECTION 10 // production model, 115% #ifdef RAMP_LENGTH #undef RAMP_LENGTH diff --git a/spaghetti-monster/anduril/cfg-ff-pl47g2.h b/spaghetti-monster/anduril/cfg-ff-pl47g2.h new file mode 100644 index 0000000..d5dd79d --- /dev/null +++ b/spaghetti-monster/anduril/cfg-ff-pl47g2.h @@ -0,0 +1,60 @@ +// Fireflies PL47 G2 config options for Anduril +#include "hwdef-FF_PL47.h" + +// the button lights up +#define USE_INDICATOR_LED +// the aux LEDs are in the same place as the main LEDs +#ifdef USE_INDICATOR_LED_WHILE_RAMPING +#undef USE_INDICATOR_LED_WHILE_RAMPING +#endif +// enable blinking indicator LED while off? +#define TICK_DURING_STANDBY +#define STANDBY_TICK_SPEED 3 // every 0.128 s +#define USE_FANCIER_BLINKING_INDICATOR + +// If TICK_DURING_STANDBY is enabled... +// off mode: low (1) +// lockout: blinking (3) +#define INDICATOR_LED_DEFAULT_MODE ((3<<2) + 1) + + +#define RAMP_LENGTH 150 + +// driver is a FET + 3x7135, ~400 lm at highest regulated level +// ramp copied from Emisar D4S ramp +#define PWM1_LEVELS 1,1,2,2,3,3,4,4,5,5,6,6,7,8,8,9,10,10,11,12,13,14,15,16,17,18,19,21,22,23,25,26,27,29,31,32,34,36,38,40,42,44,46,49,51,54,56,59,62,65,68,71,74,78,81,85,89,93,97,101,106,110,115,120,125,130,136,141,147,153,160,166,173,180,187,195,202,210,219,227,236,245,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0 +#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3,4,5,7,8,10,11,13,14,16,18,19,21,23,25,27,29,31,34,36,38,41,43,46,48,51,54,57,60,63,66,69,72,76,79,83,87,91,95,99,103,107,112,116,121,126,131,136,141,146,152,158,163,169,175,182,188,195,202,209,216,223,231,239,247,255 +#define MAX_1x7135 83 +#define HALFSPEED_LEVEL 13 +#define QUARTERSPEED_LEVEL 6 + +// thermal regulation parameters +#ifdef MIN_THERM_STEPDOWN +#undef MIN_THERM_STEPDOWN // this should be lower, because 3x7135 instead of 1x7135 +#endif +#define MIN_THERM_STEPDOWN 60 // lowest value it'll step down to + +// ceiling is level 120/150 +#define RAMP_SMOOTH_CEIL 120 + +// 10, 28, 46, 65, [83], 101, 120 +#define RAMP_DISCRETE_FLOOR 10 +#define RAMP_DISCRETE_CEIL 120 +#define RAMP_DISCRETE_STEPS 7 + +// ~25 lm to ~300 lm +#define MUGGLE_FLOOR 30 +#define MUGGLE_CEILING MAX_1x7135 + +// regulate down faster when the FET is active, slower otherwise +#define THERM_FASTER_LEVEL 135 // throttle back faster when high + +// hard drop doesn't seem to be needed on this light +#ifdef THERM_HARD_TURBO_DROP +#undef THERM_HARD_TURBO_DROP +#endif + +// don't do this +#undef BLINK_AT_RAMP_MIDDLE +#undef BLINK_AT_RAMP_CEILING + diff --git a/spaghetti-monster/anduril/cfg-ff-rot66g2.h b/spaghetti-monster/anduril/cfg-ff-rot66g2.h new file mode 100644 index 0000000..4e353a8 --- /dev/null +++ b/spaghetti-monster/anduril/cfg-ff-rot66g2.h @@ -0,0 +1,49 @@ +// Fireflies ROT66 G2 config options for Anduril +#include "cfg-ff-rot66.h" + +// if the "low" mode was disabled, turn it back on +#ifdef INDICATOR_LED_SKIP_LOW +#undef INDICATOR_LED_SKIP_LOW +#endif +// enable blinking indicator LED while off +#define TICK_DURING_STANDBY +#define STANDBY_TICK_SPEED 3 // every 0.128 s +#define USE_FANCIER_BLINKING_INDICATOR + +// lockout: blinking (3), off: low (1) +#ifdef INDICATOR_LED_DEFAULT_MODE +#undef INDICATOR_LED_DEFAULT_MODE +#endif +#define INDICATOR_LED_DEFAULT_MODE ((3<<2) + 1) + +// ramp shape is different than original ROT66 +// 1x7135: 150 lm +// Nx7135: 1200 lm +// FET: 4500 lm +// ../../../bin/level_calc.py 7.0 3 150 7135 1 4 180.16 7135 8 1 1374.48 FET 1 10 4000 +// (plus some manual tweaks) +#undef PWM1_LEVELS +#undef PWM2_LEVELS +#undef PWM3_LEVELS +#define PWM1_LEVELS 1,1,2,3,3,4,4,5,6,7,7,8,9,10,11,12,16,17,18,19,20,21,22,24,26,28,30,32,35,37,40,42,45,48,51,55,58,62,65,69,74,78,83,87,92,98,103,109,115,121,128,134,142,149,157,165,173,182,191,201,211,221,232,243,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0 +#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,11,13,14,16,18,20,22,24,26,28,30,33,35,38,41,43,46,49,52,55,59,62,66,69,73,77,81,85,89,94,98,103,108,113,118,124,129,135,141,147,153,160,166,173,180,188,195,203,211,219,228,237,246,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0 +#define PWM3_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,11,17,23,29,36,42,49,56,63,71,78,86,94,102,111,119,128,137,147,156,166,176,187,197,208,219,231,243,255 + +#undef MAX_1x7135 +#undef MAX_Nx7135 +#define MAX_1x7135 65 // ~150 lm +#define MAX_Nx7135 120 // ~1200 m +#undef HALFSPEED_LEVEL +#undef QUARTERSPEED_LEVEL +#define HALFSPEED_LEVEL 17 +#define QUARTERSPEED_LEVEL 6 + +// higher floor than default, and stop at highest regulated level +#define RAMP_SMOOTH_FLOOR 1 // ~0.3 lm +#define RAMP_SMOOTH_CEIL MAX_Nx7135 // ~1200 lm +// 10, 28, 46, [65], 83, 101, [120] +#define RAMP_DISCRETE_FLOOR 10 +#define RAMP_DISCRETE_CEIL MAX_Nx7135 +#define RAMP_DISCRETE_STEPS 7 + + diff --git a/spaghetti-monster/anduril/cfg-fw3a-nofet.h b/spaghetti-monster/anduril/cfg-fw3a-nofet.h new file mode 100644 index 0000000..a6be10d --- /dev/null +++ b/spaghetti-monster/anduril/cfg-fw3a-nofet.h @@ -0,0 +1,36 @@ +// FW3A with the FET disabled +#include "cfg-fw3a.h" + +// don't use channel 3 (FET) +#undef PWM_CHANNELS +#undef PWM3_PIN +#undef PWM3_LVL +#define PWM_CHANNELS 2 + +// reconfigure the ramp +#undef PWM1_LEVELS +#undef PWM2_LEVELS +#undef PWM3_LEVELS +// copied from Emisar D4, mostly +#define PWM1_LEVELS 1,1,2,2,3,3,4,4,5,6,7,8,9,10,12,13,14,15,17,19,20,22,24,26,29,31,34,36,39,42,45,48,51,55,59,62,66,70,75,79,84,89,93,99,104,110,115,121,127,134,140,147,154,161,168,176,184,192,200,209,217,226,236,245,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 +#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3,4,5,7,8,9,11,12,14,15,17,19,20,22,24,25,27,29,31,33,35,37,39,41,43,45,48,50,52,55,57,59,62,64,67,70,72,75,78,81,84,87,90,93,96,99,102,105,109,112,115,119,122,126,129,133,137,141,144,148,152,156,160,165,169,173,177,182,186,191,195,200,205,209,214,219,224,229,234,239,244,250,255 +#undef MAX_1x7135 +#define MAX_1x7135 65 +#undef HALFSPEED_LEVEL +#define HALFSPEED_LEVEL 14 +#undef QUARTERSPEED_LEVEL +#define QUARTERSPEED_LEVEL 6 + +#undef RAMP_SMOOTH_FLOOR +#undef RAMP_SMOOTH_CEIL +#undef RAMP_DISCRETE_FLOOR +#undef RAMP_DISCRETE_CEIL +#undef RAMP_DISCRETE_STEPS + +#define RAMP_SMOOTH_FLOOR 1 +#define RAMP_SMOOTH_CEIL 150 +// 10, 33, 56, 80, 103, 126, 150 +#define RAMP_DISCRETE_FLOOR 10 +#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 7 + diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c index b8b00de..2a3c5c6 100644 --- a/spaghetti-monster/fsm-adc.c +++ b/spaghetti-monster/fsm-adc.c @@ -276,6 +276,8 @@ static inline void ADC_temperature_handler() { #define OVERHEAT_LOWPASS_STRENGTH (ADC_CYCLES_PER_SECOND*2) // lowpass for 2 seconds #define UNDERHEAT_LOWPASS_STRENGTH (ADC_CYCLES_PER_SECOND*2) // lowpass for 2 seconds + // TODO: left-shift this so the lowpass can get higher resolution + // TODO: increase the sampling rate, to keep the lowpass from lagging uint16_t measurement = adc_values[1]; // latest 10-bit ADC reading // Convert ADC units to Celsius (ish) @@ -322,15 +324,16 @@ static inline void ADC_temperature_handler() { // if it's time to rotate the thermal history, do it history_step ++; #if (THERMAL_UPDATE_SPEED == 4) // new value every 4s - #define THERM_HISTORY_STEP_MAX ((2*ADC_CYCLES_PER_SECOND)-1) + #define THERM_HISTORY_STEP_MAX (4*ADC_CYCLES_PER_SECOND) #elif (THERMAL_UPDATE_SPEED == 2) // new value every 2s - #define THERM_HISTORY_STEP_MAX (ADC_CYCLES_PER_SECOND-1) + #define THERM_HISTORY_STEP_MAX (2*ADC_CYCLES_PER_SECOND) #elif (THERMAL_UPDATE_SPEED == 1) // new value every 1s - #define THERM_HISTORY_STEP_MAX ((ADC_CYCLES_PER_SECOND/2)-1) + #define THERM_HISTORY_STEP_MAX (ADC_CYCLES_PER_SECOND) #elif (THERMAL_UPDATE_SPEED == 0) // new value every 0.5s - #define THERM_HISTORY_STEP_MAX ((ADC_CYCLES_PER_SECOND/4)-1) + #define THERM_HISTORY_STEP_MAX (ADC_CYCLES_PER_SECOND/2) #endif - if (0 == (history_step & THERM_HISTORY_STEP_MAX)) { + if (THERM_HISTORY_STEP_MAX == history_step) { + history_step = 0; // rotate measurements and add a new one for (uint8_t i=0; i<NUM_THERMAL_VALUES_HISTORY-1; i++) { temperature_history[i] = temperature_history[i+1]; diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index ca93350..20500cc 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -81,6 +81,9 @@ void set_level(uint8_t level) { #endif #ifdef USE_TINT_RAMPING + #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 global tint value uint8_t brightness = PWM_GET(pwm1_levels, level); @@ -105,7 +108,7 @@ void set_level(uint8_t level) { // correction is only necessary when PWM is fast if (level > HALFSPEED_LEVEL) { base_PWM = brightness - + ((((uint16_t)brightness) * 26 / 64) * triangle_wave(mytint) / 255); + + ((((uint16_t)brightness) * TINT_RAMPING_CORRECTION / 64) * triangle_wave(mytint) / 255); } cool_PWM = (((uint16_t)mytint * (uint16_t)base_PWM) + 127) / 255; |
