From 27a00e9913585f02b490be2b0da6a48f6c514f42 Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Wed, 16 Feb 2022 22:06:36 +0100 Subject: [PATCH] Display refresh an display color working --- lib/obp60task/OBP60ExtensionPort.cpp | 1 + lib/obp60task/OBP60ExtensionPort.h | 23 ++-- lib/obp60task/OBP60QRWiFi.h | 30 +++-- lib/obp60task/PageOneValue.cpp | 31 +++-- lib/obp60task/config.json | 15 +++ lib/obp60task/obp60task.cpp | 182 +++++++++++++++++---------- 6 files changed, 187 insertions(+), 95 deletions(-) diff --git a/lib/obp60task/OBP60ExtensionPort.cpp b/lib/obp60task/OBP60ExtensionPort.cpp index 4d57a39..185f3e8 100644 --- a/lib/obp60task/OBP60ExtensionPort.cpp +++ b/lib/obp60task/OBP60ExtensionPort.cpp @@ -2,6 +2,7 @@ #include "OBP60Hardware.h" #include "OBP60ExtensionPort.h" +// Please dont forget to declarate the fonts in OBP60ExtensionPort.h #include "Ubuntu_Bold8pt7b.h" #include "Ubuntu_Bold20pt7b.h" #include "Ubuntu_Bold32pt7b.h" diff --git a/lib/obp60task/OBP60ExtensionPort.h b/lib/obp60task/OBP60ExtensionPort.h index 720ef8a..52d6733 100644 --- a/lib/obp60task/OBP60ExtensionPort.h +++ b/lib/obp60task/OBP60ExtensionPort.h @@ -8,10 +8,13 @@ #include // GxEPD lip for SPI display communikation #include // GxEPD lip for SPI +// Extension port void MCP23017Init(); -// SPI pin definitions for E-Ink display -extern GxEPD_Class display; +// E-Ink display +extern GxEPD_Class display; // E-Ink display functions + +// Fonts declarations for display extern const GFXfont Ubuntu_Bold8pt7b; extern const GFXfont Ubuntu_Bold20pt7b; extern const GFXfont Ubuntu_Bold32pt7b; @@ -19,17 +22,17 @@ extern const GFXfont DSEG7Classic_BoldItalic16pt7b; extern const GFXfont DSEG7Classic_BoldItalic42pt7b; extern const GFXfont DSEG7Classic_BoldItalic60pt7b; -void setPortPin(uint pin, bool value); +// Gloabl functions +void setPortPin(uint pin, bool value); // Set port pin for extension port -void togglePortPin(uint pin); +void togglePortPin(uint pin); // Toggle extension port pin -void blinkingFlashLED(); +void blinkingFlashLED(); // Blinking function for LED on extension port +void setBlinkingLED(bool on); // Set blinking LED active -void buzzer(uint frequency, uint duration); -void setBuzzerPower(uint power); +void buzzer(uint frequency, uint duration); // Buzzer function +void setBuzzerPower(uint power); // Set buzzer power -void underVoltageDetection(); - -void setBlinkingLED(bool on); +void underVoltageDetection(); // Function for 12V undervoltage detection #endif \ No newline at end of file diff --git a/lib/obp60task/OBP60QRWiFi.h b/lib/obp60task/OBP60QRWiFi.h index a5d8330..b735769 100644 --- a/lib/obp60task/OBP60QRWiFi.h +++ b/lib/obp60task/OBP60QRWiFi.h @@ -4,7 +4,22 @@ #include #include "qrcode.h" -void qrWiFi(String ssid, String passwd, bool refreshmode){ +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; + } + // Set start point and pixel size int16_t box_x = 100; // X offset int16_t box_y = 30; // Y offset @@ -24,9 +39,9 @@ void qrWiFi(String ssid, String passwd, bool refreshmode){ // Each horizontal module for (uint8_t x = 0; x < qrcode.size; x++) { if(qrcode_getModule(&qrcode, x, y)){ - display.fillRect(box_x, box_y, box_s, box_s, GxEPD_BLACK); + display.fillRect(box_x, box_y, box_s, box_s, pixelcolor); } else { - display.fillRect(box_x, box_y, box_s, box_s, GxEPD_WHITE); + display.fillRect(box_x, box_y, box_s, box_s, bgcolor); } box_x = box_x + box_s; } @@ -34,15 +49,10 @@ void qrWiFi(String ssid, String passwd, bool refreshmode){ box_x = init_x; } display.setFont(&Ubuntu_Bold32pt7b); - display.setTextColor(GxEPD_BLACK); + display.setTextColor(textcolor); display.setCursor(140, 285); display.print("WiFi"); - if(refreshmode == true){ - display.update(); // Full update (slow) - } - else{ - display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Partial update (fast) - } + display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Partial update (fast) } #endif \ No newline at end of file diff --git a/lib/obp60task/PageOneValue.cpp b/lib/obp60task/PageOneValue.cpp index dd719d7..87a89a8 100644 --- a/lib/obp60task/PageOneValue.cpp +++ b/lib/obp60task/PageOneValue.cpp @@ -6,10 +6,11 @@ class PageOneValue : public Page{ virtual void displayPage(CommonData &commonData, PageData &pageData){ GwConfigHandler *config = commonData.config; GwLog *logger=commonData.logger; - + // 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); // Get boat values @@ -21,17 +22,30 @@ class PageOneValue : public Page{ // Logging boat values if (value == NULL) return; - LOG_DEBUG(GwLog::LOG,"drawing at PageOneValue, p=%s, v=%f", name1, value1); + LOG_DEBUG(GwLog::LOG,"Drawing at PageOneValue, p=%s, v=%f", name1, value1); // Draw page //*********************************************************** - // Clear display - display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE); // Draw white sreen + // Clear display, 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; + } + display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, bgcolor); // Draw white sreen + display.setTextColor(textcolor); // Show name display.setFont(&Ubuntu_Bold32pt7b); - display.setTextColor(GxEPD_BLACK); display.setCursor(20, 100); display.print(name1); // Page name display.setFont(&Ubuntu_Bold20pt7b); @@ -77,11 +91,8 @@ class PageOneValue : public Page{ // Key Layout display.setFont(&Ubuntu_Bold8pt7b); - display.setTextColor(GxEPD_BLACK); - display.setCursor(0, 290); - display.print(" [ < ]"); - display.setCursor(290, 290); - display.print("[ > ]"); + display.setCursor(115, 290); + display.print(" [ <<<<<< >>>>>> ]"); display.setCursor(343, 290); display.print("[ILUM]"); diff --git a/lib/obp60task/config.json b/lib/obp60task/config.json index 5f68356..736a91f 100644 --- a/lib/obp60task/config.json +++ b/lib/obp60task/config.json @@ -324,6 +324,21 @@ "obp60":"true" } }, + { + "name": "displaycolor", + "label": "Display Color", + "type": "list", + "default": "Normal", + "description": "If display color inverse then is background black and all other white", + "list": [ + "Normal", + "Inverse" + ], + "category": "OBP60 Display", + "capabilities": { + "obp60":"true" + } + }, { "name": "statusLine", "label": "Status Line", diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index 99b2971..8d58d0b 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -13,8 +13,8 @@ #include "OBP60ExtensionPort.h" // Functions lib for extension board #include "OBP60Keypad.h" // Functions for keypad -// True type character sets -// See OBP60ExtensionPort.h +// True type character sets includes +// See OBP60ExtensionPort.cpp // Pictures //#include GxEPD_BitmapExamples // Example picture @@ -258,27 +258,50 @@ void OBP60Task(GwApi *api){ } // Init E-Ink display + String displaymode = api->getConfig()->getConfigItem(api->getConfig()->display,true)->asString(); + String displaycolor = api->getConfig()->getConfigItem(api->getConfig()->displaycolor,true)->asString(); + String systemname = api->getConfig()->getConfigItem(api->getConfig()->systemName,true)->asString(); + String wifipass = api->getConfig()->getConfigItem(api->getConfig()->apPassword,true)->asString(); + bool refreshmode = api->getConfig()->getConfigItem(api->getConfig()->refresh,true)->asBoolean(); + int textcolor = GxEPD_BLACK; + int pixelcolor = GxEPD_BLACK; + int bgcolor = GxEPD_WHITE; + display.init(); // Initialize and clear display - display.setTextColor(GxEPD_BLACK); // Set display color display.setRotation(0); // Set display orientation (horizontal) - display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE); // Draw white sreen + if(displaycolor == "Normal"){ + textcolor = GxEPD_BLACK; + pixelcolor = GxEPD_BLACK; + bgcolor = GxEPD_WHITE; + } + else{ + textcolor = GxEPD_WHITE; + pixelcolor = GxEPD_WHITE; + bgcolor = GxEPD_BLACK; + } + display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, bgcolor); // Draw white sreen + display.setTextColor(textcolor); // Set display color display.update(); // Full update (slow) - String displaymode = api->getConfig()->getConfigItem(api->getConfig()->display,true)->asString(); if(String(displaymode) == "Logo + QR Code" || String(displaymode) == "Logo"){ - display.drawExampleBitmap(gImage_Logo_OBP_400x300_sw, 0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE); // Draw start logo -// display.drawExampleBitmap(gImage_MFD_OBP60_400x300_sw, 0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE); // Draw start logo + display.drawBitmap(gImage_Logo_OBP_400x300_sw, 0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, pixelcolor); // Draw start logo display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Partial update (fast) delay(SHOW_TIME); // Logo show time - display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE); // Draw white sreen - display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Partial update (fast) + display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, bgcolor); // Draw white sreen + if(refreshmode == true){ + display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, bgcolor); // Draw white sreen + display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Needs partial update before full update to refresh the frame buffer + display.update(); // Full update + } + else{ + display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Partial update (fast) + } if(String(displaymode) == "Logo + QR Code"){ - String systemname = api->getConfig()->getConfigItem(api->getConfig()->systemName,true)->asString(); - String wifipass = api->getConfig()->getConfigItem(api->getConfig()->apPassword,true)->asString(); - bool refreshmode = api->getConfig()->getConfigItem(api->getConfig()->refresh,true)->asBoolean(); - qrWiFi(systemname, wifipass, refreshmode); // Show QR code for WiFi connection - delay(SHOW_TIME); // Logo show time - display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE); // Draw white sreen + qrWiFi(systemname, wifipass, displaycolor); // Show QR code for WiFi connection + delay(SHOW_TIME); // Logo show time + display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, bgcolor); // Draw white sreen + display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Needs partial update before full update to refresh the frame buffer + display.update(); // Full update } } @@ -344,63 +367,92 @@ void OBP60Task(GwApi *api){ LOG_DEBUG(GwLog::LOG,"obp60task: start mainloop"); int pageNumber=0; int lastPage=pageNumber; + long starttime0 = millis(); // Mainloop + long starttime1 = millis(); // Full disolay refresh while (true){ - delay(1000); - //check if there is a keyboard message - int keyboardMessage=0; - if (xQueueReceive(allParameters.queue,&keyboardMessage,0)){ - LOG_DEBUG(GwLog::LOG,"new key from keyboard %d",keyboardMessage); - + if(millis() > starttime0 + 100){ + starttime0 = millis(); + //check if there is a keyboard message + int keyboardMessage=0; + while (xQueueReceive(allParameters.queue,&keyboardMessage,0)){ + LOG_DEBUG(GwLog::LOG,"new key from keyboard %d",keyboardMessage); + + Page *currentPage=pages[pageNumber].page; + if (currentPage ){ + keyboardMessage=currentPage->handleKey(keyboardMessage); + } + if (keyboardMessage > 0) + { + // Decoding all key codes + // #6 Backlight on if key controled + String backlight = api->getConfig()->getConfigItem(api->getConfig()->backlight,true)->asString(); + if(String(backlight) == "Control by Key"){ + if(keyboardMessage == 6){ + LOG_DEBUG(GwLog::LOG,"Toggle Backlight LED"); + togglePortPin(OBP_BACKLIGHT_LED); + } + } + // #9 Swipe right + if (keyboardMessage == 9) + { + pageNumber++; + if (pageNumber >= numPages) + pageNumber = 0; + } + // #10 Swipe left + if (keyboardMessage == 10) + { + pageNumber--; + if (pageNumber < 0) + pageNumber = numPages - 1; + } + // #9 or #10 Refresh display befor start a new page if reshresh is enabled + bool refreshmode = api->getConfig()->getConfigItem(api->getConfig()->refresh,true)->asBoolean(); + if(refreshmode == true && (keyboardMessage == 9 || keyboardMessage == 10)){ + display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE); // Draw white sreen + display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Needs partial update before full update to refresh the frame buffer + display.update(); // Full update + } + } + LOG_DEBUG(GwLog::LOG,"set pagenumber to %d",pageNumber); + } + + // Subtask E-Ink full refresh + if(millis() > starttime1 + FULL_REFRESH_TIME * 1000){ + LOG_DEBUG(GwLog::DEBUG,"E-Ink full refresh"); + display.update(); // Full update + starttime1 = millis(); + } + + //refresh data from api + api->getBoatDataValues(boatValues.numValues,boatValues.allBoatValues); + api->getStatus(commonData.status); + + //handle the pag + if (pages[pageNumber].description && pages[pageNumber].description->header){ + + //build some header and footer using commonData + + + } + //.... + //call the particular page Page *currentPage=pages[pageNumber].page; - if (currentPage ){ - keyboardMessage=currentPage->handleKey(keyboardMessage); + if (currentPage == NULL){ + LOG_DEBUG(GwLog::ERROR,"page number %d not found",pageNumber); + // Error handling for missing page } - if (keyboardMessage > 0) - { - // Decoding all key codes - if (keyboardMessage == 9) - { - pageNumber++; - if (pageNumber >= numPages) - pageNumber = 0; - } - if (keyboardMessage == 10) - { - pageNumber--; - if (pageNumber < 0) - pageNumber = numPages - 1; + else{ + if (lastPage != pageNumber){ + currentPage->displayNew(commonData,pages[pageNumber].parameters); + lastPage=pageNumber; } + //call the page code + LOG_DEBUG(GwLog::DEBUG,"calling page %d",pageNumber); + currentPage->displayPage(commonData,pages[pageNumber].parameters); } - LOG_DEBUG(GwLog::LOG,"set pagenumber to %d",pageNumber); - } - //refresh data from api - api->getBoatDataValues(boatValues.numValues,boatValues.allBoatValues); - api->getStatus(commonData.status); - - //handle the pag - if (pages[pageNumber].description && pages[pageNumber].description->header){ - - //build some header and footer using commonData - } - //.... - //call the particular page - Page *currentPage=pages[pageNumber].page; - if (currentPage == NULL){ - LOG_DEBUG(GwLog::ERROR,"page number %d not found",pageNumber); - // Error handling for missing page - } - else{ - if (lastPage != pageNumber){ - currentPage->displayNew(commonData,pages[pageNumber].parameters); - lastPage=pageNumber; - } - //call the page code - LOG_DEBUG(GwLog::DEBUG,"calling page %d",pageNumber); - currentPage->displayPage(commonData,pages[pageNumber].parameters); - } - } vTaskDelete(NULL);