Fix brightness control for backlight LEDs

This commit is contained in:
norbert-walter 2024-01-07 16:34:51 +01:00
parent 6e7dfc6fd9
commit 74d13df414
4 changed files with 36 additions and 34 deletions

View File

@ -77,23 +77,25 @@ void togglePortPin(uint pin){
digitalWrite(pin, !digitalRead(pin));
}
CRGB colorMapping(String colorString){
CRGB color = CRGB::Red;
if(colorString == "Red"){color = CRGB::Red;}
if(colorString == "Orange"){color = CRGB::Orange;}
if(colorString == "Yellow"){color = CRGB::Yellow;}
if(colorString == "Green"){color = CRGB::Green;}
if(colorString == "Blue"){color = CRGB::Blue;}
if(colorString == "Aqua"){color = CRGB::Aqua;}
if(colorString == "Violet"){color = CRGB::Violet;}
if(colorString == "White"){color = CRGB::White;}
// Valid colors see hue
CHSV colorMapping(String colorString){
CHSV color = CHSV(HUE_RED, 255, 255);
if(colorString == "Red"){color = CHSV(HUE_RED, 255, 255);}
if(colorString == "Orange"){color = CHSV(HUE_ORANGE, 255, 255);}
if(colorString == "Yellow"){color = CHSV(HUE_YELLOW, 255, 255);}
if(colorString == "Green"){color = CHSV(HUE_GREEN, 255, 255);}
if(colorString == "Blue"){color = CHSV(HUE_BLUE, 255, 255);}
if(colorString == "Aqua"){color = CHSV(HUE_AQUA, 255, 255);}
if(colorString == "Violet"){color = CHSV(HUE_PURPLE, 255, 255);}
if(colorString == "White"){color = CHSV(HUE_AQUA, 0, 255);}
return color;
}
// All defined colors see pixeltypes.h in FastLED lib
void setBacklightLED(uint brightness, CRGB color){
FastLED.setBrightness(brightness); // Brightness for flash LED
backlight[0] = color; // Backlight LEDs on with color
void setBacklightLED(uint brightness, CHSV color){
FastLED.setBrightness(255); // Brightness for flash LED
color.value = brightness;
backlight[0] = color; // Backlight LEDs on with color
backlight[1] = color;
backlight[2] = color;
backlight[3] = color;
@ -102,11 +104,12 @@ void setBacklightLED(uint brightness, CRGB color){
FastLED.show();
}
void toggleBacklightLED(uint brightness, CRGB color){
void toggleBacklightLED(uint brightness, CHSV color){
statusBacklightLED = !statusBacklightLED;
FastLED.setBrightness(brightness); // Brightness for flash LED
FastLED.setBrightness(255); // Brightness for flash LED
if(statusBacklightLED == true){
backlight[0] = color; // Backlight LEDs on
color.value = brightness;
backlight[0] = color; // Backlight LEDs on with color
backlight[1] = color;
backlight[2] = color;
backlight[3] = color;
@ -114,12 +117,12 @@ void toggleBacklightLED(uint brightness, CRGB color){
backlight[5] = color;
}
else{
backlight[0] = CRGB::Black; // Backlight LEDs off
backlight[1] = CRGB::Black;
backlight[2] = CRGB::Black;
backlight[3] = CRGB::Black;
backlight[4] = CRGB::Black;
backlight[5] = CRGB::Black;
backlight[0] = CHSV(HUE_BLUE, 255, 0); // Backlight LEDs off (blue without britghness)
backlight[1] = CHSV(HUE_BLUE, 255, 0);
backlight[2] = CHSV(HUE_BLUE, 255, 0);
backlight[3] = CHSV(HUE_BLUE, 255, 0);
backlight[4] = CHSV(HUE_BLUE, 255, 0);
backlight[5] = CHSV(HUE_BLUE, 255, 0);
}
FastLED.show();
}

View File

@ -31,9 +31,9 @@ void setPortPin(uint pin, bool value); // Set port pin for extension po
void togglePortPin(uint pin); // Toggle extension port pin
CRGB colorMapping(String colorString); // Color mapping string to CRGB colors
void setBacklightLED(uint brightness, CRGB color);// Set backlight LEDs
void toggleBacklightLED(uint brightness, CRGB color);// Toggle backlight LEDs
CHSV colorMapping(String colorString); // Color mapping string to CHSV colors
void setBacklightLED(uint brightness, CHSV color);// Set backlight LEDs
void toggleBacklightLED(uint brightness, CHSV color);// Toggle backlight LEDs
void setFlashLED(bool status); // Set flash LED
void blinkingFlashLED(); // Blinking function for flash LED

View File

@ -675,9 +675,9 @@
"type": "number",
"default": "50",
"check": "checkMinMax",
"min": 0,
"min": 20,
"max": 100,
"description": "Backlight brightness [0...100%]",
"description": "Backlight brightness [20...100%]",
"category": "OBP60 Display",
"capabilities": {
"obp60":"true"

View File

@ -49,16 +49,16 @@ void OBP60Init(GwApi *api){
// Settings for backlight
String backlightMode = api->getConfig()->getConfigItem(api->getConfig()->backlight,true)->asString();
api->getLogger()->logDebug(GwLog::DEBUG,"Backlight Mode is: %s", backlightMode);
String backlightColor = api->getConfig()->getConfigItem(api->getConfig()->blColor,true)->asString();
uint brightness = uint(api->getConfig()->getConfigItem(api->getConfig()->blBrightness,true)->asInt());
String backlightColor = api->getConfig()->getConfigItem(api->getConfig()->blColor,true)->asString();
if(String(backlightMode) == "On"){
setBacklightLED(brightness, CRGB::Red);
setBacklightLED(brightness, colorMapping(backlightColor));
}
if(String(backlightMode) == "Off"){
setBacklightLED(0, CRGB::Black);
setBacklightLED(0, CHSV(HUE_BLUE, 255, 0)); // Backlight LEDs off (blue without britghness)
}
if(String(backlightMode) == "Control by Key"){
setBacklightLED(0, CRGB::Black);
setBacklightLED(0, CHSV(HUE_BLUE, 255, 0)); // Backlight LEDs off (blue without britghness)
}
// Settings flash LED mode
@ -354,7 +354,7 @@ void OBP60Task(GwApi *api){
String gpsOn=api->getConfig()->getConfigItem(api->getConfig()->useGPS,true)->asString();
String tz = api->getConfig()->getConfigItem(api->getConfig()->timeZone,true)->asString();
String backlightColor = api->getConfig()->getConfigItem(api->getConfig()->blColor,true)->asString();
CRGB color = colorMapping(backlightColor);
CHSV color = colorMapping(backlightColor);
uint brightness = 2.55 * uint(api->getConfig()->getConfigItem(api->getConfig()->blBrightness,true)->asInt());
// refreshmode defined in init section
@ -371,7 +371,6 @@ void OBP60Task(GwApi *api){
LOG_DEBUG(GwLog::LOG,"obp60task: start mainloop");
// Set start page
// int pageNumber = 0;
int pageNumber = int(api->getConfig()->getConfigItem(api->getConfig()->startPage,true)->asInt()) - 1;
int lastPage=pageNumber;
@ -470,7 +469,7 @@ void OBP60Task(GwApi *api){
setBacklightLED(brightness, color);
}
else{
setBacklightLED(brightness, CRGB::Black);
setBacklightLED(0, CHSV(HUE_BLUE, 255, 0)); // Backlight LEDs off (blue without britghness)
}
}