Skip to content

Commit

Permalink
Merge pull request #124 from thooge/colors
Browse files Browse the repository at this point in the history
Refactor color detection and usage
  • Loading branch information
norbert-walter authored Dec 17, 2024
2 parents c374e9e + 2659fb9 commit 6135c41
Show file tree
Hide file tree
Showing 24 changed files with 224 additions and 651 deletions.
22 changes: 4 additions & 18 deletions lib/obp60task/OBP60QRWiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,7 @@
#include "OBP60Extensions.h"
#include "qrcode.h"

void qrWiFi(String ssid, String passwd, String displaycolor){
// Set display color
int textcolor = GxEPD_BLACK;
int pixelcolor = GxEPD_BLACK;
int bgcolor = GxEPD_WHITE;
if(displaycolor == "Normal"){
textcolor = GxEPD_BLACK;
pixelcolor = GxEPD_BLACK;
bgcolor = GxEPD_WHITE;
}
else{
textcolor = GxEPD_WHITE;
pixelcolor = GxEPD_WHITE;
bgcolor = GxEPD_BLACK;
}
void qrWiFi(String ssid, String passwd, uint16_t fgcolor, uint16_t bgcolor){

// Set start point and pixel size
int16_t box_x = 100; // X offset
Expand All @@ -40,7 +26,7 @@ void qrWiFi(String ssid, String passwd, String displaycolor){
// Each horizontal module
for (uint8_t x = 0; x < qrcode.size; x++) {
if(qrcode_getModule(&qrcode, x, y)){
getdisplay().fillRect(box_x, box_y, box_s, box_s, pixelcolor);
getdisplay().fillRect(box_x, box_y, box_s, box_s, fgcolor);
} else {
getdisplay().fillRect(box_x, box_y, box_s, box_s, bgcolor);
}
Expand All @@ -50,10 +36,10 @@ void qrWiFi(String ssid, String passwd, String displaycolor){
box_x = init_x;
}
getdisplay().setFont(&Ubuntu_Bold32pt7b);
getdisplay().setTextColor(textcolor);
getdisplay().setTextColor(fgcolor);
getdisplay().setCursor(140, 285);
getdisplay().print("WiFi");
getdisplay().nextPage(); // Full Refresh
}

#endif
#endif
28 changes: 6 additions & 22 deletions lib/obp60task/PageApparentWind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ int16_t lp = 80; // Pointer length
// Get config data
String lengthformat = config->getString(config->lengthFormat);
// bool simulation = config->getBool(config->useSimuData);
String displaycolor = config->getString(config->displaycolor);
bool holdvalues = config->getBool(config->holdvalues);
String flashLED = config->getString(config->flashLED);
String backlightMode = config->getString(config->backlight);
Expand Down Expand Up @@ -90,25 +89,12 @@ int16_t lp = 80; // Pointer length
// Draw page
//***********************************************************

// Set background color and text color
int textcolor = GxEPD_BLACK;
int pixelcolor = GxEPD_BLACK;
int bgcolor = GxEPD_WHITE;
if(displaycolor == "Normal"){
textcolor = GxEPD_BLACK;
pixelcolor = GxEPD_BLACK;
bgcolor = GxEPD_WHITE;
}
else{
textcolor = GxEPD_WHITE;
pixelcolor = GxEPD_WHITE;
bgcolor = GxEPD_BLACK;
}
// Set display in partial refresh mode
getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update

getdisplay().setTextColor(commonData.fgcolor);

// Show values AWS
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold20pt7b);
getdisplay().setCursor(20, 50);
if(holdvalues == false){
Expand All @@ -127,7 +113,6 @@ int16_t lp = 80; // Pointer length
}

// Show values AWD
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold20pt7b);
getdisplay().setCursor(20, 260);
if(holdvalues == false){
Expand All @@ -154,19 +139,18 @@ int16_t lp = 80; // Pointer length
static int16_t y2 = y0;

//Draw instrument
getdisplay().fillCircle(x0, y0, lp + 5, pixelcolor); // Black circle
getdisplay().fillCircle(x0, y0, lp + 1, bgcolor); // White circle
getdisplay().fillCircle(x0, y0, lp + 5, commonData.fgcolor);
getdisplay().fillCircle(x0, y0, lp + 1, commonData.bgcolor);

// Calculation end point of pointer
value2 = value2 - 3.14 / 2;
x1 = x0 + cos(value2) * lp * 0.6;
y1 = y0 + sin(value2) * lp * 0.6;
x2 = x0 + cos(value2) * lp;
y2 = y0 + sin(value2) * lp;
getdisplay().drawLine(x1, y1, x2, y2, pixelcolor);
getdisplay().drawLine(x1, y1, x2, y2, commonData.fgcolor);

// Key Layout
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold8pt7b);
if(keylock == false){
getdisplay().setCursor(130, 290);
Expand Down Expand Up @@ -205,4 +189,4 @@ PageDescription registerPageApparentWind(
true // Show display header on/off
);

#endif
#endif
28 changes: 4 additions & 24 deletions lib/obp60task/PageBME280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class PageBME280 : public Page
// Get config data
String tempformat = config->getString(config->tempFormat);
bool simulation = config->getBool(config->useSimuData);
String displaycolor = config->getString(config->displaycolor);
String flashLED = config->getString(config->flashLED);
String backlightMode = config->getString(config->backlight);
String useenvsensor = config->getString(config->useEnvSensor);
Expand Down Expand Up @@ -105,33 +104,19 @@ class PageBME280 : public Page
// Draw page
//***********************************************************

// Set background color and text color
int textcolor = GxEPD_BLACK;
int pixelcolor = GxEPD_BLACK;
int bgcolor = GxEPD_WHITE;
if(displaycolor == "Normal"){
textcolor = GxEPD_BLACK;
pixelcolor = GxEPD_BLACK;
bgcolor = GxEPD_WHITE;
}
else{
textcolor = GxEPD_WHITE;
pixelcolor = GxEPD_WHITE;
bgcolor = GxEPD_BLACK;
}
// Set display in partial refresh mode
getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update

getdisplay().setTextColor(commonData.fgcolor);

// ############### Value 1 ################

// Show name
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold20pt7b);
getdisplay().setCursor(20, 55);
getdisplay().print(name1); // Page name

// Show unit
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold12pt7b);
getdisplay().setCursor(20, 90);
getdisplay().print(unit1); // Unit
Expand All @@ -146,18 +131,16 @@ class PageBME280 : public Page
// ############### Horizontal Line ################

// Horizontal line 3 pix
getdisplay().fillRect(0, 105, 400, 3, pixelcolor);
getdisplay().fillRect(0, 105, 400, 3, commonData.fgcolor);

// ############### Value 2 ################

// Show name
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold20pt7b);
getdisplay().setCursor(20, 145);
getdisplay().print(name2); // Page name

// Show unit
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold12pt7b);
getdisplay().setCursor(20, 180);
getdisplay().print(unit2); // Unit
Expand All @@ -172,18 +155,16 @@ class PageBME280 : public Page
// ############### Horizontal Line ################

// Horizontal line 3 pix
getdisplay().fillRect(0, 195, 400, 3, pixelcolor);
getdisplay().fillRect(0, 195, 400, 3, commonData.fgcolor);

// ############### Value 3 ################

// Show name
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold20pt7b);
getdisplay().setCursor(20, 235);
getdisplay().print(name3); // Page name

// Show unit
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold12pt7b);
getdisplay().setCursor(20, 270);
getdisplay().print(unit3); // Unit
Expand All @@ -198,7 +179,6 @@ class PageBME280 : public Page
// ############### Key Layout ################

// Key Layout
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold8pt7b);
if(keylock == false){
getdisplay().setCursor(130, 290);
Expand Down
28 changes: 3 additions & 25 deletions lib/obp60task/PageBattery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class PageBattery : public Page
// Get config data
String lengthformat = config->getString(config->lengthFormat);
// bool simulation = config->getBool(config->useSimuData);
String displaycolor = config->getString(config->displaycolor);
String flashLED = config->getString(config->flashLED);
String backlightMode = config->getString(config->backlight);
String powsensor1 = config->getString(config->usePowSensor1);
Expand Down Expand Up @@ -153,25 +152,11 @@ class PageBattery : public Page
// Draw page
//***********************************************************

// Set background color and text color
int textcolor = GxEPD_BLACK;
int pixelcolor = GxEPD_BLACK;
int bgcolor = GxEPD_WHITE;
if(displaycolor == "Normal"){
textcolor = GxEPD_BLACK;
pixelcolor = GxEPD_BLACK;
bgcolor = GxEPD_WHITE;
}
else{
textcolor = GxEPD_WHITE;
pixelcolor = GxEPD_WHITE;
bgcolor = GxEPD_BLACK;
}
// Set display in partial refresh mode
getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update

// Show average settings
getdisplay().setTextColor(textcolor);
getdisplay().setTextColor(commonData.fgcolor);
getdisplay().setFont(&Ubuntu_Bold8pt7b);
switch (average) {
case 0:
Expand Down Expand Up @@ -219,13 +204,11 @@ class PageBattery : public Page
// ############### Value 1 ################

// Show name
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold20pt7b);
getdisplay().setCursor(20, 55);
getdisplay().print(name1); // Value name

// Show unit
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold12pt7b);
getdisplay().setCursor(20, 90);
getdisplay().print(unit1); // Unit
Expand All @@ -245,18 +228,16 @@ class PageBattery : public Page
// ############### Horizontal Line ################

// Horizontal line 3 pix
getdisplay().fillRect(0, 105, 400, 3, pixelcolor);
getdisplay().fillRect(0, 105, 400, 3, commonData.fgcolor);

// ############### Value 2 ################

// Show name
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold20pt7b);
getdisplay().setCursor(20, 145);
getdisplay().print(name2); // Value name

// Show unit
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold12pt7b);
getdisplay().setCursor(20, 180);
getdisplay().print(unit2); // Unit
Expand All @@ -276,18 +257,16 @@ class PageBattery : public Page
// ############### Horizontal Line ################

// Horizontal line 3 pix
getdisplay().fillRect(0, 195, 400, 3, pixelcolor);
getdisplay().fillRect(0, 195, 400, 3, commonData.fgcolor);

// ############### Value 3 ################

// Show name
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold20pt7b);
getdisplay().setCursor(20, 235);
getdisplay().print(name3); // Value name

// Show unit
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold12pt7b);
getdisplay().setCursor(20, 270);
getdisplay().print(unit3); // Unit
Expand All @@ -308,7 +287,6 @@ class PageBattery : public Page
// ############### Key Layout ################

// Key Layout
getdisplay().setTextColor(textcolor);
getdisplay().setFont(&Ubuntu_Bold8pt7b);
if(keylock == false){
getdisplay().setCursor(10, 290);
Expand Down
Loading

0 comments on commit 6135c41

Please sign in to comment.