aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/anduril/anduril.c47
-rw-r--r--ui/anduril/aux-leds.c52
-rw-r--r--ui/anduril/battcheck-mode.c38
-rw-r--r--ui/anduril/battcheck-mode.h17
-rw-r--r--ui/anduril/config-default.h8
-rw-r--r--ui/anduril/load-save-config-fsm.h4
-rw-r--r--ui/anduril/load-save-config.h25
-rw-r--r--ui/anduril/lockout-mode.c26
-rw-r--r--ui/anduril/off-mode.c26
-rw-r--r--ui/anduril/strobe-modes.c2
-rw-r--r--ui/anduril/tactical-mode.c5
11 files changed, 181 insertions, 69 deletions
diff --git a/ui/anduril/anduril.c b/ui/anduril/anduril.c
index 1cdb8d0..a17ecf2 100644
--- a/ui/anduril/anduril.c
+++ b/ui/anduril/anduril.c
@@ -121,7 +121,7 @@
#include "anduril/lockout-mode.h"
#endif
-#ifdef USE_MOMENTARY_MODE
+#if (defined(USE_MOMENTARY_MODE) || defined(USE_TACTICAL_MODE))
#include "anduril/momentary-mode.h"
#endif
@@ -189,7 +189,7 @@
#include "anduril/lockout-mode.c"
#endif
-#ifdef USE_MOMENTARY_MODE
+#if (defined(USE_MOMENTARY_MODE) || defined(USE_TACTICAL_MODE))
#include "anduril/momentary-mode.c"
#endif
@@ -225,8 +225,16 @@ void setup() {
// regular e-switch light, no hard clicky power button
- // blink at power-on to let user know power is connected
- blink_once();
+ #ifdef USE_WEAK_BATTERY_PROTECTION
+ // try to measure the battery strength
+ // (must be done *before* factory reset,
+ // because reset tries to use full power,
+ // and a weak battery can't do that)
+ detect_weak_battery();
+ #else
+ // blink at power-on to let user know power is connected
+ blink_once();
+ #endif
#ifdef USE_FACTORY_RESET
if (button_is_pressed())
@@ -278,9 +286,17 @@ 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
+ 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
@@ -293,10 +309,12 @@ void loop() {
#ifdef USE_STROBE_STATE
else if ((state == strobe_state)
- #ifdef USE_MOMENTARY_MODE
+ #if defined(USE_MOMENTARY_MODE) || defined(USE_TACTICAL_MODE)
// also handle momentary strobes
- || ((
- (state == momentary_state)
+ || ((0
+ #ifdef USE_MOMENTARY_MODE
+ || (state == momentary_state)
+ #endif
#ifdef USE_TACTICAL_MODE
|| (state == tactical_state)
#endif
@@ -331,6 +349,15 @@ void loop() {
#ifdef USE_THERMAL_REGULATION
// TODO: blink out therm_ceil during thermal_config_state?
else if (state == tempcheck_state) {
+ // temperature is type int16_t
+ // but blink_num is uint8_t, so -10 will blink as 246
+ #ifdef USE_LONG_BLINK_FOR_NEGATIVE_SIGN
+ if (temperature < 0) {
+ blink_negative();
+ blink_num(-temperature);
+ }
+ else
+ #endif
blink_num(temperature);
nice_delay_ms(1000);
}
diff --git a/ui/anduril/aux-leds.c b/ui/anduril/aux-leds.c
index fd184fc..50ce5c5 100644
--- a/ui/anduril/aux-leds.c
+++ b/ui/anduril/aux-leds.c
@@ -58,27 +58,27 @@ void indicator_led_update(uint8_t mode, uint8_t tick) {
uint8_t voltage_to_rgb() {
static const uint8_t levels[] = {
// voltage, color
- 0, 0, // black
+ 0, 0, // black
#ifdef DUAL_VOLTAGE_FLOOR
// AA / NiMH voltages
- 4* 9, 1, // R
- 4*10, 2, // R+G
- 4*11, 3, // G
- 4*12, 4, // G+B
- 4*13, 5, // B
- 4*14, 6, // R + B
- 4*16, 7, // R+G+B
- 4*20, 0, // black
+ 9*dV, 1, // R
+ 10*dV, 2, // R+G
+ 11*dV, 3, // G
+ 12*dV, 4, // G+B
+ 13*dV, 5, // B
+ 14*dV, 6, // R + B
+ 16*dV, 7, // R+G+B
+ 20*dV, 0, // black
#endif
// li-ion voltages
- 4*29, 1, // R
- 4*33, 2, // R+G
- 4*35, 3, // G
- 4*37, 4, // G+B
- 4*39, 5, // B
- 4*41, 6, // R + B
- 4*44, 7, // R+G+B // skip; looks too similar to G+B
- 255, 7, // R+G+B
+ 29*dV, 1, // R
+ 33*dV, 2, // R+G
+ 35*dV, 3, // G
+ 37*dV, 4, // G+B
+ 39*dV, 5, // B
+ 41*dV, 6, // R + B
+ 44*dV, 7, // R+G+B // skip; looks too similar to G+B
+ 255, 7, // R+G+B
};
uint8_t volts = voltage;
//if (volts < VOLTAGE_LOW) return 0;
@@ -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;
}
@@ -151,11 +162,8 @@ void rgb_led_update(uint8_t mode, uint16_t arg) {
else { // voltage
// show actual voltage while asleep...
if (go_to_standby) {
- actual_color = voltage_to_rgb();
// choose a color based on battery voltage
- //if (volts >= 38) actual_color = pgm_read_byte(colors + 4);
- //else if (volts >= 33) actual_color = pgm_read_byte(colors + 2);
- //else actual_color = pgm_read_byte(colors + 0);
+ actual_color = voltage_to_rgb();
}
// ... but during preview, cycle colors quickly
else {
diff --git a/ui/anduril/battcheck-mode.c b/ui/anduril/battcheck-mode.c
index c7c80dd..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,21 +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) {
- #ifdef USE_POST_OFF_VOLTAGE
- if (2 == step) cfg.post_off_voltage = value;
- else
- #endif
- if (value) cfg.voltage_correction = value;
+ 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) {
- #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..2ff7c81 100644
--- a/ui/anduril/battcheck-mode.h
+++ b/ui/anduril/battcheck-mode.h
@@ -5,8 +5,23 @@
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
+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_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 d189d3a..a69d1b1 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
+ #ifdef USE_AUX_THRESHOLD_CONFIG
+ uint8_t button_led_low_ramp_level;
+ uint8_t button_led_high_ramp_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..f5afb29 100644
--- a/ui/anduril/load-save-config.h
+++ b/ui/anduril/load-save-config.h
@@ -169,5 +169,30 @@ Config cfg = {
.jump_start_level = DEFAULT_JUMP_START_LEVEL,
#endif
+ #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
+ .button_led_low_ramp_level = 0, // default
+ #endif
+ #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
+ #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
+
};
diff --git a/ui/anduril/lockout-mode.c b/ui/anduril/lockout-mode.c
index 6f85ca9..255ab22 100644
--- a/ui/anduril/lockout-mode.c
+++ b/ui/anduril/lockout-mode.c
@@ -12,25 +12,31 @@ uint8_t lockout_state(Event event, uint16_t arg) {
// button is being held
#ifdef USE_AUX_RGB_LEDS
// don't turn on during RGB aux LED configuration
- if (event == EV_click7_hold) { set_level(0); } else
+ //if (event == EV_click7_hold) { set_level(0); } else
#endif
- if ((event & (B_CLICK | B_PRESS)) == (B_CLICK | B_PRESS)) {
- // hold: lowest floor
- // click, hold: highest floor (or manual mem level)
+ uint8_t click_num = event & B_COUNT;
+ if ( // button pressed 1st or 2nd time
+ ((B_CLICK | B_PRESS) == (event & (B_CLICK | B_PRESS)))
+ && (click_num <= 2)
+ ) {
uint8_t lvl = cfg.ramp_floors[0];
- if (1 == (event & 0x0f)) { // first click
+ // hold: lowest floor
+ if (1 == click_num) { // 1st click
if (cfg.ramp_floors[1] < lvl) lvl = cfg.ramp_floors[1];
- } else { // 2nd click or later
- if (cfg.ramp_floors[1] > lvl) lvl = cfg.ramp_floors[1];
+ }
+ // click, hold: highest floor (or manual mem level)
+ else { // 2nd click
#ifdef USE_MANUAL_MEMORY
if (cfg.manual_memory) lvl = cfg.manual_memory;
+ else
#endif
+ if (cfg.ramp_floors[1] > lvl) lvl = cfg.ramp_floors[1];
}
- set_level(lvl);
+ off_state_set_level(lvl);
}
// button was released
- else if ((event & (B_CLICK | B_PRESS)) == (B_CLICK)) {
- set_level(0);
+ else if ((B_CLICK) == (event & (B_CLICK | B_PRESS))) {
+ off_state_set_level(0);
}
#endif // ifdef USE_MOON_DURING_LOCKOUT_MODE
diff --git a/ui/anduril/off-mode.c b/ui/anduril/off-mode.c
index 36d771c..f699c89 100644
--- a/ui/anduril/off-mode.c
+++ b/ui/anduril/off-mode.c
@@ -264,19 +264,6 @@ uint8_t off_state(Event event, uint16_t arg) {
#endif // ifndef USE_EXTENDED_SIMPLE_UI
#endif // ifdef USE_SIMPLE_UI
- // click, click, long-click: strobe mode
- #ifdef USE_STROBE_STATE
- else if (event == EV_click3_hold) {
- set_state(strobe_state, 0);
- return EVENT_HANDLED;
- }
- #elif defined(USE_BORING_STROBE_STATE)
- else if (event == EV_click3_hold) {
- set_state(boring_strobe_state, 0);
- return EVENT_HANDLED;
- }
- #endif
-
#ifdef USE_INDICATOR_LED
// 7 clicks: change indicator LED mode
else if (event == EV_7clicks) {
@@ -334,6 +321,19 @@ uint8_t off_state(Event event, uint16_t arg) {
}
#endif // ifdef USE_EXTENDED_SIMPLE_UI
+ // click, click, long-click: strobe mode
+ #ifdef USE_STROBE_STATE
+ else if (event == EV_click3_hold) {
+ set_state(strobe_state, 0);
+ return EVENT_HANDLED;
+ }
+ #elif defined(USE_BORING_STROBE_STATE)
+ else if (event == EV_click3_hold) {
+ set_state(boring_strobe_state, 0);
+ return EVENT_HANDLED;
+ }
+ #endif
+
// 10 clicks: enable simple UI
else if (event == EV_10clicks) {
blink_once();
diff --git a/ui/anduril/strobe-modes.c b/ui/anduril/strobe-modes.c
index ccc4aa0..38e4dca 100644
--- a/ui/anduril/strobe-modes.c
+++ b/ui/anduril/strobe-modes.c
@@ -13,7 +13,7 @@ uint8_t strobe_state(Event event, uint16_t arg) {
// 'st' reduces ROM size slightly
strobe_mode_te st = current_strobe_type;
- #ifdef USE_MOMENTARY_MODE
+ #if defined(USE_MOMENTARY_MODE) || defined(USE_TACTICAL_MODE)
momentary_mode = 1; // 0 = ramping, 1 = strobes
#endif
diff --git a/ui/anduril/tactical-mode.c b/ui/anduril/tactical-mode.c
index 5acd902..002f917 100644
--- a/ui/anduril/tactical-mode.c
+++ b/ui/anduril/tactical-mode.c
@@ -68,6 +68,11 @@ uint8_t tactical_state(Event event, uint16_t arg) {
return lockout_state(event, arg);
}
+ // handle 3C here to prevent changing channel modes unintentionally
+ if (event == EV_3clicks) {
+ return EVENT_HANDLED;
+ }
+
// 6 clicks: exit and turn off
else if (event == EV_6clicks) {
blink_once();