From d22d8405c2c04365acb30e8ee226bd7bb71b591f Mon Sep 17 00:00:00 2001 From: jpmreece Date: Mon, 23 Dec 2024 20:28:43 +0000 Subject: [PATCH] LED Dimmer (#13776) * LED Dimmer Build with EXTRA_FLAGS=-DUSE_LED_STRIP Tested on SpeedyBeeF7V3 Added adjrange to update the ledstrip_brightness variable. This allows for easy changing of LEDs without having to connect to the configurator. * Added Unit Tests, Space to Tab Added unit tests into rx_controls_unittest.cc. The LED brightness is returned as 50 for testing purposes. Changed tabs in ledstrip.c & .h and rc_adjustments.c to 4 spaces for coding standards. * Update src/main/fc/rc_adjustments.h Missed a tab in rc_adjustments.h Co-authored-by: nerdCopter <56646290+nerdCopter@users.noreply.github.com> * Update src/main/fc/rc_adjustments.c Removal of empty line Co-authored-by: nerdCopter <56646290+nerdCopter@users.noreply.github.com> * Update rc_adjustments.c Co-authored-by: Petr Ledvina * Update src/main/io/ledstrip.c * Update src/main/io/ledstrip.h * Update src/test/unit/rc_controls_unittest.cc --------- Co-authored-by: nerdCopter <56646290+nerdCopter@users.noreply.github.com> Co-authored-by: Jay Blackman Co-authored-by: Petr Ledvina Co-authored-by: Mark Haslinghuis --- src/main/fc/rc_adjustments.c | 13 +++++++++++++ src/main/fc/rc_adjustments.h | 1 + src/main/io/ledstrip.c | 12 ++++++++++++ src/main/io/ledstrip.h | 2 ++ src/test/unit/rc_controls_unittest.cc | 2 ++ 5 files changed, 30 insertions(+) diff --git a/src/main/fc/rc_adjustments.c b/src/main/fc/rc_adjustments.c index 04c96c0c2b..8e838b97be 100644 --- a/src/main/fc/rc_adjustments.c +++ b/src/main/fc/rc_adjustments.c @@ -226,6 +226,10 @@ static const adjustmentConfig_t defaultAdjustmentConfigs[ADJUSTMENT_FUNCTION_COU .adjustmentFunction = ADJUSTMENT_LED_PROFILE, .mode = ADJUSTMENT_MODE_SELECT, .data = { .switchPositions = 3 } + }, { + .adjustmentFunction = ADJUSTMENT_LED_DIMMER, + .mode = ADJUSTMENT_MODE_SELECT, + .data = { .switchPositions = 100 } } }; @@ -264,6 +268,8 @@ static const char * const adjustmentLabels[] = { "ROLL F", "YAW F", "OSD PROFILE", + "LED PROFILE", + "LED DIMMER", }; static int adjustmentRangeNameIndex = 0; @@ -641,6 +647,13 @@ static uint8_t applySelectAdjustment(adjustmentFunction_e adjustmentFunction, ui if (getLedProfile() != position) { setLedProfile(position); } +#endif + break; + case ADJUSTMENT_LED_DIMMER: +#ifdef USE_LED_STRIP + if (getLedBrightness() != position) { + setLedBrightness(position); + } #endif break; diff --git a/src/main/fc/rc_adjustments.h b/src/main/fc/rc_adjustments.h index 669205f554..57855ba24e 100644 --- a/src/main/fc/rc_adjustments.h +++ b/src/main/fc/rc_adjustments.h @@ -62,6 +62,7 @@ typedef enum { ADJUSTMENT_YAW_F, ADJUSTMENT_OSD_PROFILE, ADJUSTMENT_LED_PROFILE, + ADJUSTMENT_LED_DIMMER, ADJUSTMENT_FUNCTION_COUNT } adjustmentFunction_e; diff --git a/src/main/io/ledstrip.c b/src/main/io/ledstrip.c index 1f6ec0d45b..03dd8b4bf7 100644 --- a/src/main/io/ledstrip.c +++ b/src/main/io/ledstrip.c @@ -1588,4 +1588,16 @@ void setLedProfile(uint8_t profile) ledStripConfigMutable()->ledstrip_profile = profile; } } + +uint8_t getLedBrightness(void) +{ + return ledStripConfig()->ledstrip_brightness; +} + +void setLedBrightness(uint8_t brightness) +{ + if ( brightness <= 100 ) { + ledStripConfigMutable()->ledstrip_brightness = brightness; + } +} #endif diff --git a/src/main/io/ledstrip.h b/src/main/io/ledstrip.h index fc6d467a6c..8e6aaccf17 100644 --- a/src/main/io/ledstrip.h +++ b/src/main/io/ledstrip.h @@ -239,3 +239,5 @@ void updateRequiredOverlay(void); uint8_t getLedProfile(void); void setLedProfile(uint8_t profile); +uint8_t getLedBrightness(void); +void setLedBrightness(uint8_t brightness); diff --git a/src/test/unit/rc_controls_unittest.cc b/src/test/unit/rc_controls_unittest.cc index 7be5ff2c60..862c43119d 100644 --- a/src/test/unit/rc_controls_unittest.cc +++ b/src/test/unit/rc_controls_unittest.cc @@ -654,6 +654,8 @@ bool isTryingToArm(void) { return false; } void resetTryingToArm(void) {} void setLedProfile(uint8_t profile) { UNUSED(profile); } uint8_t getLedProfile(void) { return 0; } +uint8_t getLedBrightness(void) { return 50; } +void setLedBrightness(uint8_t brightness) { UNUSED(brightness); } void compassStartCalibration(void) {} void pinioBoxTaskControl(void) {} void schedulerIgnoreTaskExecTime(void) {}