From 176144c74eb41b09c508ad338a16217a019165bc Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 14 Oct 2020 21:49:42 -0600 Subject: renamed LED_ENABLE2_* to LED2_ENABLE_* --- spaghetti-monster/fsm-eeprom.c | 8 ++++---- spaghetti-monster/fsm-ramping.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/fsm-eeprom.c b/spaghetti-monster/fsm-eeprom.c index 0de7e05..4c734a2 100644 --- a/spaghetti-monster/fsm-eeprom.c +++ b/spaghetti-monster/fsm-eeprom.c @@ -30,7 +30,7 @@ uint8_t eeprom[EEPROM_BYTES]; #endif uint8_t load_eeprom() { - #ifdef LED_ENABLE_PIN + #if defined(LED_ENABLE_PIN) || defined(LED2_ENABLE_PIN) delay_4ms(2); // wait for power to stabilize #endif @@ -48,7 +48,7 @@ uint8_t load_eeprom() { } void save_eeprom() { - #ifdef LED_ENABLE_PIN + #if defined(LED_ENABLE_PIN) || defined(LED2_ENABLE_PIN) delay_4ms(2); // wait for power to stabilize #endif @@ -70,7 +70,7 @@ uint8_t eeprom_wl[EEPROM_WL_BYTES]; uint8_t * eep_wl_prev_offset; uint8_t load_eeprom_wl() { - #ifdef LED_ENABLE_PIN + #if defined(LED_ENABLE_PIN) || defined(LED2_ENABLE_PIN) delay_4ms(2); // wait for power to stabilize #endif @@ -99,7 +99,7 @@ uint8_t load_eeprom_wl() { } void save_eeprom_wl() { - #ifdef LED_ENABLE_PIN + #if defined(LED_ENABLE_PIN) || defined(LED2_ENABLE_PIN) delay_4ms(2); // wait for power to stabilize #endif diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 6c6d0cb..5ea4a47 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -72,8 +72,8 @@ void set_level(uint8_t level) { #ifdef LED_ENABLE_PIN LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN); #endif - #ifdef LED_ENABLE2_PIN - LED_ENABLE2_PORT &= ~(1 << LED_ENABLE2_PIN); + #ifdef LED2_ENABLE_PIN + LED2_ENABLE_PORT &= ~(1 << LED2_ENABLE_PIN); #endif } else { level --; @@ -82,8 +82,8 @@ void set_level(uint8_t level) { #ifdef LED_ENABLE_PIN LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN); #endif - #ifdef LED_ENABLE2_PIN - LED_ENABLE2_PORT |= (1 << LED_ENABLE2_PIN); + #ifdef LED2_ENABLE_PIN + LED2_ENABLE_PORT |= (1 << LED2_ENABLE_PIN); #endif #ifdef USE_TINT_RAMPING -- cgit v1.2.3 From efce24c0c7117a36cf9a7508a3784b0be0cc6671 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 14 Oct 2020 21:50:38 -0600 Subject: copied KR4 cfg to K9.3 cfg --- spaghetti-monster/anduril/cfg-noctigon-k9.3.h | 65 +++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 spaghetti-monster/anduril/cfg-noctigon-k9.3.h (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h new file mode 100644 index 0000000..17c3c00 --- /dev/null +++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h @@ -0,0 +1,65 @@ +// Noctigon KR4 config options for Anduril +// (and Emisar D4v2.5, which uses KR4 driver plus a button LED) +#define MODEL_NUMBER "0211" +#include "hwdef-Noctigon_KR4.h" +// ATTINY: 1634 + +// this light has three aux LED channels: R, G, B +#define USE_AUX_RGB_LEDS +// the aux LEDs are front-facing, so turn them off while main LEDs are on +//#define USE_AUX_RGB_LEDS_WHILE_ON +// it also has an independent LED in the button (D4v2.5 titanium/brass only) +#define USE_BUTTON_LED +// TODO: the whole "indicator LED" thing needs to be refactored into +// "aux LED(s)" and "button LED(s)" since they work a bit differently +// enabling this option breaks the button LED on D4v2.5 +#ifdef USE_INDICATOR_LED_WHILE_RAMPING +#undef USE_INDICATOR_LED_WHILE_RAMPING +#endif + +// enable blinking aux LEDs +#define TICK_DURING_STANDBY +#define STANDBY_TICK_SPEED 3 // every 0.128 s + + +// brightness w/ SST-20 4000K LEDs: +// 0/1023: 0.35 lm +// 1/1023: 2.56 lm +// max regulated: 1740 lm +// FET: ~3700 lm +// maxreg at 130: level_calc.py cube 2 150 7135 0 2.5 1740 FET 1 10 2565 +// maxreg at 120: level_calc.py cube 2 150 7135 0 2.5 1740 FET 1 10 3190 +#define RAMP_LENGTH 150 +#define PWM1_LEVELS 0,0,1,1,2,2,3,3,4,4,5,6,7,8,9,10,11,13,14,15,17,19,20,22,24,26,28,30,33,35,38,40,43,46,49,52,55,59,62,66,70,74,78,82,86,91,96,100,105,111,116,121,127,133,139,145,151,158,165,172,179,186,193,201,209,217,225,234,243,251,261,270,280,289,299,310,320,331,342,353,364,376,388,400,412,425,438,451,464,478,492,506,521,536,551,566,582,597,614,630,647,664,681,699,717,735,754,772,792,811,831,851,871,892,913,935,956,978,1001,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,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,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,22,51,79,109,138,168,198,229,260,292,324,357,390,423,457,492,527,562,598,634,671,708,746,784,822,861,901,941,982,1023 +#define DEFAULT_LEVEL 46 +#define MAX_1x7135 120 +#define HALFSPEED_LEVEL 10 +#define QUARTERSPEED_LEVEL 2 + +#define RAMP_SMOOTH_FLOOR 3 // level 1 is unreliable +#define RAMP_SMOOTH_CEIL 120 +// 10, 28, [46], 65, 83, 101, [120] +#define RAMP_DISCRETE_FLOOR 10 +#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 7 + +// safe limit ~30% power / ~1400 lm (can sustain 900 lm) +#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR +#define SIMPLE_UI_CEIL 110 +#define SIMPLE_UI_STEPS 5 + +// stop panicking at ~25% power or ~1000 lm +#define THERM_FASTER_LEVEL 100 +#define MIN_THERM_STEPDOWN DEFAULT_LEVEL +#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) +//#define PARTY_STROBE_ONTIME 2 + +#define THERM_CAL_OFFSET 5 + +// can't reset the normal way because power is connected before the button +#define USE_SOFT_FACTORY_RESET -- cgit v1.2.3 From 9464eca79e80d6385b0a1b81a6f10b9d1460e66e Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 14 Oct 2020 22:10:01 -0600 Subject: configured K9.3 cfg (mostly), assigned a model number, fixed typo in hwdef (main LEDs work now; 2nd LEDs not yet) (aux and button LEDs work too, plus switch) --- spaghetti-monster/anduril/MODELS | 1 + spaghetti-monster/anduril/cfg-noctigon-k9.3.h | 33 ++++++++++++++------------- 2 files changed, 18 insertions(+), 16 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/MODELS b/spaghetti-monster/anduril/MODELS index 6697e52..96ec795 100644 --- a/spaghetti-monster/anduril/MODELS +++ b/spaghetti-monster/anduril/MODELS @@ -18,6 +18,7 @@ Model numbers: 0251 noctigon-k1 0252 noctigon-k1-sbt90 0253 noctigon-k1-12v +0261 noctigon-k9.3 0311 fw3a 0312 fw3a-219 0313 fw3a-nofet diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h index 17c3c00..8276ec8 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h +++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h @@ -1,14 +1,13 @@ -// Noctigon KR4 config options for Anduril -// (and Emisar D4v2.5, which uses KR4 driver plus a button LED) -#define MODEL_NUMBER "0211" -#include "hwdef-Noctigon_KR4.h" +// Noctigon K9.3 config options for Anduril +#define MODEL_NUMBER "0261" +#include "hwdef-Noctigon_K9.3.h" // ATTINY: 1634 // this light has three aux LED channels: R, G, B #define USE_AUX_RGB_LEDS // the aux LEDs are front-facing, so turn them off while main LEDs are on //#define USE_AUX_RGB_LEDS_WHILE_ON -// it also has an independent LED in the button (D4v2.5 titanium/brass only) +// it also has an independent LED in the button #define USE_BUTTON_LED // TODO: the whole "indicator LED" thing needs to be refactored into // "aux LED(s)" and "button LED(s)" since they work a bit differently @@ -22,16 +21,18 @@ #define STANDBY_TICK_SPEED 3 // every 0.128 s -// brightness w/ SST-20 4000K LEDs: -// 0/1023: 0.35 lm -// 1/1023: 2.56 lm -// max regulated: 1740 lm -// FET: ~3700 lm -// maxreg at 130: level_calc.py cube 2 150 7135 0 2.5 1740 FET 1 10 2565 +// main LEDs +// max regulated: ~1750 lm +// FET: ~8000 lm +// 2nd LEDs +// max regulated: ~1500 lm // maxreg at 120: level_calc.py cube 2 150 7135 0 2.5 1740 FET 1 10 3190 #define RAMP_LENGTH 150 +// main LEDs #define PWM1_LEVELS 0,0,1,1,2,2,3,3,4,4,5,6,7,8,9,10,11,13,14,15,17,19,20,22,24,26,28,30,33,35,38,40,43,46,49,52,55,59,62,66,70,74,78,82,86,91,96,100,105,111,116,121,127,133,139,145,151,158,165,172,179,186,193,201,209,217,225,234,243,251,261,270,280,289,299,310,320,331,342,353,364,376,388,400,412,425,438,451,464,478,492,506,521,536,551,566,582,597,614,630,647,664,681,699,717,735,754,772,792,811,831,851,871,892,913,935,956,978,1001,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,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,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,22,51,79,109,138,168,198,229,260,292,324,357,390,423,457,492,527,562,598,634,671,708,746,784,822,861,901,941,982,1023 +// 2nd LEDs +#define PWM3_LEVELS 0,0,1,1,2,2,3,3,4,4,5,5,6,7,8,9,10,11,12,13,15,16,17,18,20,21,23,24,26,27,29,31,33,35,37,39,41,43,45,48,50,53,55,58,61,63,66,69,72,75,79,82,85,89,92,96,100,104,108,112,116,120,125,129,134,138,143,148,153,158,163,169,174,180,185,191,197,203,209,215,222,228,235,242,248,255,263,270,277,285,292,300,308,316,324,333,341,350,359,368,377,386,395,405,414,424,434,444,454,465,475,486,497,508,519,531,542,554,566,578,590,603,615,628,641,654,667,680,694,708,722,736,750,765,779,794,809,825,840,856,872,888,904,920,937,954,971,988,1005,1023 #define DEFAULT_LEVEL 46 #define MAX_1x7135 120 #define HALFSPEED_LEVEL 10 @@ -44,16 +45,16 @@ #define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL #define RAMP_DISCRETE_STEPS 7 -// safe limit ~30% power / ~1400 lm (can sustain 900 lm) +// safe limit highest regulated power (no FET or turbo) #define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR -#define SIMPLE_UI_CEIL 110 +#define SIMPLE_UI_CEIL RAMP_DISCRETE_CEIL #define SIMPLE_UI_STEPS 5 // stop panicking at ~25% power or ~1000 lm #define THERM_FASTER_LEVEL 100 #define MIN_THERM_STEPDOWN DEFAULT_LEVEL -#define THERM_NEXT_WARNING_THRESHOLD 16 // accumulate less error before adjusting -#define THERM_RESPONSE_MAGNITUDE 128 // bigger adjustments +//#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) @@ -61,5 +62,5 @@ #define THERM_CAL_OFFSET 5 -// can't reset the normal way because power is connected before the button +// for consistency with KR4 (not otherwise necessary though) #define USE_SOFT_FACTORY_RESET -- cgit v1.2.3 From db1c7ef28405c123faaaadb25c8c9b2edeea0d43 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 14 Oct 2020 23:17:27 -0600 Subject: got K9.3 2nd LEDs working (and modified FSM to allow this sort of thing) added a way to include per-model code overrides added an override mechanism for logic inside set_level() wrote K9.3's set_level() function added TINT_RAMP_TOGGLE_ONLY mode for tint ramping --- spaghetti-monster/anduril/anduril.c | 6 ++++- spaghetti-monster/anduril/cfg-noctigon-k9.3.c | 36 +++++++++++++++++++++++++++ spaghetti-monster/anduril/cfg-noctigon-k9.3.h | 11 ++++++++ spaghetti-monster/anduril/tint-ramping.c | 28 +++++++++++++++++++++ spaghetti-monster/fsm-ramping.c | 5 ++++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 spaghetti-monster/anduril/cfg-noctigon-k9.3.c (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index f632229..549fe46 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -85,12 +85,16 @@ // (include this one last) #include "load-save-config-fsm.h" - /********* bring in FSM / SpaghettiMonster *********/ #define USE_IDLE_MODE // reduce power use while awake and no tasks are pending #include "spaghetti-monster.h" +/********* does this build target have special code to include? *********/ +#ifdef OVERRIDES_FILE +#include incfile(OVERRIDES_FILE) +#endif + /********* Include all the regular app headers *********/ diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.c b/spaghetti-monster/anduril/cfg-noctigon-k9.3.c new file mode 100644 index 0000000..5e3350a --- /dev/null +++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.c @@ -0,0 +1,36 @@ +#ifdef USE_SET_LEVEL_GRADUALLY +//#undef USE_SET_LEVEL_GRADUALLY +#endif + +inline void set_level_override(uint8_t level) { + if (level == 0) { + PWM1_LVL = 0; + PWM2_LVL = 0; + PWM3_LVL = 0; + // disable the power channel + LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN); + LED2_ENABLE_PORT &= ~(1 << LED2_ENABLE_PIN); + } else { + level --; + + if (! tint) { // main LEDs + // enable this power channel + LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN); + // disable other power channel + LED2_ENABLE_PORT &= ~(1 << LED2_ENABLE_PIN); + // set levels + PWM1_LVL = PWM_GET(pwm1_levels, level); + PWM2_LVL = (uint8_t)(PWM_GET(pwm2_levels, level) >> 2); + PWM3_LVL = 0; + } else { // 2nd LEDs + // disable other power channel + LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN); + // enable this power channel + LED2_ENABLE_PORT |= (1 << LED2_ENABLE_PIN); + // set levels + PWM1_LVL = 0; + PWM2_LVL = 0; + PWM3_LVL = PWM_GET(pwm3_levels, level); + } + } +} diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h index 8276ec8..123dabe 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h +++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h @@ -2,6 +2,11 @@ #define MODEL_NUMBER "0261" #include "hwdef-Noctigon_K9.3.h" // ATTINY: 1634 +// this model requires some special code +#define OVERRIDES_FILE cfg-noctigon-k9.3.c +#define OVERRIDE_SET_LEVEL +inline void set_level_override(uint8_t level); + // this light has three aux LED channels: R, G, B #define USE_AUX_RGB_LEDS @@ -20,6 +25,10 @@ #define TICK_DURING_STANDBY #define STANDBY_TICK_SPEED 3 // every 0.128 s +// has two channels of independent LEDs +#define USE_TINT_RAMPING +// ... but it doesn't make sense to ramp between; only toggle +#define TINT_RAMP_TOGGLE_ONLY // main LEDs // max regulated: ~1750 lm @@ -35,6 +44,7 @@ #define PWM3_LEVELS 0,0,1,1,2,2,3,3,4,4,5,5,6,7,8,9,10,11,12,13,15,16,17,18,20,21,23,24,26,27,29,31,33,35,37,39,41,43,45,48,50,53,55,58,61,63,66,69,72,75,79,82,85,89,92,96,100,104,108,112,116,120,125,129,134,138,143,148,153,158,163,169,174,180,185,191,197,203,209,215,222,228,235,242,248,255,263,270,277,285,292,300,308,316,324,333,341,350,359,368,377,386,395,405,414,424,434,444,454,465,475,486,497,508,519,531,542,554,566,578,590,603,615,628,641,654,667,680,694,708,722,736,750,765,779,794,809,825,840,856,872,888,904,920,937,954,971,988,1005,1023 #define DEFAULT_LEVEL 46 #define MAX_1x7135 120 +#define MAX_Nx7135 MAX_1x7135 #define HALFSPEED_LEVEL 10 #define QUARTERSPEED_LEVEL 2 @@ -64,3 +74,4 @@ // for consistency with KR4 (not otherwise necessary though) #define USE_SOFT_FACTORY_RESET + diff --git a/spaghetti-monster/anduril/tint-ramping.c b/spaghetti-monster/anduril/tint-ramping.c index 0196bc7..0b077ef 100644 --- a/spaghetti-monster/anduril/tint-ramping.c +++ b/spaghetti-monster/anduril/tint-ramping.c @@ -22,6 +22,32 @@ #include "tint-ramping.h" +#ifdef TINT_RAMP_TOGGLE_ONLY + +uint8_t tint_ramping_state(Event event, uint16_t arg) { + // click, click, hold: change the tint + if (event == EV_click3_hold) { + // toggle once on first frame; ignore other frames + if (! arg) { + tint = !tint; + set_level(actual_level); + blink_once(); + } + return EVENT_HANDLED; + } + + // click, click, hold, release: save config + else if (event == EV_click3_hold_release) { + // remember tint after battery change + save_config(); + return EVENT_HANDLED; + } + + return EVENT_NOT_HANDLED; +} + +#else // no TINT_RAMP_TOGGLE_ONLY + uint8_t tint_ramping_state(Event event, uint16_t arg) { static int8_t tint_ramp_direction = 1; static uint8_t prev_tint = 0; @@ -82,6 +108,8 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { return EVENT_NOT_HANDLED; } +#endif // ifdef TINT_RAMP_TOGGLE_ONLY + #endif diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 5ea4a47..16bffe3 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -54,6 +54,10 @@ void set_level(uint8_t level) { #endif #endif + #ifdef OVERRIDE_SET_LEVEL + set_level_override(level); + #else + //TCCR0A = PHASE; if (level == 0) { #if PWM_CHANNELS >= 1 @@ -139,6 +143,7 @@ void set_level(uint8_t level) { #endif // ifdef USE_TINT_RAMPING } + #endif // ifdef OVERRIDE_SET_LEVEL #ifdef USE_DYNAMIC_UNDERCLOCKING auto_clock_speed(); #endif -- cgit v1.2.3 From 2789e3893de182fe1bf66aa9da1ba5f93d78098b Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 15 Oct 2020 17:07:09 -0600 Subject: made gradual_tick() work on K9.3 (via override), fixed strobe config, made blink_once() more configurable (and more reliable on K9.3) --- spaghetti-monster/anduril/cfg-noctigon-k9.3.c | 79 +++++++++++++++++++++++++-- spaghetti-monster/anduril/cfg-noctigon-k9.3.h | 8 ++- spaghetti-monster/anduril/misc.c | 5 +- spaghetti-monster/fsm-ramping.c | 4 +- 4 files changed, 87 insertions(+), 9 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.c b/spaghetti-monster/anduril/cfg-noctigon-k9.3.c index 5e3350a..5cb027a 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.c +++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.c @@ -1,13 +1,28 @@ -#ifdef USE_SET_LEVEL_GRADUALLY +/* + * K9.3 has unusual power channels, so it must override some of FSM's code. + * There are two sets of LEDs: + * 1. Main LEDs: (9 x white LEDs) + * PWM1 (10-bit, linear) + * PWM2 (8-bit, FET, only used on some K9.3 models) + * 2. 2nd LEDs: (3 x white or color LEDs) + * PWM3 (10-bit, linear) + * + * The two sets are not used at the same time... just one or the other, + * depending on the "tint" variable. (0 = main LEDs, other value = 2nd LEDs) + */ +// if the gradual adjustment mechanism doesn't work, disable it here: +//#ifdef USE_SET_LEVEL_GRADUALLY //#undef USE_SET_LEVEL_GRADUALLY -#endif +//#endif +// this is inserted into fsm-ramping.c :: set_level() +// (it overrides part of the function, but not all of it) inline void set_level_override(uint8_t level) { - if (level == 0) { + if (level == 0) { // off PWM1_LVL = 0; PWM2_LVL = 0; PWM3_LVL = 0; - // disable the power channel + // disable both power channels LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN); LED2_ENABLE_PORT &= ~(1 << LED2_ENABLE_PIN); } else { @@ -20,7 +35,9 @@ inline void set_level_override(uint8_t level) { LED2_ENABLE_PORT &= ~(1 << LED2_ENABLE_PIN); // set levels PWM1_LVL = PWM_GET(pwm1_levels, level); - PWM2_LVL = (uint8_t)(PWM_GET(pwm2_levels, level) >> 2); + #ifndef K93_NO_FET + PWM2_LVL = (uint8_t)(PWM_GET(pwm2_levels, level) >> 2); // 8 bits + #endif PWM3_LVL = 0; } else { // 2nd LEDs // disable other power channel @@ -34,3 +51,55 @@ inline void set_level_override(uint8_t level) { } } } + +// override fsm-ramping.c :: gradual_tick() +// (because the power handling on this light is weird) +// call this every frame or every few frames to change brightness very smoothly +void gradual_tick() { + // go by only one ramp level at a time instead of directly to the target + uint8_t gt = gradual_target; + if (gt < actual_level) gt = actual_level - 1; + else if (gt > actual_level) gt = actual_level + 1; + + gt --; // convert 1-based number to 0-based + + PWM_DATATYPE target; + + if (! tint) { // main LED channel + target = PWM_GET(pwm1_levels, gt); + if ((gt < actual_level) // special case for FET-only turbo + && (PWM1_LVL == 0) // (bypass adjustment period for first step) + && (target == PWM_TOP)) PWM1_LVL = PWM_TOP; + else if (PWM1_LVL < target) PWM1_LVL ++; + else if (PWM1_LVL > target) PWM1_LVL --; + + #ifndef K93_NO_FET // skip this on E21A model + target = PWM_GET(pwm2_levels, gt) >> 2; // 8 bits, not 10 + if (PWM2_LVL < target) PWM2_LVL ++; + else if (PWM2_LVL > target) PWM2_LVL --; + #endif + + // did we go far enough to hit the next defined ramp level? + // if so, update the main ramp level tracking var + if ((PWM1_LVL == PWM_GET(pwm1_levels, gt)) + #ifndef K93_NO_FET + && (PWM2_LVL == (PWM_GET(pwm2_levels, gt) >> 2)) + #endif + ) + { actual_level = gt + 1; } + } else { // 2nd LED channel + target = PWM_GET(pwm3_levels, gt); + if (PWM3_LVL < target) PWM3_LVL ++; + else if (PWM3_LVL > target) PWM3_LVL --; + + // did we go far enough to hit the next defined ramp level? + // if so, update the main ramp level tracking var + if ( PWM3_LVL == PWM_GET(pwm3_levels, gt) ) + { actual_level = gt + 1; } + } + + #ifdef USE_DYNAMIC_UNDERCLOCKING + auto_clock_speed(); + #endif +} + diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h index 123dabe..e4524ec 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h +++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h @@ -5,6 +5,7 @@ // this model requires some special code #define OVERRIDES_FILE cfg-noctigon-k9.3.c #define OVERRIDE_SET_LEVEL +#define OVERRIDE_GRADUAL_TICK inline void set_level_override(uint8_t level); @@ -66,9 +67,12 @@ inline void set_level_override(uint8_t level); //#define THERM_NEXT_WARNING_THRESHOLD 16 // accumulate less error before adjusting //#define THERM_RESPONSE_MAGNITUDE 128 // bigger adjustments +// use the brightest setting for strobe +#define STROBE_BRIGHTNESS MAX_LEVEL // slow down party strobe; this driver can't pulse for 1ms or less -// (only needed on no-FET build) -//#define PARTY_STROBE_ONTIME 2 +#define PARTY_STROBE_ONTIME 2 + +#define BLINK_ONCE_TIME 12 // longer blink, since main LEDs are slow #define THERM_CAL_OFFSET 5 diff --git a/spaghetti-monster/anduril/misc.c b/spaghetti-monster/anduril/misc.c index 63b8f48..523bbf0 100644 --- a/spaghetti-monster/anduril/misc.c +++ b/spaghetti-monster/anduril/misc.c @@ -38,13 +38,16 @@ void blink_confirm(uint8_t num) { // make a short, visible pulse // (either brighter or darker, depending on current brightness) +#ifndef BLINK_ONCE_TIME +#define BLINK_ONCE_TIME 10 +#endif void blink_once() { uint8_t brightness = actual_level; uint8_t bump = brightness + (MAX_LEVEL/6); if (bump > MAX_LEVEL) bump = 0; set_level(bump); - delay_4ms(10/4); + delay_4ms(BLINK_ONCE_TIME/4); set_level(brightness); } diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 16bffe3..f092204 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -154,6 +154,7 @@ inline void set_level_gradually(uint8_t lvl) { gradual_target = lvl; } +#ifndef OVERRIDE_GRADUAL_TICK // call this every frame or every few frames to change brightness very smoothly void gradual_tick() { // go by only one ramp level at a time instead of directly to the target @@ -209,7 +210,8 @@ void gradual_tick() { auto_clock_speed(); #endif } -#endif +#endif // ifdef OVERRIDE_GRADUAL_TICK +#endif // ifdef USE_SET_LEVEL_GRADUALLY #endif // ifdef USE_RAMPING #endif -- cgit v1.2.3 From 5f2d12b7b225bdf291cea76cf1ba5fc8796150b6 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 16 Oct 2020 22:10:35 -0600 Subject: start tint at 0 instead of 128 on lights with toggle instead of ramp --- spaghetti-monster/fsm-ramping.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/fsm-ramping.h b/spaghetti-monster/fsm-ramping.h index f177db9..8fd89c7 100644 --- a/spaghetti-monster/fsm-ramping.h +++ b/spaghetti-monster/fsm-ramping.h @@ -27,7 +27,11 @@ uint8_t actual_level = 0; #ifdef USE_TINT_RAMPING +#ifdef TINT_RAMP_TOGGLE_ONLY +uint8_t tint = 0; +#else uint8_t tint = 128; +#endif #define USE_TRIANGLE_WAVE #endif -- cgit v1.2.3 From f8c6e2edd5fbfc9e54d6072e1ab53dd887968ad5 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 16 Oct 2020 22:11:25 -0600 Subject: added K9.3-noFET build target (for models with E21A as main LEDs) --- .../anduril/cfg-noctigon-k9.3-nofet.h | 54 ++++++++++++++++++++++ spaghetti-monster/anduril/cfg-noctigon-k9.3.h | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 spaghetti-monster/anduril/cfg-noctigon-k9.3-nofet.h (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3-nofet.h b/spaghetti-monster/anduril/cfg-noctigon-k9.3-nofet.h new file mode 100644 index 0000000..e91ebc4 --- /dev/null +++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3-nofet.h @@ -0,0 +1,54 @@ +// Noctigon K9.3 (noFET) config options for Anduril +#include "cfg-noctigon-k9.3.h" +#undef MODEL_NUMBER +#define MODEL_NUMBER "0262" +// ATTINY: 1634 + +// don't use the highest power channel +#define K93_NO_FET + +// main LEDs +#undef PWM1_LEVELS +#undef PWM2_LEVELS +#define PWM1_LEVELS 0,0,1,1,2,2,3,3,4,4,5,5,6,7,8,9,10,11,12,13,15,16,17,18,20,21,23,24,26,27,29,31,33,35,37,39,41,43,45,48,50,53,55,58,61,63,66,69,72,75,79,82,85,89,92,96,100,104,108,112,116,120,125,129,134,138,143,148,153,158,163,169,174,180,185,191,197,203,209,215,222,228,235,242,248,255,263,270,277,285,292,300,308,316,324,333,341,350,359,368,377,386,395,405,414,424,434,444,454,465,475,486,497,508,519,531,542,554,566,578,590,603,615,628,641,654,667,680,694,708,722,736,750,765,779,794,809,825,840,856,872,888,904,920,937,954,971,988,1005,1023 +// FET channel: unused, all zeroes +#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,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 +// 2nd LEDs +#undef PWM3_LEVELS +#define PWM3_LEVELS 0,0,1,1,2,2,3,3,4,4,5,5,6,7,8,9,10,11,12,13,15,16,17,18,20,21,23,24,26,27,29,31,33,35,37,39,41,43,45,48,50,53,55,58,61,63,66,69,72,75,79,82,85,89,92,96,100,104,108,112,116,120,125,129,134,138,143,148,153,158,163,169,174,180,185,191,197,203,209,215,222,228,235,242,248,255,263,270,277,285,292,300,308,316,324,333,341,350,359,368,377,386,395,405,414,424,434,444,454,465,475,486,497,508,519,531,542,554,566,578,590,603,615,628,641,654,667,680,694,708,722,736,750,765,779,794,809,825,840,856,872,888,904,920,937,954,971,988,1005,1023 +#undef DEFAULT_LEVEL +#define DEFAULT_LEVEL 50 +#undef MAX_1x7135 +#undef MAX_Nx7135 +#define MAX_1x7135 150 +#define MAX_Nx7135 MAX_1x7135 + +#undef RAMP_SMOOTH_FLOOR +#undef RAMP_SMOOTH_CEIL +#undef RAMP_DISCRETE_FLOOR +#undef RAMP_DISCRETE_CEIL +#undef RAMP_DISCRETE_STEPS + +#define RAMP_SMOOTH_FLOOR 3 // level 1 is unreliable(?) +#define RAMP_SMOOTH_CEIL 130 +// 10, 30, [50], 70, 90, 110, 130 (plus [150] on turbo) +#define RAMP_DISCRETE_FLOOR 10 +#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 7 + +// safe limit same as full UI +#undef SIMPLE_UI_FLOOR +#undef SIMPLE_UI_CEIL +#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR +#define SIMPLE_UI_CEIL RAMP_DISCRETE_CEIL + + +// make candle mode wobble more +#define CANDLE_AMPLITUDE 32 + +// stop panicking at ~90% power or ~1600 lm +#undef THERM_FASTER_LEVEL +#define THERM_FASTER_LEVEL 143 +#undef MIN_THERM_STEPDOWN +#define MIN_THERM_STEPDOWN DEFAULT_LEVEL + diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h index e4524ec..76ddb05 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h +++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h @@ -49,7 +49,7 @@ inline void set_level_override(uint8_t level); #define HALFSPEED_LEVEL 10 #define QUARTERSPEED_LEVEL 2 -#define RAMP_SMOOTH_FLOOR 3 // level 1 is unreliable +#define RAMP_SMOOTH_FLOOR 3 // level 1 is unreliable (?) #define RAMP_SMOOTH_CEIL 120 // 10, 28, [46], 65, 83, 101, [120] #define RAMP_DISCRETE_FLOOR 10 -- cgit v1.2.3 From fa6155c367f14ebe229ce8c6248429a45b3605d2 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 22 Oct 2020 02:56:00 -0600 Subject: enabled memory timer and resetting tint after timeout on K9.3 (unsure if I'll keep it this way though, or if the old way was better) --- spaghetti-monster/anduril/cfg-noctigon-k9.3.h | 4 ++++ spaghetti-monster/anduril/off-mode.c | 3 +++ spaghetti-monster/anduril/ramp-mode.h | 10 ++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h index 76ddb05..fd162fe 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h +++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h @@ -49,6 +49,10 @@ inline void set_level_override(uint8_t level); #define HALFSPEED_LEVEL 10 #define QUARTERSPEED_LEVEL 2 +#define USE_MANUAL_MEMORY_TIMER_FOR_TINT +#define DEFAULT_MANUAL_MEMORY DEFAULT_LEVEL +#define DEFAULT_MANUAL_MEMORY_TIMER 10 + #define RAMP_SMOOTH_FLOOR 3 // level 1 is unreliable (?) #define RAMP_SMOOTH_CEIL 120 // 10, 28, [46], 65, 83, 101, [120] diff --git a/spaghetti-monster/anduril/off-mode.c b/spaghetti-monster/anduril/off-mode.c index 5ebaa1d..34d9e6d 100644 --- a/spaghetti-monster/anduril/off-mode.c +++ b/spaghetti-monster/anduril/off-mode.c @@ -133,6 +133,9 @@ uint8_t off_state(Event event, uint16_t arg) { && (off_time >= (manual_memory_timer * SLEEP_TICKS_PER_MINUTE)) #endif ) { + #if defined(USE_MANUAL_MEMORY_TIMER_FOR_TINT) && defined(USE_TINT_RAMPING) && defined(TINT_RAMP_TOGGLE_ONLY) + tint = 0; + #endif set_level(nearest_level(manual_memory)); } else #endif diff --git a/spaghetti-monster/anduril/ramp-mode.h b/spaghetti-monster/anduril/ramp-mode.h index b772407..ed806bd 100644 --- a/spaghetti-monster/anduril/ramp-mode.h +++ b/spaghetti-monster/anduril/ramp-mode.h @@ -148,9 +148,15 @@ void set_level_and_therm_target(uint8_t level); // brightness control uint8_t memorized_level = DEFAULT_LEVEL; #ifdef USE_MANUAL_MEMORY -uint8_t manual_memory = 0; +#ifndef DEFAULT_MANUAL_MEMORY +#define DEFAULT_MANUAL_MEMORY 0 +#endif +uint8_t manual_memory = DEFAULT_MANUAL_MEMORY; #ifdef USE_MANUAL_MEMORY_TIMER -uint8_t manual_memory_timer = 0; +#ifndef DEFAULT_MANUAL_MEMORY_TIMER +#define DEFAULT_MANUAL_MEMORY_TIMER 0 +#endif +uint8_t manual_memory_timer = DEFAULT_MANUAL_MEMORY_TIMER; #endif #endif #ifdef USE_SIMPLE_UI -- cgit v1.2.3 From 9f693768d56541f4be2ce5bc211e34be14e6ea79 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 13 Dec 2020 23:55:09 -0700 Subject: noctigon k9.3: default to aux RGB rainbow mode, and automatic memory --- spaghetti-monster/anduril/cfg-noctigon-k9.3.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h index fd162fe..4d3d3d9 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h +++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h @@ -11,6 +11,7 @@ inline void set_level_override(uint8_t level); // this light has three aux LED channels: R, G, B #define USE_AUX_RGB_LEDS +#define RGB_LED_OFF_DEFAULT 0x18 // low, rainbow // the aux LEDs are front-facing, so turn them off while main LEDs are on //#define USE_AUX_RGB_LEDS_WHILE_ON // it also has an independent LED in the button @@ -50,8 +51,8 @@ inline void set_level_override(uint8_t level); #define QUARTERSPEED_LEVEL 2 #define USE_MANUAL_MEMORY_TIMER_FOR_TINT -#define DEFAULT_MANUAL_MEMORY DEFAULT_LEVEL -#define DEFAULT_MANUAL_MEMORY_TIMER 10 +//#define DEFAULT_MANUAL_MEMORY DEFAULT_LEVEL +//#define DEFAULT_MANUAL_MEMORY_TIMER 10 #define RAMP_SMOOTH_FLOOR 3 // level 1 is unreliable (?) #define RAMP_SMOOTH_CEIL 120 -- cgit v1.2.3 From 0132c47f0ca6725593f9b43a4984df29f7a90cc4 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 25 Jan 2021 00:02:10 -0700 Subject: bug pseudo-fix: K9.3 lockout mode failed in blinking single-color mode because of what appears to be compiler jank or a race condition or some other highly unusual issue (fixed by eating up extra clock cycles in the affected code path) --- spaghetti-monster/anduril/aux-leds.c | 9 +++++++++ spaghetti-monster/anduril/cfg-noctigon-k9.3.h | 3 +++ 2 files changed, 12 insertions(+) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/aux-leds.c b/spaghetti-monster/anduril/aux-leds.c index c819bd7..73d163e 100644 --- a/spaghetti-monster/anduril/aux-leds.c +++ b/spaghetti-monster/anduril/aux-leds.c @@ -99,6 +99,15 @@ void rgb_led_update(uint8_t mode, uint8_t arg) { const uint8_t *colors = rgb_led_colors; uint8_t actual_color = 0; if (color < 7) { // normal color + #ifdef USE_K93_LOCKOUT_KLUDGE + // FIXME: jank alert: this is dumb + // this clause does nothing; it just uses up clock cycles + // because without it, the K9.3's lockout mode fails and returns + // to "off" after ~5 to 15 seconds when configured for a blinking + // single color, even though there is no code path from lockout to + // "off", and it doesn't act like a reboot either (no boot-up blink) + rainbow = (rainbow + 1 + pseudo_rand() % 5) % 6; + #endif actual_color = pgm_read_byte(colors + color); } else if (color == 7) { // disco diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h index 4d3d3d9..e61ea13 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h +++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h @@ -84,3 +84,6 @@ inline void set_level_override(uint8_t level); // for consistency with KR4 (not otherwise necessary though) #define USE_SOFT_FACTORY_RESET + +// work around bizarre bug: lockout mode fails when set to solid color blinking +#define USE_K93_LOCKOUT_KLUDGE -- cgit v1.2.3 From e3886bb569ccb89fb1198bab08c5f7d5fc0e2583 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 25 Jan 2021 00:03:02 -0700 Subject: removed redundant function call, added missing comment --- spaghetti-monster/anduril/cfg-noctigon-k9.3.c | 3 --- spaghetti-monster/fsm-ramping.c | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.c b/spaghetti-monster/anduril/cfg-noctigon-k9.3.c index 5cb027a..5ce5c5a 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.c +++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.c @@ -98,8 +98,5 @@ void gradual_tick() { { actual_level = gt + 1; } } - #ifdef USE_DYNAMIC_UNDERCLOCKING - auto_clock_speed(); - #endif } diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 0768f8d..d6a14ef 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -135,7 +135,7 @@ void set_level(uint8_t level) { PWM1_LVL = warm_PWM; PWM2_LVL = cool_PWM; - #else + #else // ifdef USE_TINT_RAMPING #if PWM_CHANNELS >= 1 PWM1_LVL = PWM_GET(pwm1_levels, level); -- cgit v1.2.3 From b02057175d97ca45723f64492049b89873cf0709 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 25 Jan 2021 01:09:35 -0700 Subject: updated MODELS file with missing K9.3-nofet build target --- spaghetti-monster/anduril/MODELS | 1 + 1 file changed, 1 insertion(+) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/MODELS b/spaghetti-monster/anduril/MODELS index 173620a..52fa200 100644 --- a/spaghetti-monster/anduril/MODELS +++ b/spaghetti-monster/anduril/MODELS @@ -19,6 +19,7 @@ Model numbers: 0252 noctigon-k1-sbt90 0253 noctigon-k1-12v 0261 noctigon-k9.3 +0262 noctigon-k9.3-nofet 0311 fw3a 0312 fw3a-219 0313 fw3a-nofet -- cgit v1.2.3