Skip to content

Commit

Permalink
Add configurable RGB voltage aux with two vars, and moved config to
Browse files Browse the repository at this point in the history
battcheck menu compared to earlier implementation

This is a compromise between 1 var (not possible to fully configure) and
three (too many) and allows to confingure all posisbilities in the
previous implementation with 3.

Battcheck mode, 7H, items 3 and 4: 3 is threshold for RGB voltage aux to
switch to high level. 0 means "always high", and 151 "never high". In
addition, 152 disables the feature entirely (low *or* high). 4 is the
threshold below which RGB voltage aux will *always* be off, regardless
of high/low threshold setting, for lights where the aux are with the
main emitters and may interfere with moon mode.
  • Loading branch information
SiteRelEnby committed Oct 9, 2023
1 parent f135afa commit f745ed4
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 17 deletions.
5 changes: 3 additions & 2 deletions spaghetti-monster/anduril/anduril.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,9 @@ void loop() {

#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);
if ((state == steady_state) && (cfg.use_aux_rgb_leds_while_on < (RAMP_SIZE + 2)) //152+ disables feature entirely; 151 forces "always low"; 0 forces "always high"
&& (actual_level > cfg.use_aux_rgb_leds_while_on_min_level))
rgb_led_voltage_readout(actual_level > cfg.use_aux_rgb_leds_while_on);
#endif

if (0) {} // placeholder
Expand Down
16 changes: 9 additions & 7 deletions spaghetti-monster/anduril/battcheck-mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
#ifdef USE_AUX_RGB_LEDS_WHILE_ON
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;
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
}

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
Expand Down
14 changes: 14 additions & 0 deletions spaghetti-monster/anduril/battcheck-mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,17 @@ 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
#ifdef USE_AUX_RGB_LEDS_WHILE_ON
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;
6 changes: 0 additions & 6 deletions spaghetti-monster/anduril/config-default.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,3 @@
#endif
// 0 = none, 1 = smooth, 2+ = undefined
#define DEFAULT_SMOOTH_STEPS_STYLE 1

// compatibility hack: if USE_AUX_RGB_LEDS_WHILE_ON is defined but has no value, set it to something sensible
#if (!(USE_AUX_RGB_LEDS_WHILE_ON + 0)) // if USE_AUX_RGB_LEDS_WHILE_ON is an int, passes. If blank, evaluates to `(+0)` which evaluates to false.
#undef USE_AUX_RGB_LEDS_WHILE_ON
#define USE_AUX_RGB_LEDS_WHILE_ON 25
#endif
4 changes: 4 additions & 0 deletions spaghetti-monster/anduril/load-save-config-fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ typedef struct Config {
#ifdef USE_JUMP_START
uint8_t jump_start_level;
#endif
#ifdef USE_AUX_RGB_LEDS_WHILE_ON
uint8_t use_aux_rgb_leds_while_on;
uint8_t use_aux_rgb_leds_while_on_min_level;
#endif

} Config;

Expand Down
15 changes: 15 additions & 0 deletions spaghetti-monster/anduril/load-save-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,20 @@ Config cfg = {
.jump_start_level = DEFAULT_JUMP_START_LEVEL,
#endif

#ifdef USE_AUX_RGB_LEDS_WHILE_ON
// 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, 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. This will break RGB voltage aux in ramp mode. Overriding to default of 25"
.use_aux_rgb_leds_while_on = 25, // default
#endif
#ifdef USE_AUX_RGB_LEDS_WHILE_ON_DEFAULT_MINIMUM_LEVEL
.use_aux_rgb_leds_while_on_min_level = USE_AUX_RGB_LEDS_WHILE_ON_DEFAULT_MINIMUM_LEVEL,
#else
.use_aux_rgb_leds_while_on_min_level = 15, // default
#endif
#endif

};

4 changes: 2 additions & 2 deletions spaghetti-monster/fsm-ramping.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ 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) {
if (level > 0) {
rgb_led_voltage_readout(level > USE_AUX_RGB_LEDS_WHILE_ON);
if ((level > 0) && (cfg.use_aux_rgb_leds_while_on < (RAMP_SIZE + 2)) && (actual_level > cfg.use_aux_rgb_leds_while_on_min_level)){
rgb_led_voltage_readout(level > cfg.use_aux_rgb_leds_while_on);
} else {
rgb_led_set(0);
}
Expand Down

0 comments on commit f745ed4

Please sign in to comment.