From 8a93e0ca93683ddd8850127a617697129d792e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phillip=20K=C3=BChne?= Date: Wed, 12 Feb 2025 18:27:48 +0100 Subject: [PATCH] Integrate RGB LEDs into power management --- src/multiColorLight/MultiColorLight.cpp | 24 +++++++++++++++++++++++- src/multiColorLight/MultiColorLight.h | 5 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/multiColorLight/MultiColorLight.cpp b/src/multiColorLight/MultiColorLight.cpp index aa22a4a..c6936b1 100644 --- a/src/multiColorLight/MultiColorLight.cpp +++ b/src/multiColorLight/MultiColorLight.cpp @@ -5,6 +5,9 @@ MultiColorLight::MultiColorLight():rgbLeds(ledAmount,ledPin){ }; void MultiColorLight::begin(void){ + Power::waitForCurrentAllowance(PowerParameters::PowerConsumers::LED_RGB_TOP_LEFT, PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_BASE, MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL); + Power::waitForCurrentAllowance(PowerParameters::PowerConsumers::LED_RGB_TOP_RIGHT, PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_BASE, MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL); + Power::waitForCurrentAllowance(PowerParameters::PowerConsumers::LED_RGB_BOTTOM, PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_BASE, MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL); rgbLeds.begin(); this->turnOffLed(); }; @@ -13,7 +16,26 @@ void MultiColorLight::setLed(uint8_t index , uint32_t color){ if (index > ledAmount-1){ //TODO: logging } - rgbLeds.setPixelColor(index, normalizeColor(color)); + uint32_t normalizedColor = normalizeColor(color); + uint16_t colorComponentRed = (normalizedColor & 0x00FF0000) >> 16; + uint16_t colorComponentGreen = (normalizedColor & 0x0000FF00) >> 8; + uint16_t colorComponentBlue = (normalizedColor & 0x000000FF); + float redChannelConsumption = (colorComponentRed/255.0) * PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_CHAN_T_ON; + float greenChannelConsumption = (colorComponentGreen/255.0) * PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_CHAN_T_ON; + float blueChannelConsumption = (colorComponentBlue/255.0) * PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_CHAN_T_ON; + float totalConsumption = redChannelConsumption + greenChannelConsumption + blueChannelConsumption + PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_BASE; + switch (index) { + case 0: + Power::waitForCurrentAllowance(PowerParameters::PowerConsumers::LED_RGB_TOP_RIGHT, totalConsumption, MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL); + break; + case 1: + Power::waitForCurrentAllowance(PowerParameters::PowerConsumers::LED_RGB_TOP_LEFT, totalConsumption, MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL); + break; + case 2: + Power::waitForCurrentAllowance(PowerParameters::PowerConsumers::LED_RGB_BOTTOM, totalConsumption, MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL); + break; + } + rgbLeds.setPixelColor(index, normalizedColor); rgbLeds.show(); }; diff --git a/src/multiColorLight/MultiColorLight.h b/src/multiColorLight/MultiColorLight.h index 44498cf..0d5634e 100644 --- a/src/multiColorLight/MultiColorLight.h +++ b/src/multiColorLight/MultiColorLight.h @@ -12,6 +12,10 @@ #define MultiColorLight_h #include #include "ColorConstants.h" +#include "../power/Power.h" + +#define MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS 20 + /** * @brief Describes combinations of leds on the Dezibot. * With the Robot in Front of you, when the robot drives away from you, the left LED is TOP_LEFT @@ -31,6 +35,7 @@ protected: static const int16_t ledPin = 48; static const uint8_t maxBrightness = 150; Adafruit_NeoPixel rgbLeds; + static constexpr int maximumExecutionDelayMs = 10; public: MultiColorLight();