Skip to content

Commit

Permalink
Fix brightness control for backlight LEDs
Browse files Browse the repository at this point in the history
  • Loading branch information
norbert-walter committed Jan 7, 2024
1 parent 6e7dfc6 commit 74d13df
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
47 changes: 25 additions & 22 deletions lib/obp60task/OBP60Extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -102,24 +104,25 @@ 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;
backlight[4] = 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();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/obp60task/OBP60Extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/obp60task/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 6 additions & 7 deletions lib/obp60task/obp60task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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)
}

}
Expand Down

0 comments on commit 74d13df

Please sign in to comment.