Integrate RGB LEDs into power management

This commit is contained in:
Phillip Kühne 2025-02-12 18:27:48 +01:00
parent 4bfae98f6b
commit 8a93e0ca93
Signed by: phillip
GPG Key ID: E4C1C4D2F90902AA
2 changed files with 28 additions and 1 deletions

View File

@ -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();
};

View File

@ -12,6 +12,10 @@
#define MultiColorLight_h
#include <Adafruit_NeoPixel.h>
#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();