From d7c7ff8e921456b1f1a27ad16f6d3466157c91c4 Mon Sep 17 00:00:00 2001 From: SiteRelEnby Date: Mon, 6 Nov 2023 14:50:06 -0600 Subject: Add a feature to make RGB voltage configurable Adds two entries to the battery voltage settings menu, the first isathreshold for switching aux to high, and the second sets a minimum level for it to be displayed, also effectively allowing the feature to be entirely disabled if not wanted. --- docs/anduril-manual.md | 13 ++++++++++++- fsm/ramping.c | 9 ++++++++- hw/hank/emisar-d1v2/7135-fet/anduril.h | 1 + hw/hank/emisar-d1v2/linear-fet/anduril.h | 1 + hw/hank/emisar-d1v2/nofet/anduril.h | 1 + hw/hank/emisar-d4k-3ch/anduril.h | 1 + hw/hank/noctigon-k1/anduril.h | 1 + hw/hank/noctigon-k1/boost/anduril.h | 1 + hw/hank/noctigon-k1/sbt90/anduril.h | 1 + hw/wurkkos/fc13/anduril.h | 1 + hw/wurkkos/ts11/anduril.h | 1 + ui/anduril/anduril.c | 10 +++++++--- ui/anduril/battcheck-mode.c | 20 +++++++++++--------- ui/anduril/battcheck-mode.h | 15 +++++++++++++++ ui/anduril/load-save-config-fsm.h | 4 ++++ ui/anduril/load-save-config.h | 15 +++++++++++++++ 16 files changed, 81 insertions(+), 14 deletions(-) diff --git a/docs/anduril-manual.md b/docs/anduril-manual.md index 68c577c..9ede671 100644 --- a/docs/anduril-manual.md +++ b/docs/anduril-manual.md @@ -453,12 +453,23 @@ The voltage config menu has these settings: `12C`: +0.25V `13C`: +0.30V - 2. Post-off voltage display timeout. (only on lights with RGB aux) + 2. Post-off voltage display timeout. (only on lights with RGB aux) This setting determines how many seconds the RGB aux LEDs display the voltage color after the torch goes to sleep. Click once per desired second, or zero times to turn this function off. + 3. RGB voltage while on high threshold. On lights where the battery + voltage is displayed using RGB aux while the light is on, sets + the ramp level at which the aux will switch to high brightness. + If set to 151, this effectively forces the voltage to only ever + be displayed using low brightness, or if set to 0, to only ever + use high brightness. + + 4. RGB voltage while on minimum level. Below this level, voltage will + not be displayed using the RGB aux at all. Setting this to 151+ + effectively disables the entire feature. + ### Temperature check: Blinks out the current temperature in degrees C. This number should diff --git a/fsm/ramping.c b/fsm/ramping.c index adc8acb..b3b3b23 100644 --- a/fsm/ramping.c +++ b/fsm/ramping.c @@ -41,9 +41,16 @@ inline void set_level_aux_leds(uint8_t level) { #include "anduril/aux-leds.h" // for rgb_led_voltage_readout() inline void set_level_aux_rgb_leds(uint8_t level) { if (! go_to_standby) { + #ifdef USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS + if ((level > 0) && (actual_level > cfg.use_aux_rgb_leds_while_on_min_level)){ + rgb_led_voltage_readout(level > cfg.use_aux_rgb_leds_while_on); + } + #else if (level > 0) { rgb_led_voltage_readout(level > USE_AUX_RGB_LEDS_WHILE_ON); - } else { + } + #endif + else { rgb_led_set(0); } // some drivers can be wired with RGB or single color to button diff --git a/hw/hank/emisar-d1v2/7135-fet/anduril.h b/hw/hank/emisar-d1v2/7135-fet/anduril.h index 968162a..8682585 100644 --- a/hw/hank/emisar-d1v2/7135-fet/anduril.h +++ b/hw/hank/emisar-d1v2/7135-fet/anduril.h @@ -15,6 +15,7 @@ // so it's unlikely that anyone needs this, but it doesn't hurt anything) #define USE_AUX_RGB_LEDS #define USE_AUX_RGB_LEDS_WHILE_ON 25 +#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING // safe limit ~50% power diff --git a/hw/hank/emisar-d1v2/linear-fet/anduril.h b/hw/hank/emisar-d1v2/linear-fet/anduril.h index 1d09001..a15fa5e 100644 --- a/hw/hank/emisar-d1v2/linear-fet/anduril.h +++ b/hw/hank/emisar-d1v2/linear-fet/anduril.h @@ -13,6 +13,7 @@ // the aux LEDs are in the button, so use them while main LEDs are on #define USE_AUX_RGB_LEDS #define USE_AUX_RGB_LEDS_WHILE_ON 25 +#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING // safe limit: max regulated power diff --git a/hw/hank/emisar-d1v2/nofet/anduril.h b/hw/hank/emisar-d1v2/nofet/anduril.h index 1c320e7..7900d98 100644 --- a/hw/hank/emisar-d1v2/nofet/anduril.h +++ b/hw/hank/emisar-d1v2/nofet/anduril.h @@ -13,6 +13,7 @@ // the aux LEDs are in the button, so use them while main LEDs are on #define USE_AUX_RGB_LEDS #define USE_AUX_RGB_LEDS_WHILE_ON 25 +#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING // safe limit: same as regular ramp diff --git a/hw/hank/emisar-d4k-3ch/anduril.h b/hw/hank/emisar-d4k-3ch/anduril.h index 722fa89..ede62b3 100644 --- a/hw/hank/emisar-d4k-3ch/anduril.h +++ b/hw/hank/emisar-d4k-3ch/anduril.h @@ -12,6 +12,7 @@ // turn on the aux LEDs while main LEDs are on // (in case there's a RGB button) #define USE_AUX_RGB_LEDS_WHILE_ON 40 +#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING // channel modes... diff --git a/hw/hank/noctigon-k1/anduril.h b/hw/hank/noctigon-k1/anduril.h index 06a9b69..48dc947 100644 --- a/hw/hank/noctigon-k1/anduril.h +++ b/hw/hank/noctigon-k1/anduril.h @@ -14,6 +14,7 @@ // this light has three aux LED channels: R, G, B #define USE_AUX_RGB_LEDS #define USE_AUX_RGB_LEDS_WHILE_ON 5 +#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING diff --git a/hw/hank/noctigon-k1/boost/anduril.h b/hw/hank/noctigon-k1/boost/anduril.h index 4ea1127..01969eb 100644 --- a/hw/hank/noctigon-k1/boost/anduril.h +++ b/hw/hank/noctigon-k1/boost/anduril.h @@ -17,6 +17,7 @@ // this light has three aux LED channels: R, G, B #define USE_AUX_RGB_LEDS #define USE_AUX_RGB_LEDS_WHILE_ON 25 +#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING #if 0 // old, 10-bit PWM method diff --git a/hw/hank/noctigon-k1/sbt90/anduril.h b/hw/hank/noctigon-k1/sbt90/anduril.h index 6943a0a..ef9e067 100644 --- a/hw/hank/noctigon-k1/sbt90/anduril.h +++ b/hw/hank/noctigon-k1/sbt90/anduril.h @@ -14,6 +14,7 @@ // this light has three aux LED channels: R, G, B #define USE_AUX_RGB_LEDS #define USE_AUX_RGB_LEDS_WHILE_ON 10 +#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING diff --git a/hw/wurkkos/fc13/anduril.h b/hw/wurkkos/fc13/anduril.h index db766c7..dd23d4a 100644 --- a/hw/wurkkos/fc13/anduril.h +++ b/hw/wurkkos/fc13/anduril.h @@ -10,5 +10,6 @@ // turn on the aux LEDs while main LEDs are on #define USE_AUX_RGB_LEDS_WHILE_ON 20 +#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING diff --git a/hw/wurkkos/ts11/anduril.h b/hw/wurkkos/ts11/anduril.h index 169c848..e329c38 100644 --- a/hw/wurkkos/ts11/anduril.h +++ b/hw/wurkkos/ts11/anduril.h @@ -12,5 +12,6 @@ // (but not until the main LEDs are bright enough to overpower the aux) // (setting this lower makes an annoying effect on some levels) #define USE_AUX_RGB_LEDS_WHILE_ON 50 +#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING diff --git a/ui/anduril/anduril.c b/ui/anduril/anduril.c index 4378816..fdc9527 100644 --- a/ui/anduril/anduril.c +++ b/ui/anduril/anduril.c @@ -278,9 +278,13 @@ void loop() { StatePtr state = current_state; #ifdef USE_AUX_RGB_LEDS_WHILE_ON - // display battery charge on RGB button during use - if (state == steady_state) - rgb_led_voltage_readout(actual_level > USE_AUX_RGB_LEDS_WHILE_ON); + // display battery charge on RGB button during use + #ifdef USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS + if ((state == steady_state) && (actual_level > cfg.use_aux_rgb_leds_while_on_min_level)) // only show voltage if we are above the configured minimum ramp level + #else + if (state == steady_state) + #endif + rgb_led_voltage_readout(actual_level > USE_AUX_RGB_LEDS_WHILE_ON); #endif if (0) {} // placeholder diff --git a/ui/anduril/battcheck-mode.c b/ui/anduril/battcheck-mode.c index c7c80dd..997c2b0 100644 --- a/ui/anduril/battcheck-mode.c +++ b/ui/anduril/battcheck-mode.c @@ -61,21 +61,23 @@ uint8_t battcheck_state(Event event, uint16_t arg) { // ... // 13 = add 0.30V void voltage_config_save(uint8_t step, uint8_t value) { + #if defined(USE_AUX_RGB_LEDS_WHILE_ON) && defined(USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS) + if (use_aux_rgb_leds_while_on_config_step == step) cfg.use_aux_rgb_leds_while_on = value; + else if (use_aux_rgb_leds_while_on_min_level_step == step) cfg.use_aux_rgb_leds_while_on_min_level = value; + else + #endif #ifdef USE_POST_OFF_VOLTAGE - if (2 == step) cfg.post_off_voltage = value; - else + if (post_off_voltage_config_step == step) cfg.post_off_voltage = value; + else + #endif + #ifdef USE_VOLTAGE_CORRECTION + if (value) cfg.voltage_correction = value; #endif - if (value) cfg.voltage_correction = value; } uint8_t voltage_config_state(Event event, uint16_t arg) { - #ifdef USE_POST_OFF_VOLTAGE - #define VOLTAGE_CONFIG_STEPS 2 - #else - #define VOLTAGE_CONFIG_STEPS 1 - #endif return config_state_base(event, arg, - VOLTAGE_CONFIG_STEPS, + (voltage_config_num_steps - 1), voltage_config_save); } #endif // #ifdef USE_VOLTAGE_CORRECTION diff --git a/ui/anduril/battcheck-mode.h b/ui/anduril/battcheck-mode.h index b505b68..4acdb74 100644 --- a/ui/anduril/battcheck-mode.h +++ b/ui/anduril/battcheck-mode.h @@ -10,3 +10,18 @@ void voltage_config_save(uint8_t step, uint8_t value); uint8_t voltage_config_state(Event event, uint16_t arg); #endif +typedef enum { + voltage_cfg_zero = 0, + #ifdef USE_VOLTAGE_CORRECTION + voltage_correction_config_step, + #endif + #ifdef USE_POST_OFF_VOLTAGE + post_off_voltage_config_step, + #endif + #if defined(USE_AUX_RGB_LEDS_WHILE_ON) && defined(USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS) + use_aux_rgb_leds_while_on_config_step, + use_aux_rgb_leds_while_on_min_level_step, + #endif + voltage_config_num_steps +} voltage_config_steps_e; + diff --git a/ui/anduril/load-save-config-fsm.h b/ui/anduril/load-save-config-fsm.h index d189d3a..61947ce 100644 --- a/ui/anduril/load-save-config-fsm.h +++ b/ui/anduril/load-save-config-fsm.h @@ -97,6 +97,10 @@ typedef struct Config { uint8_t therm_ceil; int8_t therm_cal_offset; #endif + #if defined(USE_AUX_RGB_LEDS_WHILE_ON) && defined(USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS) + uint8_t use_aux_rgb_leds_while_on; + uint8_t use_aux_rgb_leds_while_on_min_level; + #endif ///// aux LEDs #ifdef USE_INDICATOR_LED diff --git a/ui/anduril/load-save-config.h b/ui/anduril/load-save-config.h index 3ad477c..6a52171 100644 --- a/ui/anduril/load-save-config.h +++ b/ui/anduril/load-save-config.h @@ -169,5 +169,20 @@ Config cfg = { .jump_start_level = DEFAULT_JUMP_START_LEVEL, #endif + #if defined(USE_AUX_RGB_LEDS_WHILE_ON) && defined(USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS) + // config for RGB voltage. We need to check these here rather than setting defaults in `config-default.h` as we only know *after* defaults are loaded if `USE_AUX_RGB_LEDS_WHILE_ON` is set or unset (in `CFG_H`). + #if (USE_AUX_RGB_LEDS_WHILE_ON + 0) // if USE_AUX_RGB_LEDS_WHILE_ON is an int, passes. If blank (undefined or defined with no value), evaluates to `(+0)` which evaluates to false. + .use_aux_rgb_leds_while_on = USE_AUX_RGB_LEDS_WHILE_ON, + #else + #warning "USE_AUX_RGB_LEDS_WHILE_ON defined but has no value. Setting minimum threshold to default of 25" + .use_aux_rgb_leds_while_on = 25, + #endif + #ifdef USE_AUX_RGB_LEDS_WHILE_ON_INITIAL_MINIMUM_LEVEL + .use_aux_rgb_leds_while_on_min_level = USE_AUX_RGB_LEDS_WHILE_ON_INITIAL_MINIMUM_LEVEL, + #else + .use_aux_rgb_leds_while_on_min_level = 15, // default + #endif + #endif + }; -- cgit v1.2.3 From 2b19de99a2c4acd8041a50593ff3a7586fe06a27 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 4 Jul 2025 04:57:34 -0600 Subject: made new settings apply to all button LEDs on lights bigger than 8K ROM This replaces "USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS" with "USE_AUX_THRESHOLD_CONFIG", which controls the brightness of button LEDs while the main LEDs are on, and during post-off voltage display. Same basic concept, but works on single-color LEDs too, and lets the user finally configure POVD thresholds. The code for this is a bit messy, but the aux LED code as a whole is pretty messy since it wasn't designed for the things it does now. The entire thing needs a refactor or rewrite someday. But not today. For now, this is just enough to make the pull request cover more use cases before merging into trunk. I've tested it on a variety of lights, but am not yet entirely comfortable with it. However, it worked on at least these: - 1-color button LED, no RGB - front RGB, 1-color button LED - front RGB, hardwired also to RGB button - RGB button, no other aux These may need extra changes, and may have extra config options which do nothing... - front RGB, no button LED - 1-color front aux, no button LED - no aux at all - attiny85 lights (some could theoretically support the new options, but none even try) --- docs/anduril-manual.md | 39 +++++++++++++++++-------------- fsm/ramping.c | 27 ++++++++++++++++----- hw/hank/emisar-d1v2/7135-fet/anduril.h | 1 - hw/hank/emisar-d1v2/linear-fet/anduril.h | 1 - hw/hank/emisar-d1v2/nofet/anduril.h | 1 - hw/hank/emisar-d4k-3ch/anduril.h | 1 - hw/hank/noctigon-k1/anduril.h | 1 - hw/hank/noctigon-k1/boost/anduril.h | 1 - hw/hank/noctigon-k1/sbt90/anduril.h | 1 - hw/wurkkos/fc13/anduril.h | 1 - hw/wurkkos/ts11/anduril.h | 1 - ui/anduril/anduril.c | 16 ++++++++----- ui/anduril/aux-leds.c | 13 ++++++++++- ui/anduril/battcheck-mode.c | 40 +++++++++++++++++++++----------- ui/anduril/battcheck-mode.h | 12 +++++----- ui/anduril/config-default.h | 8 +++++++ ui/anduril/load-save-config-fsm.h | 6 ++--- ui/anduril/load-save-config.h | 28 +++++++++++++++------- 18 files changed, 127 insertions(+), 71 deletions(-) diff --git a/docs/anduril-manual.md b/docs/anduril-manual.md index 4a1723b..2b7ea30 100644 --- a/docs/anduril-manual.md +++ b/docs/anduril-manual.md @@ -455,16 +455,17 @@ The voltage config menu has these settings: once per desired second, or zero times to turn this function off. - 3. RGB voltage while on high threshold. On lights where the battery - voltage is displayed using RGB aux while the light is on, sets - the ramp level at which the aux will switch to high brightness. - If set to 151, this effectively forces the voltage to only ever - be displayed using low brightness, or if set to 0, to only ever - use high brightness. - - 4. RGB voltage while on minimum level. Below this level, voltage will - not be displayed using the RGB aux at all. Setting this to 151+ - effectively disables the entire feature. + 3. Aux low ramp level. Controls behavior of aux button LEDs while the main + LEDs are on. Below this ramp level, button LEDs will not be lit up while + the main LEDs are on. At or above this level, button LEDs light up at the + "low" brightness level. Setting it to 0 keeps the button LEDs off + completely while the main LEDs are on. + Also controls brightness of post-off voltage display. + + 4. Aux high ramp level. At or above this ramp level, button LEDs light up at + the "high" brightness level. Setting it to 0 disables button's high aux + mode while the main LEDs are on. + Also controls brightness of post-off voltage display. ### Temperature check: @@ -1076,14 +1077,18 @@ This is a table of all button mappings in Anduril, in one place: | Batt check | Full | `3C` | Next channel mode (for number blinks only) | Batt check | Full | `7H` | Voltage config menu | | | | 1: voltage correction factor -| | | | ... -| | | | 5: -0.10V -| | | | 6: -0.05V -| | | | 7: no correction -| | | | 8: +0.05V -| | | | 9: +0.10V -| | | | ... +| | | | ... 5: -0.10V +| | | | ... 6: -0.05V +| | | | ... 7: no correction +| | | | ... 8: +0.05V +| | | | ... 9: +0.10V | | | | 2: post-off voltage display seconds +| | | | 3: aux low ramp level +| | | | ... 0: disabled +| | | | ... 1+: light up at this ramp level +| | | | 4: aux high ramp level +| | | | ... 0: disabled +| | | | ... 1+: brighter at this ramp level | Mode | UI | Button | Action | :--- | :-- | ------: | :----- diff --git a/fsm/ramping.c b/fsm/ramping.c index e0c391a..f8ca4ec 100644 --- a/fsm/ramping.c +++ b/fsm/ramping.c @@ -8,14 +8,20 @@ #ifdef HAS_AUX_LEDS inline void set_level_aux_leds(uint8_t level) { + #ifdef USE_AUX_THRESHOLD_CONFIG + #define AUX_BRIGHTNESS ((level > cfg.button_led_low_ramp_level) \ + << (level > cfg.button_led_high_ramp_level)) + #else + #define AUX_BRIGHTNESS ((level > 0) + (level > DEFAULT_LEVEL)) + #endif #ifdef USE_INDICATOR_LED_WHILE_RAMPING // use side-facing aux LEDs while main LEDs are on if (! go_to_standby) { #ifdef USE_INDICATOR_LED - indicator_led((level > 0) + (level > DEFAULT_LEVEL)); + indicator_led(AUX_BRIGHTNESS); #endif #ifdef USE_BUTTON_LED - button_led_set((level > 0) + (level > DEFAULT_LEVEL)); + button_led_set(AUX_BRIGHTNESS); #endif } #else // turn off front-facing aux LEDs while main LEDs are on @@ -27,12 +33,15 @@ inline void set_level_aux_leds(uint8_t level) { #ifdef USE_AUX_RGB_LEDS rgb_led_set(0); #ifdef USE_BUTTON_LED - button_led_set((level > 0) + (level > DEFAULT_LEVEL)); + button_led_set(AUX_BRIGHTNESS); #endif #endif } #endif #endif + #ifdef AUX_BRIGHTNESS + #undef AUX_BRIGHTNESS + #endif } #endif // ifdef HAS_AUX_LEDS @@ -41,9 +50,9 @@ inline void set_level_aux_leds(uint8_t level) { #include "anduril/aux-leds.h" // for rgb_led_voltage_readout() inline void set_level_aux_rgb_leds(uint8_t level) { if (! go_to_standby) { - #ifdef USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS - if ((level > 0) && (actual_level > cfg.use_aux_rgb_leds_while_on_min_level)){ - rgb_led_voltage_readout(level > cfg.use_aux_rgb_leds_while_on); + #ifdef USE_AUX_THRESHOLD_CONFIG + if (level > cfg.button_led_low_ramp_level) { + rgb_led_voltage_readout(level > cfg.button_led_high_ramp_level); } #else if (level > 0) { @@ -56,7 +65,13 @@ inline void set_level_aux_rgb_leds(uint8_t level) { // some drivers can be wired with RGB or single color to button // ... so support both even though only one is connected #ifdef USE_BUTTON_LED + #ifdef USE_AUX_THRESHOLD_CONFIG + button_led_set( + (level > cfg.button_led_low_ramp_level) + << (level > cfg.button_led_high_ramp_level)); + #else button_led_set((level > 0) + (level > DEFAULT_LEVEL)); + #endif #endif } } diff --git a/hw/hank/emisar-d1v2/7135-fet/anduril.h b/hw/hank/emisar-d1v2/7135-fet/anduril.h index 8682585..968162a 100644 --- a/hw/hank/emisar-d1v2/7135-fet/anduril.h +++ b/hw/hank/emisar-d1v2/7135-fet/anduril.h @@ -15,7 +15,6 @@ // so it's unlikely that anyone needs this, but it doesn't hurt anything) #define USE_AUX_RGB_LEDS #define USE_AUX_RGB_LEDS_WHILE_ON 25 -#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING // safe limit ~50% power diff --git a/hw/hank/emisar-d1v2/linear-fet/anduril.h b/hw/hank/emisar-d1v2/linear-fet/anduril.h index a15fa5e..1d09001 100644 --- a/hw/hank/emisar-d1v2/linear-fet/anduril.h +++ b/hw/hank/emisar-d1v2/linear-fet/anduril.h @@ -13,7 +13,6 @@ // the aux LEDs are in the button, so use them while main LEDs are on #define USE_AUX_RGB_LEDS #define USE_AUX_RGB_LEDS_WHILE_ON 25 -#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING // safe limit: max regulated power diff --git a/hw/hank/emisar-d1v2/nofet/anduril.h b/hw/hank/emisar-d1v2/nofet/anduril.h index 7900d98..1c320e7 100644 --- a/hw/hank/emisar-d1v2/nofet/anduril.h +++ b/hw/hank/emisar-d1v2/nofet/anduril.h @@ -13,7 +13,6 @@ // the aux LEDs are in the button, so use them while main LEDs are on #define USE_AUX_RGB_LEDS #define USE_AUX_RGB_LEDS_WHILE_ON 25 -#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING // safe limit: same as regular ramp diff --git a/hw/hank/emisar-d4k-3ch/anduril.h b/hw/hank/emisar-d4k-3ch/anduril.h index ede62b3..722fa89 100644 --- a/hw/hank/emisar-d4k-3ch/anduril.h +++ b/hw/hank/emisar-d4k-3ch/anduril.h @@ -12,7 +12,6 @@ // turn on the aux LEDs while main LEDs are on // (in case there's a RGB button) #define USE_AUX_RGB_LEDS_WHILE_ON 40 -#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING // channel modes... diff --git a/hw/hank/noctigon-k1/anduril.h b/hw/hank/noctigon-k1/anduril.h index 48dc947..06a9b69 100644 --- a/hw/hank/noctigon-k1/anduril.h +++ b/hw/hank/noctigon-k1/anduril.h @@ -14,7 +14,6 @@ // this light has three aux LED channels: R, G, B #define USE_AUX_RGB_LEDS #define USE_AUX_RGB_LEDS_WHILE_ON 5 -#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING diff --git a/hw/hank/noctigon-k1/boost/anduril.h b/hw/hank/noctigon-k1/boost/anduril.h index 01969eb..4ea1127 100644 --- a/hw/hank/noctigon-k1/boost/anduril.h +++ b/hw/hank/noctigon-k1/boost/anduril.h @@ -17,7 +17,6 @@ // this light has three aux LED channels: R, G, B #define USE_AUX_RGB_LEDS #define USE_AUX_RGB_LEDS_WHILE_ON 25 -#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING #if 0 // old, 10-bit PWM method diff --git a/hw/hank/noctigon-k1/sbt90/anduril.h b/hw/hank/noctigon-k1/sbt90/anduril.h index ef9e067..6943a0a 100644 --- a/hw/hank/noctigon-k1/sbt90/anduril.h +++ b/hw/hank/noctigon-k1/sbt90/anduril.h @@ -14,7 +14,6 @@ // this light has three aux LED channels: R, G, B #define USE_AUX_RGB_LEDS #define USE_AUX_RGB_LEDS_WHILE_ON 10 -#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING diff --git a/hw/wurkkos/fc13/anduril.h b/hw/wurkkos/fc13/anduril.h index dd23d4a..db766c7 100644 --- a/hw/wurkkos/fc13/anduril.h +++ b/hw/wurkkos/fc13/anduril.h @@ -10,6 +10,5 @@ // turn on the aux LEDs while main LEDs are on #define USE_AUX_RGB_LEDS_WHILE_ON 20 -#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING diff --git a/hw/wurkkos/ts11/anduril.h b/hw/wurkkos/ts11/anduril.h index e329c38..169c848 100644 --- a/hw/wurkkos/ts11/anduril.h +++ b/hw/wurkkos/ts11/anduril.h @@ -12,6 +12,5 @@ // (but not until the main LEDs are bright enough to overpower the aux) // (setting this lower makes an annoying effect on some levels) #define USE_AUX_RGB_LEDS_WHILE_ON 50 -#define USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS #define USE_INDICATOR_LED_WHILE_RAMPING diff --git a/ui/anduril/anduril.c b/ui/anduril/anduril.c index 5972eb2..a17ecf2 100644 --- a/ui/anduril/anduril.c +++ b/ui/anduril/anduril.c @@ -287,12 +287,16 @@ void loop() { #ifdef USE_AUX_RGB_LEDS_WHILE_ON // display battery charge on RGB button during use - #ifdef USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS - if ((state == steady_state) && (actual_level > cfg.use_aux_rgb_leds_while_on_min_level)) // only show voltage if we are above the configured minimum ramp level - #else - if (state == steady_state) - #endif - rgb_led_voltage_readout(actual_level > USE_AUX_RGB_LEDS_WHILE_ON); + if (state == steady_state) { + #ifdef USE_AUX_THRESHOLD_CONFIG + // only show voltage if feature is enabled and + // we are above the configured minimum ramp level + if (actual_level > cfg.button_led_low_ramp_level) + rgb_led_voltage_readout(actual_level > cfg.button_led_high_ramp_level); + #else + rgb_led_voltage_readout(actual_level > USE_AUX_RGB_LEDS_WHILE_ON); + #endif + } #endif if (0) {} // placeholder diff --git a/ui/anduril/aux-leds.c b/ui/anduril/aux-leds.c index 7356666..50ce5c5 100644 --- a/ui/anduril/aux-leds.c +++ b/ui/anduril/aux-leds.c @@ -125,7 +125,18 @@ void rgb_led_update(uint8_t mode, uint16_t arg) { && (ticks_since_on > 0) // don't blink red on 1st frame ) { // use high mode if regular aux level is high or prev level was high - pattern = 1 + ((2 == pattern) | (prev_level >= POST_OFF_VOLTAGE_BRIGHTNESS)); + #ifdef USE_AUX_THRESHOLD_CONFIG + // always high if configured for high aux + // otherwise 0/1/2 depending on recent main LED brightness + // (using >= makes it off by 1, but allows POVD at boot time) + if (pattern != 2) + pattern = (prev_level >= cfg.button_led_low_ramp_level) + << (prev_level > cfg.button_led_high_ramp_level); + #else + pattern = 1 + + ((2 == pattern) + | (prev_level >= POST_OFF_VOLTAGE_BRIGHTNESS)); + #endif // voltage mode color = RGB_LED_NUM_COLORS - 1; } diff --git a/ui/anduril/battcheck-mode.c b/ui/anduril/battcheck-mode.c index 997c2b0..460c58a 100644 --- a/ui/anduril/battcheck-mode.c +++ b/ui/anduril/battcheck-mode.c @@ -51,7 +51,7 @@ uint8_t battcheck_state(Event event, uint16_t arg) { return EVENT_NOT_HANDLED; } -#ifdef USE_VOLTAGE_CORRECTION +#if defined(USE_VOLTAGE_CORRECTION) || defined(USE_POST_OFF_VOLTAGE) || defined(USE_AUX_THRESHOLD_CONFIG) // the user can adjust the battery measurements... on a scale of 1 to 13 // 1 = subtract 0.30V // 2 = subtract 0.25V @@ -61,23 +61,35 @@ uint8_t battcheck_state(Event event, uint16_t arg) { // ... // 13 = add 0.30V void voltage_config_save(uint8_t step, uint8_t value) { - #if defined(USE_AUX_RGB_LEDS_WHILE_ON) && defined(USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS) - if (use_aux_rgb_leds_while_on_config_step == step) cfg.use_aux_rgb_leds_while_on = value; - else if (use_aux_rgb_leds_while_on_min_level_step == step) cfg.use_aux_rgb_leds_while_on_min_level = value; - else - #endif - #ifdef USE_POST_OFF_VOLTAGE - if (post_off_voltage_config_step == step) cfg.post_off_voltage = value; - else - #endif - #ifdef USE_VOLTAGE_CORRECTION - if (value) cfg.voltage_correction = value; - #endif + switch (step) { + #if defined(USE_AUX_THRESHOLD_CONFIG) + case button_led_low_ramp_level_step: + // 0 clicks = 255 = never turn on + cfg.button_led_low_ramp_level = value - 1; + break; + case button_led_high_ramp_level_step: + // 0 clicks = 255 = never turn on + cfg.button_led_high_ramp_level = value - 1; + break; + #endif + + #ifdef USE_POST_OFF_VOLTAGE + case post_off_voltage_config_step: + cfg.post_off_voltage = value; + break; + #endif + + #ifdef USE_VOLTAGE_CORRECTION + default: + if (value) cfg.voltage_correction = value; + break; + #endif + } } uint8_t voltage_config_state(Event event, uint16_t arg) { return config_state_base(event, arg, - (voltage_config_num_steps - 1), + voltage_config_num_steps - 1, voltage_config_save); } #endif // #ifdef USE_VOLTAGE_CORRECTION diff --git a/ui/anduril/battcheck-mode.h b/ui/anduril/battcheck-mode.h index 4acdb74..2ff7c81 100644 --- a/ui/anduril/battcheck-mode.h +++ b/ui/anduril/battcheck-mode.h @@ -5,7 +5,7 @@ uint8_t battcheck_state(Event event, uint16_t arg); -#ifdef USE_VOLTAGE_CORRECTION +#if defined(USE_VOLTAGE_CORRECTION) || defined(USE_POST_OFF_VOLTAGE) || defined(USE_AUX_THRESHOLD_CONFIG) void voltage_config_save(uint8_t step, uint8_t value); uint8_t voltage_config_state(Event event, uint16_t arg); #endif @@ -13,14 +13,14 @@ uint8_t voltage_config_state(Event event, uint16_t arg); typedef enum { voltage_cfg_zero = 0, #ifdef USE_VOLTAGE_CORRECTION - voltage_correction_config_step, + voltage_correction_config_step, #endif #ifdef USE_POST_OFF_VOLTAGE - post_off_voltage_config_step, + post_off_voltage_config_step, #endif - #if defined(USE_AUX_RGB_LEDS_WHILE_ON) && defined(USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS) - use_aux_rgb_leds_while_on_config_step, - use_aux_rgb_leds_while_on_min_level_step, + #if defined(USE_AUX_THRESHOLD_CONFIG) + button_led_low_ramp_level_step, + button_led_high_ramp_level_step, #endif voltage_config_num_steps } voltage_config_steps_e; diff --git a/ui/anduril/config-default.h b/ui/anduril/config-default.h index 1b34e8c..51249f6 100644 --- a/ui/anduril/config-default.h +++ b/ui/anduril/config-default.h @@ -199,6 +199,14 @@ #define USE_LOWPASS_WHILE_ASLEEP #endif +// if the light has aux LEDs and enough ROM, let the user choose whether +// the aux LEDs should be on while the main LEDs are on +#if (ROM_SIZE > 10000) +// can be enabled even if no aux LEDs exist, +// will simply do nothing in that case +#define USE_AUX_THRESHOLD_CONFIG +#endif + // if there's tint ramping, allow user to set it smooth or stepped #define USE_STEPPED_TINT_RAMPING #define DEFAULT_TINT_RAMP_STYLE 0 // smooth diff --git a/ui/anduril/load-save-config-fsm.h b/ui/anduril/load-save-config-fsm.h index 61947ce..a69d1b1 100644 --- a/ui/anduril/load-save-config-fsm.h +++ b/ui/anduril/load-save-config-fsm.h @@ -97,9 +97,9 @@ typedef struct Config { uint8_t therm_ceil; int8_t therm_cal_offset; #endif - #if defined(USE_AUX_RGB_LEDS_WHILE_ON) && defined(USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS) - uint8_t use_aux_rgb_leds_while_on; - uint8_t use_aux_rgb_leds_while_on_min_level; + #ifdef USE_AUX_THRESHOLD_CONFIG + uint8_t button_led_low_ramp_level; + uint8_t button_led_high_ramp_level; #endif ///// aux LEDs diff --git a/ui/anduril/load-save-config.h b/ui/anduril/load-save-config.h index 6a52171..f5afb29 100644 --- a/ui/anduril/load-save-config.h +++ b/ui/anduril/load-save-config.h @@ -169,18 +169,28 @@ Config cfg = { .jump_start_level = DEFAULT_JUMP_START_LEVEL, #endif - #if defined(USE_AUX_RGB_LEDS_WHILE_ON) && defined(USE_CONFIGURABLE_RGB_VOLTAGE_LEVELS) - // config for RGB voltage. We need to check these here rather than setting defaults in `config-default.h` as we only know *after* defaults are loaded if `USE_AUX_RGB_LEDS_WHILE_ON` is set or unset (in `CFG_H`). - #if (USE_AUX_RGB_LEDS_WHILE_ON + 0) // if USE_AUX_RGB_LEDS_WHILE_ON is an int, passes. If blank (undefined or defined with no value), evaluates to `(+0)` which evaluates to false. - .use_aux_rgb_leds_while_on = USE_AUX_RGB_LEDS_WHILE_ON, + #if defined(USE_AUX_THRESHOLD_CONFIG) + // config for RGB voltage. We need to check these here rather than + // setting defaults in `config-default.h` as we only know *after* + // defaults are loaded if `USE_AUX_RGB_LEDS_WHILE_ON` is set or unset + // (in `CFG_H`). + #ifdef USE_AUX_LEDS_WHILE_ON_INITIAL_MINIMUM_LEVEL + .button_led_low_ramp_level = USE_AUX_LEDS_WHILE_ON_INITIAL_MINIMUM_LEVEL, #else - #warning "USE_AUX_RGB_LEDS_WHILE_ON defined but has no value. Setting minimum threshold to default of 25" - .use_aux_rgb_leds_while_on = 25, + .button_led_low_ramp_level = 0, // default #endif - #ifdef USE_AUX_RGB_LEDS_WHILE_ON_INITIAL_MINIMUM_LEVEL - .use_aux_rgb_leds_while_on_min_level = USE_AUX_RGB_LEDS_WHILE_ON_INITIAL_MINIMUM_LEVEL, + #if (USE_AUX_RGB_LEDS_WHILE_ON + 0) + // if USE_AUX_RGB_LEDS_WHILE_ON is an int, passes. If blank (undefined + // or defined with no value), evaluates to `(+0)` which evaluates to + // false. + .button_led_high_ramp_level = USE_AUX_RGB_LEDS_WHILE_ON, #else - .use_aux_rgb_leds_while_on_min_level = 15, // default + #ifdef USE_AUX_RGB_LEDS + //#warning "USE_AUX_RGB_LEDS_WHILE_ON defined but has no value. Setting to default value." + .button_led_high_ramp_level = 25 - 1, // default + #else + .button_led_high_ramp_level = DEFAULT_LEVEL - 1, // default + #endif #endif #endif -- cgit v1.2.3