From 4436bf39ed713b7f714b5beb8170e1a4259a835e Mon Sep 17 00:00:00 2001 From: Shane Synan Date: Mon, 12 Jul 2021 16:19:26 -0400 Subject: add configurable #define DEFAULT_AUTOLOCK_TIME Added a new #define DEFAULT_AUTOLOCK_TIME to simplify compiling firmware with the autolock timer enabled by default. If this is not specified, the autolock timer remains disabled by default. This removes the need to modify lockout-mode.h directly. --- spaghetti-monster/anduril/lockout-mode.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/lockout-mode.h b/spaghetti-monster/anduril/lockout-mode.h index 021d34a..1c9c081 100644 --- a/spaghetti-monster/anduril/lockout-mode.h +++ b/spaghetti-monster/anduril/lockout-mode.h @@ -24,7 +24,10 @@ uint8_t lockout_state(Event event, uint16_t arg); #ifdef USE_AUTOLOCK -uint8_t autolock_time = 0; +#ifndef DEFAULT_AUTOLOCK_TIME +#define DEFAULT_AUTOLOCK_TIME 0 // autolock time in minutes, 0 = disabled +#endif +uint8_t autolock_time = DEFAULT_AUTOLOCK_TIME; uint8_t autolock_config_state(Event event, uint16_t arg); #endif -- cgit v1.2.3 From 68ffcea4e3fb2b544501725f5de8fbb304369f64 Mon Sep 17 00:00:00 2001 From: Shane Synan Date: Tue, 13 Jul 2021 19:44:08 -0400 Subject: added #define USE_THERM_AUTOCALIBRATE to opt out Moved factory reset thermal auto-calibration behind a new default-on config #define USE_THERM_AUTOCALIBRATE. Commenting this out or the usual #ifdef/#undef in a cfg-[...].h build file allows for manually calibrating the temperature offset. This may be useful for factory-calibrated temperature sensors or for those who regularly flash custom builds and don't want to recalibrate each time. Determining the correct temperature offset for a given flashlight first requires flashing a build with auto-calibrate disabled, using that to determine the offset, which can then be baked in to future firmware builds. --- spaghetti-monster/anduril/config-default.h | 14 +++++++++++++- spaghetti-monster/anduril/factory-reset.c | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/config-default.h b/spaghetti-monster/anduril/config-default.h index 31fcbf4..a50be5d 100644 --- a/spaghetti-monster/anduril/config-default.h +++ b/spaghetti-monster/anduril/config-default.h @@ -37,7 +37,19 @@ // overheat protection #define USE_THERMAL_REGULATION #define DEFAULT_THERM_CEIL 45 // try not to get hotter than this (in C) - +// Comment out to disable automatic calibration on factory reset +// - If so, be sure to set THERM_CAL_OFFSET to the correct calibration offset +// - Calibration can still be overridden in temperature check mode +// Or uncomment to use the default auto-calibrate on factory reset +// +// To determine THERM_CAL_OFFSET, comment out USE_THERM_AUTOCALIBRATE to +// disable auto-calibration, compile and flash, let flashlight rest at a known +// temperature, then enter temp check mode (do NOT enter calibration mode). +// +// THERM_CAL_OFFSET = known_temperature - temp_check_blinks + THERM_CAL_OFFSET +// +// (include THERM_CAL_OFFSET in sum as it might already be a non-zero number) +#define USE_THERM_AUTOCALIBRATE // Include a simplified UI for non-enthusiasts? #define USE_SIMPLE_UI diff --git a/spaghetti-monster/anduril/factory-reset.c b/spaghetti-monster/anduril/factory-reset.c index c327e65..5377b09 100644 --- a/spaghetti-monster/anduril/factory-reset.c +++ b/spaghetti-monster/anduril/factory-reset.c @@ -43,7 +43,7 @@ void factory_reset() { } // explode, if button pressed long enough if (reset) { - #ifdef USE_THERMAL_REGULATION + #if defined(USE_THERMAL_REGULATION) && defined(USE_THERM_AUTOCALIBRATE) // auto-calibrate temperature... assume current temperature is 21 C thermal_config_save(1, 21); #endif -- cgit v1.2.3 From 5b2fd8aec2a9d6f98c9608123d4df416de29654e Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 12 Aug 2021 22:00:14 -0600 Subject: KR4 thermal regulation no longer needs overrides, because dynamic PWM makes the defaults work better (the overrides were mostly needed as a side effect of having 1024 PWM steps instead of 256) --- spaghetti-monster/anduril/cfg-noctigon-kr4.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4.h b/spaghetti-monster/anduril/cfg-noctigon-kr4.h index f5625c7..7432cdd 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-kr4.h +++ b/spaghetti-monster/anduril/cfg-noctigon-kr4.h @@ -58,8 +58,9 @@ // stop panicking at ~1300 lm #define THERM_FASTER_LEVEL 120 #define MIN_THERM_STEPDOWN 66 // must be > end of dynamic PWM range -#define THERM_NEXT_WARNING_THRESHOLD 16 // accumulate less error before adjusting -#define THERM_RESPONSE_MAGNITUDE 128 // bigger adjustments +// no longer needed, after switching to dynamic PWM +//#define THERM_NEXT_WARNING_THRESHOLD 16 // accumulate less error before adjusting +//#define THERM_RESPONSE_MAGNITUDE 128 // bigger adjustments // slow down party strobe; this driver can't pulse for 1ms or less // (only needed on no-FET build) -- cgit v1.2.3 From 316163b94dabb512b9848cde26fa7991dbe1dd48 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 12 Aug 2021 23:11:48 -0600 Subject: calibrated KR4 jump-start-moon, may be too high on some older hardware --- spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h | 2 +- spaghetti-monster/anduril/cfg-noctigon-kr4.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h b/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h index 871a405..51eef7d 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h +++ b/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h @@ -54,7 +54,7 @@ // jump start a bit higher than base driver #undef JUMP_START_MOON -#define JUMP_START_MOON 25 +#define JUMP_START_MOON 36 // stop panicking at ~1300 lm #undef THERM_FASTER_LEVEL diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4.h b/spaghetti-monster/anduril/cfg-noctigon-kr4.h index 7432cdd..113c1de 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-kr4.h +++ b/spaghetti-monster/anduril/cfg-noctigon-kr4.h @@ -69,7 +69,7 @@ #define THERM_CAL_OFFSET 5 // the power regulator is a bit slow, so push it harder for a quick response from off -#define JUMP_START_MOON 25 +#define JUMP_START_MOON 31 #define BLINK_BRIGHTNESS DEFAULT_LEVEL #define BLINK_ONCE_TIME 12 -- cgit v1.2.3 From ba0e1a3c539276786fc76a14d0abcd2e988ddb8d Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 14 Aug 2021 04:56:25 -0600 Subject: set KR4 default floor higher at Hank's request, and reduced the jump-start-moon power a bit too (he says both are good now, but I don't have hardware to measure it myself) The higher floor is because, when the driver is really hot from being on turbo, going directly to moon causes the LEDs to turn off for a while until the driver cools. The new floor is the lowest level where post-turbo activation works reliably. However, it should turn on even at the level 1/150 when it's not hot. --- spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h | 8 ++++---- spaghetti-monster/anduril/cfg-noctigon-kr4.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h b/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h index 51eef7d..383a0c8 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h +++ b/spaghetti-monster/anduril/cfg-noctigon-kr4-nofet.h @@ -31,10 +31,10 @@ #undef RAMP_DISCRETE_CEIL #undef RAMP_DISCRETE_STEPS -#define RAMP_SMOOTH_FLOOR 1 // level 1 may be unreliable +#define RAMP_SMOOTH_FLOOR 11 // low levels may be unreliable #define RAMP_SMOOTH_CEIL 130 -// 10, 30, [50], 70, 90, 110, 130 (plus [150] on turbo) -#define RAMP_DISCRETE_FLOOR 10 +// 11, 30, [50], 70, 90, 110, 130 (plus [150] on turbo) +#define RAMP_DISCRETE_FLOOR 11 #define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL #define RAMP_DISCRETE_STEPS 7 @@ -54,7 +54,7 @@ // jump start a bit higher than base driver #undef JUMP_START_MOON -#define JUMP_START_MOON 36 +#define JUMP_START_MOON 31 // stop panicking at ~1300 lm #undef THERM_FASTER_LEVEL diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4.h b/spaghetti-monster/anduril/cfg-noctigon-kr4.h index 113c1de..d584445 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-kr4.h +++ b/spaghetti-monster/anduril/cfg-noctigon-kr4.h @@ -43,10 +43,10 @@ #define HALFSPEED_LEVEL 12 #define QUARTERSPEED_LEVEL 4 -#define RAMP_SMOOTH_FLOOR 3 // level 1 may be unreliable +#define RAMP_SMOOTH_FLOOR 11 // low levels may be unreliable #define RAMP_SMOOTH_CEIL 130 -// 10 30 [50] 70 90 110 [130] -#define RAMP_DISCRETE_FLOOR 10 +// 11 30 [50] 70 90 110 [130] +#define RAMP_DISCRETE_FLOOR 11 #define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL #define RAMP_DISCRETE_STEPS 7 @@ -69,7 +69,7 @@ #define THERM_CAL_OFFSET 5 // the power regulator is a bit slow, so push it harder for a quick response from off -#define JUMP_START_MOON 31 +#define JUMP_START_MOON 26 #define BLINK_BRIGHTNESS DEFAULT_LEVEL #define BLINK_ONCE_TIME 12 -- cgit v1.2.3 From efbdb48966a7676d0f3158f89f5fe9205e6c333a Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 16 Aug 2021 04:56:54 -0600 Subject: made dynamic PWM phase-correct; replaced brute-force phase reset to avoid flickering (I didn't see any flickering on my lights, but SammysHP reported it was visible) --- spaghetti-monster/fsm-ramping.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 503f90f..1a08149 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -153,30 +153,33 @@ void set_level(uint8_t level) { #endif // ifdef USE_TINT_RAMPING #ifdef USE_DYN_PWM + uint16_t top = PWM_GET(pwm_tops, level); + #ifdef PWM1_CNT + // wait to ensure compare match won't be missed + // (causes visible flickering when missed, because the counter + // goes all the way to 65535 before returning) + // (see attiny1634 reference manual page 103 for a warning about + // the timing of changing the TOP value (section 12.8.4)) + // to be safe, allow at least 64 cycles to update TOP + while(PWM1_CNT > (top - 64)) {} + #endif // pulse frequency modulation, a.k.a. dynamic PWM - PWM1_TOP = PWM_GET(pwm_tops, level); + PWM1_TOP = top; + + // repeat for other channels if necessary #ifdef PMW2_TOP - PWM2_TOP = PWM_GET(pwm_tops, level); + #ifdef PWM2_CNT + while(PWM2_CNT > (top - 64)) {} + #endif + PWM2_TOP = top; #endif #ifdef PMW3_TOP - PWM3_TOP = PWM_GET(pwm_tops, level); - #endif - - // reset the phase, to avoid random long pulses - // see attiny1634 reference manual page 103 for a warning about - // the timing of changing the TOP value (section 12.8.4) - // (we don't care about being phase-correct, so the brute-force - // approach can be used to reset it here) - #ifdef PWM1_CNT - PWM1_CNT = 0; - #endif - #ifdef PWM2_CNT - PWM2_CNT = 0; - #endif - #ifdef PWM3_CNT - PWM3_CNT = 0; + #ifdef PWM3_CNT + while(PWM3_CNT > (top - 64)) {} + #endif + PWM3_TOP = top; #endif - #endif + #endif // ifdef USE_DYN_PWM } #endif // ifdef OVERRIDE_SET_LEVEL #ifdef USE_DYNAMIC_UNDERCLOCKING -- cgit v1.2.3