From 95795342274a99195282ba6a8bf5bebb36ac8d01 Mon Sep 17 00:00:00 2001 From: SiteRelEnby <125829806+SiteRelEnby@users.noreply.github.com> Date: Sun, 17 Dec 2023 14:54:44 -0600 Subject: [PATCH] Implement channel_uses_aux() (Fixes issue #29) Define when a channel needs to use aux LEDs as part of its operation, allowing that channel to block RGB voltage when on if configured. --- fsm/chan-aux.h | 7 +++++++ fsm/chan-rgbaux.h | 12 ++++++++++++ fsm/channels.h | 6 ++++++ fsm/ramping.c | 6 +++++- hw/hank/emisar-2ch/fet/hwdef.c | 16 ++++++++++------ hw/hank/emisar-2ch/hwdef.c | 15 ++++++++++----- hw/hank/emisar-d4k-3ch/hwdef.c | 24 ++++++++++++++++-------- hw/hank/noctigon-kr4/nofet/anduril.h | 2 ++ hw/hank/noctigon-kr4/nofet/hwdef.c | 4 ++-- hw/hank/noctigon-m44/hwdef.c | 15 ++++++++++----- hw/sofirn/blf-lt1-t1616/hwdef.c | 15 ++++++++++----- hw/sofirn/blf-lt1/hwdef.c | 15 ++++++++++----- hw/sofirn/lt1s-pro/hwdef.c | 15 ++++++++++----- ui/anduril/anduril.c | 7 ++++++- ui/anduril/aux-leds.c | 6 ++++++ ui/anduril/config-default.h | 2 ++ 16 files changed, 124 insertions(+), 43 deletions(-) diff --git a/fsm/chan-aux.h b/fsm/chan-aux.h index ff599b8d..a042c997 100644 --- a/fsm/chan-aux.h +++ b/fsm/chan-aux.h @@ -12,11 +12,18 @@ #define AUX_HAS_ARGS #endif +#ifdef USE_CHANNEL_USES_AUX + #define AUX_USES_AUX , .uses_aux = 0 +#else + #define AUX_USES_AUX +#endif + #define AUX_CHANNELS \ { \ .set_level = set_level_aux, \ .gradual_tick = gradual_tick_null \ AUX_HAS_ARGS \ + AUX_USES_AUX \ } void set_level_aux(uint8_t level); diff --git a/fsm/chan-rgbaux.h b/fsm/chan-rgbaux.h index 6ef5d892..bfb0f559 100644 --- a/fsm/chan-rgbaux.h +++ b/fsm/chan-rgbaux.h @@ -22,17 +22,25 @@ #else #define AUX_RGB_HAS_ARGS #endif +#ifdef USE_CHANNEL_USES_AUX + //USE_CHANNEL_USES_AUX + #define AUX_RGB_USES_AUX , .uses_aux = 1 +#else + #define AUX_RGB_USES_AUX +#endif #define RGB_AUX_CHANNELS \ { \ .set_level = set_level_auxred, \ .gradual_tick = gradual_tick_null \ AUX_RGB_HAS_ARGS \ + AUX_RGB_USES_AUX \ }, \ { \ .set_level = set_level_auxyel, \ .gradual_tick = gradual_tick_null \ AUX_RGB_HAS_ARGS \ + AUX_RGB_USES_AUX \ }, \ { \ .set_level = set_level_auxgrn, \ @@ -43,21 +51,25 @@ .set_level = set_level_auxcyn, \ .gradual_tick = gradual_tick_null \ AUX_RGB_HAS_ARGS \ + AUX_RGB_USES_AUX \ }, \ { \ .set_level = set_level_auxblu, \ .gradual_tick = gradual_tick_null \ AUX_RGB_HAS_ARGS \ + AUX_RGB_USES_AUX \ }, \ { \ .set_level = set_level_auxprp, \ .gradual_tick = gradual_tick_null \ AUX_RGB_HAS_ARGS \ + AUX_RGB_USES_AUX \ }, \ { \ .set_level = set_level_auxwht, \ .gradual_tick = gradual_tick_null \ AUX_RGB_HAS_ARGS \ + AUX_RGB_USES_AUX \ } void set_level_auxred(uint8_t level); diff --git a/fsm/channels.h b/fsm/channels.h index 218f4f57..340bba84 100644 --- a/fsm/channels.h +++ b/fsm/channels.h @@ -31,6 +31,9 @@ typedef struct Channel { bool has_args; //uint8_t arg; // is in the config struct, not here #endif + #ifdef USE_CHANNEL_USES_AUX + bool uses_aux; + #endif } Channel; Channel channels[]; // values are defined in the hwdef-*.c @@ -80,6 +83,9 @@ StatePtr channel_3H_modes[NUM_CHANNEL_MODES]; // struct member #define channel_has_args(n) (channels[n].has_args) #endif +#ifdef USE_CHANNEL_USES_AUX + #define channel_uses_aux(n) (channels[n].uses_aux) +#endif #if NUM_CHANNEL_MODES > 1 void set_channel_mode(uint8_t mode); diff --git a/fsm/ramping.c b/fsm/ramping.c index adc8acb3..86c949fa 100644 --- a/fsm/ramping.c +++ b/fsm/ramping.c @@ -40,7 +40,11 @@ inline void set_level_aux_leds(uint8_t level) { // TODO: maybe move this stuff into FSM #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 ((! go_to_standby) + #ifdef USE_CHANNEL_USES_AUX + && (!channel_uses_aux(channel_mode)) + #endif + ){ if (level > 0) { rgb_led_voltage_readout(level > USE_AUX_RGB_LEDS_WHILE_ON); } else { diff --git a/hw/hank/emisar-2ch/fet/hwdef.c b/hw/hank/emisar-2ch/fet/hwdef.c index 4309a42f..8b2545e4 100644 --- a/hw/hank/emisar-2ch/fet/hwdef.c +++ b/hw/hank/emisar-2ch/fet/hwdef.c @@ -21,32 +21,36 @@ bool gradual_tick_both(uint8_t gt); bool gradual_tick_blend(uint8_t gt); bool gradual_tick_auto(uint8_t gt); - Channel channels[] = { { // channel 1 only .set_level = set_level_ch1, .gradual_tick = gradual_tick_ch1, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // channel 2 only .set_level = set_level_ch2, .gradual_tick = gradual_tick_ch2, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // both channels, tied together (max "200%" power) .set_level = set_level_both, .gradual_tick = gradual_tick_both, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // both channels, manual blend (max "100%" power) .set_level = set_level_blend, .gradual_tick = gradual_tick_blend, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 }, { // both channels, auto blend .set_level = set_level_auto, .gradual_tick = gradual_tick_auto, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 }, RGB_AUX_CHANNELS }; diff --git a/hw/hank/emisar-2ch/hwdef.c b/hw/hank/emisar-2ch/hwdef.c index 24be5add..3171eac2 100644 --- a/hw/hank/emisar-2ch/hwdef.c +++ b/hw/hank/emisar-2ch/hwdef.c @@ -25,27 +25,32 @@ Channel channels[] = { { // channel 1 only .set_level = set_level_ch1, .gradual_tick = gradual_tick_ch1, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // channel 2 only .set_level = set_level_ch2, .gradual_tick = gradual_tick_ch2, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // both channels, tied together (max "200%" power) .set_level = set_level_both, .gradual_tick = gradual_tick_both, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // both channels, manual blend (max "100%" power) .set_level = set_level_blend, .gradual_tick = gradual_tick_blend, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 }, { // both channels, auto blend .set_level = set_level_auto, .gradual_tick = gradual_tick_auto, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 }, RGB_AUX_CHANNELS }; diff --git a/hw/hank/emisar-d4k-3ch/hwdef.c b/hw/hank/emisar-d4k-3ch/hwdef.c index ba5273d2..552040d6 100644 --- a/hw/hank/emisar-d4k-3ch/hwdef.c +++ b/hw/hank/emisar-d4k-3ch/hwdef.c @@ -31,42 +31,50 @@ Channel channels[] = { { // main 2 LEDs only .set_level = set_level_main2, .gradual_tick = gradual_tick_main2, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // 3rd LED only .set_level = set_level_led3, .gradual_tick = gradual_tick_led3, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // 4th LED only .set_level = set_level_led4, .gradual_tick = gradual_tick_led4, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // all channels, tied together (equal amounts, max power) .set_level = set_level_all, .gradual_tick = gradual_tick_all, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // 3rd + 4th LEDs, manual blend (max "100%" power) (8/16/16) .set_level = set_level_led34a_blend, .gradual_tick = gradual_tick_led34a_blend, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 }, { // 3rd + 4th LEDs, manual blend (max "100%" power) (16/16/8) .set_level = set_level_led34b_blend, .gradual_tick = gradual_tick_led34b_blend, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 }, { // 3ch blend (HSV style) .set_level = set_level_hsv, .gradual_tick = gradual_tick_hsv, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 }, { // 3ch auto blend (red-warm-cool style, led4-led3-main2) .set_level = set_level_auto3, .gradual_tick = gradual_tick_auto3, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, RGB_AUX_CHANNELS }; diff --git a/hw/hank/noctigon-kr4/nofet/anduril.h b/hw/hank/noctigon-kr4/nofet/anduril.h index ad3f0125..d5257a04 100644 --- a/hw/hank/noctigon-kr4/nofet/anduril.h +++ b/hw/hank/noctigon-kr4/nofet/anduril.h @@ -8,6 +8,8 @@ #define HWDEF_C hank/noctigon-kr4/nofet/hwdef.c #include "hank/noctigon-kr4/anduril.h" +#define USE_AUX_RGB_LEDS_WHILE_ON 1 + // brightness w/ SST-20 4000K LEDs: // 0/1023: 0.35 lm // 1/1023: 2.56 lm diff --git a/hw/hank/noctigon-kr4/nofet/hwdef.c b/hw/hank/noctigon-kr4/nofet/hwdef.c index 783eeedb..e228a6a3 100644 --- a/hw/hank/noctigon-kr4/nofet/hwdef.c +++ b/hw/hank/noctigon-kr4/nofet/hwdef.c @@ -11,11 +11,11 @@ void set_level_zero(); void set_level_main(uint8_t level); bool gradual_tick_main(uint8_t gt); - Channel channels[] = { { // channel 1 only .set_level = set_level_main, - .gradual_tick = gradual_tick_main + .gradual_tick = gradual_tick_main, + .uses_aux = 0 }, RGB_AUX_CHANNELS }; diff --git a/hw/hank/noctigon-m44/hwdef.c b/hw/hank/noctigon-m44/hwdef.c index c7e1435b..0593aabb 100644 --- a/hw/hank/noctigon-m44/hwdef.c +++ b/hw/hank/noctigon-m44/hwdef.c @@ -25,27 +25,32 @@ Channel channels[] = { { // channel 1 only .set_level = set_level_ch1, .gradual_tick = gradual_tick_ch1, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // channel 2 only .set_level = set_level_ch2, .gradual_tick = gradual_tick_ch2, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // both channels, tied together (max "200%" power) .set_level = set_level_both, .gradual_tick = gradual_tick_both, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // both channels, manual blend (max "100%" power) .set_level = set_level_blend, .gradual_tick = gradual_tick_blend, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 }, { // both channels, auto blend .set_level = set_level_auto, .gradual_tick = gradual_tick_auto, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 }, RGB_AUX_CHANNELS }; diff --git a/hw/sofirn/blf-lt1-t1616/hwdef.c b/hw/sofirn/blf-lt1-t1616/hwdef.c index 5a838496..d290c6c7 100644 --- a/hw/sofirn/blf-lt1-t1616/hwdef.c +++ b/hw/sofirn/blf-lt1-t1616/hwdef.c @@ -25,27 +25,32 @@ Channel channels[] = { { // channel 1 only .set_level = set_level_ch1, .gradual_tick = gradual_tick_ch1, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // channel 2 only .set_level = set_level_ch2, .gradual_tick = gradual_tick_ch2, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // both channels, tied together (max "200%" power) .set_level = set_level_both, .gradual_tick = gradual_tick_both, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // both channels, manual blend (max "100%" power) .set_level = set_level_blend, .gradual_tick = gradual_tick_blend, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 }, { // both channels, auto blend .set_level = set_level_auto, .gradual_tick = gradual_tick_auto, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 }, AUX_CHANNELS }; diff --git a/hw/sofirn/blf-lt1/hwdef.c b/hw/sofirn/blf-lt1/hwdef.c index 8a4c0e19..9aaaad37 100644 --- a/hw/sofirn/blf-lt1/hwdef.c +++ b/hw/sofirn/blf-lt1/hwdef.c @@ -25,27 +25,32 @@ Channel channels[] = { { // channel 1 only .set_level = set_level_ch1, //.gradual_tick = gradual_tick_ch1, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // channel 2 only .set_level = set_level_ch2, //.gradual_tick = gradual_tick_ch2, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // both channels, tied together (max "200%" power) .set_level = set_level_both, //.gradual_tick = gradual_tick_both, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // both channels, manual blend (max "100%" power) .set_level = set_level_blend, //.gradual_tick = gradual_tick_blend, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 }, { // both channels, auto blend .set_level = set_level_blend, //.gradual_tick = gradual_tick_blend, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 }, }; diff --git a/hw/sofirn/lt1s-pro/hwdef.c b/hw/sofirn/lt1s-pro/hwdef.c index 90c2c075..ac797589 100644 --- a/hw/sofirn/lt1s-pro/hwdef.c +++ b/hw/sofirn/lt1s-pro/hwdef.c @@ -23,27 +23,32 @@ Channel channels[] = { { // manual blend of warm and cool white .set_level = set_level_white_blend, .gradual_tick = gradual_tick_white_blend, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 }, { // auto blend from warm white to cool white .set_level = set_level_auto_2ch_blend, .gradual_tick = gradual_tick_auto_2ch_blend, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // auto blend from red to warm white to cool white .set_level = set_level_auto_3ch_blend, .gradual_tick = gradual_tick_auto_3ch_blend, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // red only .set_level = set_level_red, .gradual_tick = gradual_tick_red, - .has_args = 0 + .has_args = 0, + .uses_aux = 0 }, { // manual white blend + adjustable red .set_level = set_level_red_white_blend, .gradual_tick = gradual_tick_red_white_blend, - .has_args = 1 + .has_args = 1, + .uses_aux = 0 } }; diff --git a/ui/anduril/anduril.c b/ui/anduril/anduril.c index 1cdb8d00..12e1042f 100644 --- a/ui/anduril/anduril.c +++ b/ui/anduril/anduril.c @@ -279,8 +279,13 @@ void loop() { #ifdef USE_AUX_RGB_LEDS_WHILE_ON // display battery charge on RGB button during use - if (state == steady_state) + if ((state == steady_state) + #ifdef USE_CHANNEL_USES_AUX + && (!channel_uses_aux(channel_mode)) + #endif + ){ rgb_led_voltage_readout(actual_level > USE_AUX_RGB_LEDS_WHILE_ON); + } #endif if (0) {} // placeholder diff --git a/ui/anduril/aux-leds.c b/ui/anduril/aux-leds.c index fd184fc3..7a46eeae 100644 --- a/ui/anduril/aux-leds.c +++ b/ui/anduril/aux-leds.c @@ -202,9 +202,15 @@ void rgb_led_update(uint8_t mode, uint16_t arg) { } void rgb_led_voltage_readout(uint8_t bright) { + #ifdef USE_CHANNEL_USES_AUX + if (!channel_uses_aux(channel_mode)){ + #endif uint8_t color = voltage_to_rgb(); if (bright) color = color << 1; rgb_led_set(color); + #ifdef USE_CHANNEL_USES_AUX + } + #endif } #endif diff --git a/ui/anduril/config-default.h b/ui/anduril/config-default.h index 1b34e8c0..98751e38 100644 --- a/ui/anduril/config-default.h +++ b/ui/anduril/config-default.h @@ -215,3 +215,5 @@ // (but allow disabling this feature per build) #define USE_CHANNEL_PER_STROBE +// enable channel mode config prerequisites for channel_uses_aux() +#define USE_CHANNEL_USES_AUX