mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-07-16 23:41:40 +02:00
Add power Modeling functions to all components
This commit is contained in:
@ -1,142 +1,245 @@
|
||||
#include "MultiColorLight.h"
|
||||
|
||||
MultiColorLight::MultiColorLight():rgbLeds(ledAmount,ledPin){
|
||||
MultiColorLight::MultiColorLight()
|
||||
: rgbLeds(ledAmount, ledPin) {
|
||||
|
||||
};
|
||||
|
||||
void MultiColorLight::begin(void) {
|
||||
if (!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)) {
|
||||
ESP_LOGE(TAG, "Could not get power for MultiColorLight");
|
||||
Serial.println("Could not get power for MultiColorLight");
|
||||
}
|
||||
rgbLeds.begin();
|
||||
this->turnOffLed();
|
||||
};
|
||||
|
||||
void MultiColorLight::begin(void){
|
||||
if(!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) ){
|
||||
ESP_LOGE(TAG, "Could not get power for MultiColorLight");
|
||||
Serial.println("Could not get power for MultiColorLight");
|
||||
void MultiColorLight::setLed(uint8_t index, uint32_t color) {
|
||||
if (index > ledAmount - 1) {
|
||||
// TODO: logging
|
||||
}
|
||||
uint32_t normalizedColor = normalizeColor(color);
|
||||
float totalConsumption = modelCurrentConsumption(normalizedColor);
|
||||
switch (index) {
|
||||
case 0:
|
||||
if (!Power::waitForCurrentAllowance(
|
||||
PowerParameters::PowerConsumers::LED_RGB_TOP_RIGHT,
|
||||
totalConsumption, MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)) {
|
||||
ESP_LOGW(TAG,
|
||||
"Power to set LED RGB TOP RIGHT to color 0x%.8X not granted in "
|
||||
"time. Skipping.",
|
||||
normalizedColor);
|
||||
return;
|
||||
}
|
||||
rgbLeds.begin();
|
||||
this->turnOffLed();
|
||||
break;
|
||||
case 1:
|
||||
if (!Power::waitForCurrentAllowance(
|
||||
PowerParameters::PowerConsumers::LED_RGB_TOP_LEFT, totalConsumption,
|
||||
MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)) {
|
||||
ESP_LOGW(TAG,
|
||||
"Power to set LED RGB TOP LEFT to color 0x%.8X not granted in "
|
||||
"time. Skipping.",
|
||||
normalizedColor);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (!Power::waitForCurrentAllowance(
|
||||
PowerParameters::PowerConsumers::LED_RGB_BOTTOM, totalConsumption,
|
||||
MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)) {
|
||||
ESP_LOGW(TAG,
|
||||
"Power to set LED RGB BOTTOM to color 0x%.8X not granted in "
|
||||
"time. Skipping.",
|
||||
normalizedColor);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
rgbLeds.setPixelColor(index, normalizedColor);
|
||||
rgbLeds.show();
|
||||
};
|
||||
|
||||
|
||||
void MultiColorLight::setLed(uint8_t index , uint32_t color){
|
||||
if (index > ledAmount-1){
|
||||
//TODO: logging
|
||||
void MultiColorLight::setLed(leds leds, uint32_t color) {
|
||||
switch (leds) {
|
||||
case TOP_LEFT:
|
||||
MultiColorLight::setLed(1, color);
|
||||
break;
|
||||
case TOP_RIGHT:
|
||||
MultiColorLight::setLed(0, color);
|
||||
break;
|
||||
case BOTTOM:
|
||||
MultiColorLight::setLed(2, color);
|
||||
break;
|
||||
case TOP:
|
||||
for (int index = 0; index < 2; index++) {
|
||||
MultiColorLight::setLed(index, 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:
|
||||
if(!Power::waitForCurrentAllowance(PowerParameters::PowerConsumers::LED_RGB_TOP_RIGHT, totalConsumption, MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)){
|
||||
ESP_LOGW(TAG, "Power to set LED RGB TOP RIGHT to color %d not granted in time. Skipping.", color);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if(!Power::waitForCurrentAllowance(PowerParameters::PowerConsumers::LED_RGB_TOP_LEFT, totalConsumption, MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)){
|
||||
ESP_LOGW(TAG, "Power to set LED RGB TOP LEFT to color %d not granted in time. Skipping.", color);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if(!Power::waitForCurrentAllowance(PowerParameters::PowerConsumers::LED_RGB_BOTTOM, totalConsumption, MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)){
|
||||
ESP_LOGW(TAG, "Power to set LED RGB BOTTOM to color %d not granted in time. Skipping.", color);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case ALL:
|
||||
for (int index = 0; index < ledAmount; index++) {
|
||||
MultiColorLight::setLed(index, color);
|
||||
}
|
||||
rgbLeds.setPixelColor(index, normalizedColor);
|
||||
rgbLeds.show();
|
||||
break;
|
||||
default:
|
||||
// TODO logging
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void MultiColorLight::setLed(leds leds, uint32_t color){
|
||||
switch (leds){
|
||||
case TOP_LEFT:
|
||||
MultiColorLight::setLed(1,color);break;
|
||||
case TOP_RIGHT:
|
||||
MultiColorLight::setLed(0,color);break;
|
||||
case BOTTOM:
|
||||
MultiColorLight::setLed(2,color);break;
|
||||
case TOP:
|
||||
for (int index = 0; index<2; index++){
|
||||
MultiColorLight::setLed(index,color);
|
||||
}break;
|
||||
case ALL:
|
||||
for (int index = 0; index<ledAmount; index++){
|
||||
MultiColorLight::setLed(index,color);
|
||||
}break;
|
||||
default:
|
||||
//TODO logging
|
||||
break;
|
||||
}
|
||||
|
||||
void MultiColorLight::setLed(leds leds, uint8_t red, uint8_t green,
|
||||
uint8_t blue) {
|
||||
MultiColorLight::setLed(leds, MultiColorLight::color(red, green, blue));
|
||||
};
|
||||
|
||||
void MultiColorLight::setLed(leds leds, uint8_t red, uint8_t green, uint8_t blue){
|
||||
MultiColorLight::setLed(leds, MultiColorLight::color(red,green,blue));
|
||||
void MultiColorLight::setTopLeds(uint32_t color) {
|
||||
MultiColorLight::setLed(TOP, color);
|
||||
};
|
||||
|
||||
|
||||
void MultiColorLight::setTopLeds(uint32_t color){
|
||||
MultiColorLight::setLed(TOP,color);
|
||||
};
|
||||
|
||||
void MultiColorLight::setTopLeds(uint8_t red, uint8_t green, uint8_t blue){
|
||||
MultiColorLight::setTopLeds(MultiColorLight::color(red,green,blue));
|
||||
};
|
||||
|
||||
void MultiColorLight::blink(uint16_t amount,uint32_t color, leds leds, uint32_t interval){
|
||||
for(uint16_t index = 0; index < amount;index++){
|
||||
MultiColorLight::setLed(leds, color);
|
||||
vTaskDelay(interval);
|
||||
MultiColorLight::turnOffLed(leds);
|
||||
vTaskDelay(interval);
|
||||
}
|
||||
void MultiColorLight::setTopLeds(uint8_t red, uint8_t green, uint8_t blue) {
|
||||
MultiColorLight::setTopLeds(MultiColorLight::color(red, green, blue));
|
||||
};
|
||||
|
||||
void MultiColorLight::turnOffLed(leds leds){
|
||||
switch (leds){
|
||||
case TOP_LEFT:
|
||||
MultiColorLight::setLed(1,0);break;
|
||||
case TOP_RIGHT:
|
||||
MultiColorLight::setLed(0,0);break;
|
||||
case BOTTOM:
|
||||
MultiColorLight::setLed(2,0);break;
|
||||
case TOP:
|
||||
for (int index = 0; index<2; index++){
|
||||
MultiColorLight::setLed(index,0);
|
||||
}break;
|
||||
case ALL:
|
||||
for (int index = 0; index<3; index++){
|
||||
MultiColorLight::setLed(index,0);
|
||||
}break;
|
||||
default:
|
||||
//TODO logging
|
||||
break;
|
||||
}
|
||||
void MultiColorLight::blink(uint16_t amount, uint32_t color, leds leds,
|
||||
uint32_t interval) {
|
||||
for (uint16_t index = 0; index < amount; index++) {
|
||||
MultiColorLight::setLed(leds, color);
|
||||
vTaskDelay(interval);
|
||||
MultiColorLight::turnOffLed(leds);
|
||||
vTaskDelay(interval);
|
||||
}
|
||||
};
|
||||
|
||||
uint32_t MultiColorLight::color(uint8_t r, uint8_t g, uint8_t b){
|
||||
return rgbLeds.Color(r,g,b);
|
||||
void MultiColorLight::turnOffLed(leds leds) {
|
||||
switch (leds) {
|
||||
case TOP_LEFT:
|
||||
MultiColorLight::setLed(1, 0);
|
||||
break;
|
||||
case TOP_RIGHT:
|
||||
MultiColorLight::setLed(0, 0);
|
||||
break;
|
||||
case BOTTOM:
|
||||
MultiColorLight::setLed(2, 0);
|
||||
break;
|
||||
case TOP:
|
||||
for (int index = 0; index < 2; index++) {
|
||||
MultiColorLight::setLed(index, 0);
|
||||
}
|
||||
break;
|
||||
case ALL:
|
||||
for (int index = 0; index < 3; index++) {
|
||||
MultiColorLight::setLed(index, 0);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// TODO logging
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
//PRIVATE
|
||||
uint32_t MultiColorLight::normalizeColor(uint32_t color,uint8_t maxBrightness){
|
||||
uint8_t red = (color&0x00FF0000)>>16;
|
||||
uint8_t green = (color&0x0000FF00)>>8;
|
||||
uint8_t blue = (color&0x000000FF);
|
||||
if (red > maxBrightness){
|
||||
red = maxBrightness;
|
||||
uint32_t MultiColorLight::color(uint8_t r, uint8_t g, uint8_t b) {
|
||||
return rgbLeds.Color(r, g, b);
|
||||
};
|
||||
|
||||
// PRIVATE
|
||||
uint32_t MultiColorLight::normalizeColor(uint32_t color,
|
||||
uint8_t maxBrightness) {
|
||||
uint8_t red = (color & 0x00FF0000) >> 16;
|
||||
uint8_t green = (color & 0x0000FF00) >> 8;
|
||||
uint8_t blue = (color & 0x000000FF);
|
||||
if (red > maxBrightness) {
|
||||
red = maxBrightness;
|
||||
}
|
||||
if (green > maxBrightness - 70) {
|
||||
green = maxBrightness - 70;
|
||||
}
|
||||
if (blue > maxBrightness - 50) {
|
||||
blue = maxBrightness - 50;
|
||||
}
|
||||
return MultiColorLight::color(red, green, blue);
|
||||
};
|
||||
|
||||
float MultiColorLight::modelCurrentConsumption(uint32_t 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;
|
||||
return redChannelConsumption + greenChannelConsumption +
|
||||
blueChannelConsumption +
|
||||
PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_BASE;
|
||||
};
|
||||
|
||||
float MultiColorLight::modelCurrentConsumption(uint8_t red, uint8_t green,
|
||||
uint8_t blue) {
|
||||
return modelCurrentConsumption(MultiColorLight::color(red, green, blue));
|
||||
};
|
||||
|
||||
float MultiColorLight::modelChargeConsumption(uint8_t index, uint32_t color,
|
||||
uint16_t durationMs) {
|
||||
if (index > ledAmount - 1) {
|
||||
// TODO: logging
|
||||
}
|
||||
uint32_t normalizedColor = normalizeColor(color);
|
||||
float ledConsumption = modelCurrentConsumption(normalizedColor);
|
||||
return ledConsumption * durationMs * 10e6;
|
||||
};
|
||||
|
||||
float MultiColorLight::modelChargeConsumption(leds leds, uint32_t color,
|
||||
uint16_t durationMs) {
|
||||
float ledsConsumption = 0;
|
||||
switch (leds) {
|
||||
case TOP_LEFT:
|
||||
ledsConsumption =
|
||||
MultiColorLight::modelChargeConsumption(1, color, durationMs);
|
||||
break;
|
||||
case TOP_RIGHT:
|
||||
ledsConsumption =
|
||||
MultiColorLight::modelChargeConsumption(0, color, durationMs);
|
||||
break;
|
||||
case BOTTOM:
|
||||
ledsConsumption =
|
||||
MultiColorLight::modelChargeConsumption(2, color, durationMs);
|
||||
break;
|
||||
case TOP:
|
||||
for (int index = 0; index < 2; index++) {
|
||||
ledsConsumption +=
|
||||
MultiColorLight::modelChargeConsumption(index, color, durationMs);
|
||||
}
|
||||
if(green > maxBrightness-70){
|
||||
green = maxBrightness-70;
|
||||
break;
|
||||
case ALL:
|
||||
for (int index = 0; index < ledAmount; index++) {
|
||||
ledsConsumption +=
|
||||
MultiColorLight::modelChargeConsumption(index, color, durationMs);
|
||||
}
|
||||
if(blue > maxBrightness-50){
|
||||
blue = maxBrightness-50;
|
||||
}
|
||||
return MultiColorLight::color(red,green,blue);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// TODO logging
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
float MultiColorLight::modelChargeConsumption(leds leds, uint8_t red,
|
||||
uint8_t green, uint8_t blue,
|
||||
uint16_t durationMs) {
|
||||
return MultiColorLight::modelChargeConsumption(
|
||||
leds, MultiColorLight::color(red, green, blue), durationMs);
|
||||
};
|
@ -1,146 +1,209 @@
|
||||
/**
|
||||
* @file MultiColorLight.h
|
||||
* @author Saskia Duebener, Hans Haupt
|
||||
* @brief This component controls the ability to show multicolored light, using the RGB-LEDs
|
||||
* @brief This component controls the ability to show multicolored light, using
|
||||
* the RGB-LEDs
|
||||
* @version 0.2
|
||||
* @date 2023-11-25
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*
|
||||
*/
|
||||
#ifndef MultiColorLight_h
|
||||
#define MultiColorLight_h
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include "ColorConstants.h"
|
||||
#include "../power/Power.h"
|
||||
#include "ColorConstants.h"
|
||||
#include <Adafruit_NeoPixel.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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
*/
|
||||
enum leds{
|
||||
TOP_LEFT,
|
||||
TOP_RIGHT,
|
||||
BOTTOM,
|
||||
TOP,
|
||||
ALL
|
||||
};
|
||||
enum leds { TOP_LEFT, TOP_RIGHT, BOTTOM, TOP, ALL };
|
||||
|
||||
#define TAG "MultiColorLight"
|
||||
|
||||
class MultiColorLight{
|
||||
class MultiColorLight {
|
||||
protected:
|
||||
static const uint16_t ledAmount = 3;
|
||||
static const int16_t ledPin = 48;
|
||||
static const uint8_t maxBrightness = 150;
|
||||
Adafruit_NeoPixel rgbLeds;
|
||||
static constexpr int maximumExecutionDelayMs = 10;
|
||||
static const uint16_t ledAmount = 3;
|
||||
static const int16_t ledPin = 48;
|
||||
static const uint8_t maxBrightness = 150;
|
||||
Adafruit_NeoPixel rgbLeds;
|
||||
static constexpr int maximumExecutionDelayMs = 10;
|
||||
|
||||
public:
|
||||
|
||||
MultiColorLight();
|
||||
/**
|
||||
* @brief initialize the multicolor component
|
||||
*
|
||||
*/
|
||||
void begin(void);
|
||||
MultiColorLight();
|
||||
/**
|
||||
* @brief initialize the multicolor component
|
||||
*
|
||||
*/
|
||||
void begin(void);
|
||||
|
||||
/**
|
||||
* @brief Set the specified led to the passed color
|
||||
* @param index ranging from 0-2, 0: Right, 1: Left, 2: Bottom
|
||||
* @param color A 32-bit unsigned integer representing the color in the format
|
||||
* 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component. Each color can range between 0 to 100
|
||||
*/
|
||||
void setLed(uint8_t index , uint32_t color);
|
||||
/**
|
||||
* @brief Set the specified led to the passed color
|
||||
* @param index ranging from 0-2, 0: Right, 1: Left, 2: Bottom
|
||||
* @param color A 32-bit unsigned integer representing the color in the format
|
||||
* 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component. Each color can range
|
||||
* between 0 to 100
|
||||
*/
|
||||
void setLed(uint8_t index, uint32_t color);
|
||||
|
||||
/**
|
||||
* @brief Set the specified leds to the passed color value
|
||||
*
|
||||
* @param leds which leds should be updated
|
||||
* @param color A 32-bit unsigned integer representing the color in the format
|
||||
* 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component. Each color can range between 0 to 100
|
||||
*/
|
||||
void setLed(leds leds, uint32_t color);
|
||||
/**
|
||||
* @brief Set the specified leds to the passed color value
|
||||
*
|
||||
* @param leds which leds should be updated
|
||||
* @param color A 32-bit unsigned integer representing the color in the format
|
||||
* 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component. Each color can range
|
||||
* between 0 to 100
|
||||
*/
|
||||
void setLed(leds leds, uint32_t color);
|
||||
|
||||
/**
|
||||
* @brief Set the specified leds to the passed color value
|
||||
*
|
||||
* @param leds which leds should be updated
|
||||
* @param red brightness of red, is normalized in the function
|
||||
* @param green brightness of green, is normalized in the function
|
||||
* @param blue brightness of blue, is normalized in the function
|
||||
*/
|
||||
void setLed(leds leds, uint8_t red, uint8_t green, uint8_t blue);
|
||||
|
||||
/**
|
||||
* @brief sets the two leds on the top of the robot to the specified color
|
||||
*
|
||||
* @param color A 32-bit unsigned integer representing the color in the format
|
||||
* 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component. Each color can range between 0 to 100
|
||||
*/
|
||||
void setTopLeds(uint32_t color);
|
||||
/**
|
||||
* @brief Set the specified leds to the passed color value
|
||||
*
|
||||
* @param leds which leds should be updated
|
||||
* @param red brightness of red, is normalized in the function
|
||||
* @param green brightness of green, is normalized in the function
|
||||
* @param blue brightness of blue, is normalized in the function
|
||||
*/
|
||||
void setLed(leds leds, uint8_t red, uint8_t green, uint8_t blue);
|
||||
|
||||
/**
|
||||
* @brief sets the two leds on the top of the robot to the specified color
|
||||
*
|
||||
* @param red brightness of red, is normalized in the function
|
||||
* @param green brightness of green, is normalized in the function
|
||||
* @param blue brightness of blue, is normalized in the function
|
||||
*/
|
||||
void setTopLeds(uint8_t red, uint8_t green, uint8_t blue);
|
||||
|
||||
/**
|
||||
* @brief Let LEDs blink, returns after all blinks were executed
|
||||
*
|
||||
* @param amount how often should the leds blink
|
||||
* @param color A 32-bit unsigned integer representing the color in the format
|
||||
* 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component.
|
||||
* Each color can range between 0 to 100
|
||||
* Defaults to blue
|
||||
* @param leds which LEDs should blink, default is TOP
|
||||
* @param interval how many miliseconds the led is on, defaults to 1s
|
||||
*/
|
||||
void blink(uint16_t amount,uint32_t color = 0x00006400,leds leds=TOP, uint32_t interval=1000);
|
||||
/**
|
||||
* @brief calculates the current consumption of an LED with the given color
|
||||
*
|
||||
* @param color A 32-bit unsigned integer representing the color in the
|
||||
* format 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component.
|
||||
* @return float the current consumption in mA
|
||||
*/
|
||||
float modelCurrentConsumption(uint32_t color);
|
||||
|
||||
/**
|
||||
* @brief turn off the given leds
|
||||
*
|
||||
* @param leds which leds should be turned off, defaults to ALL
|
||||
*/
|
||||
void turnOffLed(leds leds=ALL);
|
||||
|
||||
/**
|
||||
* @brief wrapper to calulate the used colorformat from a rgb-value
|
||||
*
|
||||
* @param r red (0-100)
|
||||
* @param g green (0-100)
|
||||
* @param b blue (0-100)
|
||||
* @return A 32-bit unsigned integer representing the color in the format
|
||||
* 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component.
|
||||
*/
|
||||
uint32_t color(uint8_t r, uint8_t g, uint8_t b);
|
||||
/**
|
||||
* @brief calculates the current consumption of an LED with the given color
|
||||
* @note color is not normalized in this function
|
||||
*
|
||||
* @param red brightness of red
|
||||
* @param green brightness of green
|
||||
* @param blue brightness of blue
|
||||
* @return float the current consumption in mA
|
||||
*/
|
||||
float modelCurrentConsumption(uint8_t red, uint8_t green, uint8_t blue);
|
||||
|
||||
/**
|
||||
* @brief Estimate the energy consumption of setting the specified led to the
|
||||
* passed color
|
||||
* @param index ranging from 0-2, 0: Right, 1: Left, 2: Bottom
|
||||
* @param color A 32-bit unsigned integer representing the color in the
|
||||
* format 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component. Each color can
|
||||
* range between 0 to 100
|
||||
* @return consumed energy in coloumbs
|
||||
*/
|
||||
float modelChargeConsumption(uint8_t index, uint32_t color,
|
||||
uint16_t durationMs);
|
||||
|
||||
/**
|
||||
* @brief Estimate the energy consumption of setting the specified leds to the
|
||||
* passed color value
|
||||
*
|
||||
* @param leds which leds should be considered
|
||||
* @param color A 32-bit unsigned integer representing the color in the
|
||||
* format 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component. Each color can
|
||||
* range between 0 to 100
|
||||
* @return consumed energy in coloumbs
|
||||
*/
|
||||
float modelChargeConsumption(leds leds, uint32_t color,
|
||||
uint16_t durationMs);
|
||||
|
||||
/**
|
||||
* @brief Estimate the energy consumption of setting the specified leds to the
|
||||
* passed color value
|
||||
*
|
||||
* @param leds which leds should be considered
|
||||
* @param red brightness of red, is normalized in the function
|
||||
* @param green brightness of green, is normalized in the function
|
||||
* @param blue brightness of blue, is normalized in the function
|
||||
* @return consumed energy in coloumbs
|
||||
*/
|
||||
float modelChargeConsumption(leds leds, uint8_t red, uint8_t green,
|
||||
uint8_t blue, uint16_t durationMs);
|
||||
|
||||
/**
|
||||
* @brief sets the two leds on the top of the robot to the specified color
|
||||
*
|
||||
* @param color A 32-bit unsigned integer representing the color in the format
|
||||
* 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component. Each color can range
|
||||
* between 0 to 100
|
||||
*/
|
||||
void setTopLeds(uint32_t color);
|
||||
|
||||
/**
|
||||
* @brief sets the two leds on the top of the robot to the specified color
|
||||
*
|
||||
* @param red brightness of red, is normalized in the function
|
||||
* @param green brightness of green, is normalized in the function
|
||||
* @param blue brightness of blue, is normalized in the function
|
||||
*/
|
||||
void setTopLeds(uint8_t red, uint8_t green, uint8_t blue);
|
||||
|
||||
/**
|
||||
* @brief Let LEDs blink, returns after all blinks were executed
|
||||
*
|
||||
* @param amount how often should the leds blink
|
||||
* @param color A 32-bit unsigned integer representing the color in the format
|
||||
* 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component.
|
||||
* Each color can range between 0 to 100
|
||||
* Defaults to blue
|
||||
* @param leds which LEDs should blink, default is TOP
|
||||
* @param interval how many miliseconds the led is on, defaults to 1s
|
||||
*/
|
||||
void blink(uint16_t amount, uint32_t color = 0x00006400, leds leds = TOP,
|
||||
uint32_t interval = 1000);
|
||||
|
||||
/**
|
||||
* @brief turn off the given leds
|
||||
*
|
||||
* @param leds which leds should be turned off, defaults to ALL
|
||||
*/
|
||||
void turnOffLed(leds leds = ALL);
|
||||
|
||||
/**
|
||||
* @brief wrapper to calulate the used colorformat from a rgb-value
|
||||
*
|
||||
* @param r red (0-100)
|
||||
* @param g green (0-100)
|
||||
* @param b blue (0-100)
|
||||
* @return A 32-bit unsigned integer representing the color in the format
|
||||
* 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component.
|
||||
*/
|
||||
uint32_t color(uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief normalizes every component of color to not exeed the maxBrightness
|
||||
*
|
||||
* @param color A 32-bit unsigned integer representing the color in the format
|
||||
* 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component.
|
||||
* @param maxBrigthness maximal level of brightness that is allowed for each color
|
||||
* @return uint32_t A 32-bit unsigned integer representing the color in the format
|
||||
* 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component. Where each component can be
|
||||
* between 0 - maxBrightness
|
||||
*/
|
||||
uint32_t normalizeColor(uint32_t color, uint8_t maxBrigthness=maxBrightness);
|
||||
/**
|
||||
* @brief normalizes every component of color to not exeed the maxBrightness
|
||||
*
|
||||
* @param color A 32-bit unsigned integer representing the color in the format
|
||||
* 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component.
|
||||
* @param maxBrigthness maximal level of brightness that is allowed for each
|
||||
* color
|
||||
* @return uint32_t A 32-bit unsigned integer representing the color in the
|
||||
* format 0x00RRGGBB, where RR is the red component, GG is the green
|
||||
* component, and BB is the blue component. Where each component
|
||||
* can be between 0 - maxBrightness
|
||||
*/
|
||||
uint32_t normalizeColor(uint32_t color,
|
||||
uint8_t maxBrigthness = maxBrightness);
|
||||
};
|
||||
|
||||
#endif //MultiColorLight_h
|
||||
#endif // MultiColorLight_h
|
Reference in New Issue
Block a user