From 0b79b7e2ef173e856320b9401a11b71e1048d471 Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Thu, 15 Jan 2026 15:08:42 +0100 Subject: [PATCH] Modify PageDigitalOut --- lib/obp60task/OBP60Extensions.cpp | 47 +++++++++++++++++++++++++++---- lib/obp60task/OBP60Extensions.h | 3 +- lib/obp60task/PageDigitalOut.cpp | 24 ++++++++++------ lib/obp60task/PageNavigation.cpp | 19 +++++++------ 4 files changed, 70 insertions(+), 23 deletions(-) diff --git a/lib/obp60task/OBP60Extensions.cpp b/lib/obp60task/OBP60Extensions.cpp index c8729f9..99dedce 100644 --- a/lib/obp60task/OBP60Extensions.cpp +++ b/lib/obp60task/OBP60Extensions.cpp @@ -57,7 +57,7 @@ GxEPD2_BW & getdisplay(){r #endif // Horter I2C moduls -PCF8574 pcf8574_Out(PCF8574_I2C_ADDR1); // First digital output modul PCF8574 from Horter +PCF8574 pcf8574_Modul1(PCF8574_I2C_ADDR1); // First digital IO modul PCF8574 from Horter // FRAM Adafruit_FRAM_I2C fram; @@ -89,8 +89,8 @@ void hardwareInit(GwApi *api) Wire.begin(); // Init PCF8574 digital outputs Wire.setClock(I2C_SPEED_LOW); // Set I2C clock on 10 kHz - if(pcf8574_Out.begin()){ // Initialize PCF8574 - pcf8574_Out.write8(255); // Clear all outputs + if(pcf8574_Modul1.begin()){ // Initialize PCF8574 + pcf8574_Modul1.write8(255); // Clear all outputs } Wire.setClock(I2C_SPEED); // Set I2C clock on 100 kHz fram = Adafruit_FRAM_I2C(); @@ -193,13 +193,29 @@ void powerInit(String powermode) { } } -void setPCF8574PortPin(uint pin, uint8_t value){ +/* Old function +void setPCF8574PortPin(uint8_t pin, uint8_t value){ Wire.setClock(I2C_SPEED_LOW); // Set I2C clock on 10 kHz - if(pcf8574_Out.begin()){ // Check available and initialize PCF8574 - pcf8574_Out.write(pin, value); // Toggle pin + if(pcf8574_Modul1.begin()){ // Check available and initialize PCF8574 + pcf8574_Modul1.write(pin, value); // Set pin } Wire.setClock(I2C_SPEED); // Set I2C clock on 100 kHz } +*/ + +void setPCF8574PortPin(uint8_t pin, uint8_t value) +{ + if (pin > 7) return; + Wire.setClock(I2C_SPEED_LOW); + if (pcf8574_Modul1.begin()) + { + uint8_t port = pcf8574_Modul1.read8(); // Read all 8 bits + if (value == LOW) port &= ~(1 << pin); // Set bit + else port |= (1 << pin); + pcf8574_Modul1.write8(port); // Write byte + } + Wire.setClock(I2C_SPEED); // Set I2C clock on 100 kHz +} void setPortPin(uint pin, bool value){ @@ -437,6 +453,25 @@ void drawTextCenter(int16_t cx, int16_t cy, String text) { getdisplay().print(text); } +// Draw centered botton with centered text +void drawButtonCenter(int16_t cx, int16_t cy, int8_t sx, int8_t sy, String text, uint16_t fg, uint16_t bg, bool inverted) { + int16_t x1, y1; + uint16_t w, h; + uint16_t color; + getdisplay().getTextBounds(text, 0, 150, &x1, &y1, &w, &h); // Find text center + getdisplay().setCursor(cx - w / 2, cy + h / 2); // Set cursor to center + if (inverted) { + getdisplay().setTextColor(bg); + getdisplay().print(text); // Draw text + getdisplay().fillRoundRect(cx - sx / 2, cy + sy / 2, sx, sy, 5, fg); // Draw button + } + else{ + getdisplay().setTextColor(fg); + getdisplay().print(text); // Draw text + getdisplay().drawRoundRect(cx - sx / 2, cy + sy / 2, sx, sy, 5, fg); // Draw button + } +} + // Draw right aligned text void drawTextRalign(int16_t x, int16_t y, String text) { int16_t x1, y1; diff --git a/lib/obp60task/OBP60Extensions.h b/lib/obp60task/OBP60Extensions.h index 010bd35..33c2a14 100644 --- a/lib/obp60task/OBP60Extensions.h +++ b/lib/obp60task/OBP60Extensions.h @@ -89,7 +89,7 @@ uint8_t getLastPage(); void hardwareInit(GwApi *api); void powerInit(String powermode); -void setPCF8574PortPin(uint pin, uint8_t value);// Set PCF8574 port pin +void setPCF8574PortPin(uint8_t pin, uint8_t value);// Set PCF8574 port pin void setPortPin(uint pin, bool value); // Set port pin for extension port void togglePortPin(uint pin); // Toggle extension port pin @@ -108,6 +108,7 @@ void setBuzzerPower(uint power); // Set buzzer power String xdrDelete(String input); // Delete xdr prefix from string void drawTextCenter(int16_t cx, int16_t cy, String text); +void drawButtonCenter(int16_t cx, int16_t cy, int8_t sx, int8_t sy, String text, uint16_t fg, uint16_t bg, bool inverted); void drawTextRalign(int16_t x, int16_t y, String text); void drawTextBoxed(Rect box, String text, uint16_t fg, uint16_t bg, bool inverted, bool border); diff --git a/lib/obp60task/PageDigitalOut.cpp b/lib/obp60task/PageDigitalOut.cpp index dfe0a76..9988aed 100644 --- a/lib/obp60task/PageDigitalOut.cpp +++ b/lib/obp60task/PageDigitalOut.cpp @@ -22,12 +22,22 @@ bool button3 = false; bool button4 = false; bool button5 = false; -public: + public: PageDigitalOut(CommonData &common){ commonData = &common; common.logger->logDebug(GwLog::LOG,"Instantiate PageDigitalOut"); } + // Set botton labels + virtual void setupKeys(){ + Page::setupKeys(); + commonData->keydata[0].label = "BTN 1"; + commonData->keydata[1].label = "BTN 2"; + commonData->keydata[2].label = "BTN 3"; + commonData->keydata[3].label = "BTN 4"; + commonData->keydata[4].label = "BTN 5"; + } + virtual int handleKey(int key){ // Code for keylock if(key == 11){ @@ -94,18 +104,16 @@ public: getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update getdisplay().setTextColor(commonData->fgcolor); getdisplay().setFont(&Ubuntu_Bold12pt8b); + drawButtonCenter(50, 30, 40, 20, "1", commonData->fgcolor, commonData->bgcolor, button1); + drawButtonCenter(50, 30, 40, 20, "2", commonData->fgcolor, commonData->bgcolor, button2); + drawButtonCenter(50, 30, 40, 20, "3", commonData->fgcolor, commonData->bgcolor, button3); + drawButtonCenter(50, 30, 40, 20, "4", commonData->fgcolor, commonData->bgcolor, button4); + drawButtonCenter(50, 30, 40, 20, "5", commonData->fgcolor, commonData->bgcolor, button5); getdisplay().fillRoundRect(200, 250 , 200, 25, 5, commonData->fgcolor); // Black rect getdisplay().fillRoundRect(202, 252 , 196, 21, 5, commonData->bgcolor); // White rect getdisplay().setCursor(210, 270); getdisplay().print("Map server lost"); - // Set botton labels - commonData->keydata[0].label = "BTN 1"; - commonData->keydata[1].label = "BTN 2"; - commonData->keydata[2].label = "BTN 3"; - commonData->keydata[3].label = "BTN 4"; - commonData->keydata[4].label = "BTN 5"; - return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageNavigation.cpp b/lib/obp60task/PageNavigation.cpp index 7531685..8a3da06 100644 --- a/lib/obp60task/PageNavigation.cpp +++ b/lib/obp60task/PageNavigation.cpp @@ -19,20 +19,28 @@ bool firstRun = true; // Detect the first page run int zoom = 15; // Default zoom level bool showValues = false; // Show values HDT, SOG, DBT in navigation map -private: + private: uint8_t* imageBackupData = nullptr; int imageBackupWidth = 0; int imageBackupHeight = 0; size_t imageBackupSize = 0; bool hasImageBackup = false; -public: + public: PageNavigation(CommonData &common){ commonData = &common; common.logger->logDebug(GwLog::LOG,"Instantiate PageNavigation"); imageBackupData = (uint8_t*)heap_caps_malloc((GxEPD_WIDTH * GxEPD_HEIGHT), MALLOC_CAP_SPIRAM); } + // Set botton labels + virtual void setupKeys(){ + Page::setupKeys(); + commonData->keydata[0].label = "ZOOM -"; + commonData->keydata[1].label = "ZOOM +"; + commonData->keydata[4].label = "VALUES"; + } + virtual int handleKey(int key){ // Code for keylock if(key == 11){ @@ -475,12 +483,7 @@ public: getdisplay().setCursor(70, 85); getdisplay().print(svalue6); } - - // Set botton labels - commonData->keydata[0].label = "ZOOM -"; - commonData->keydata[1].label = "ZOOM +"; - commonData->keydata[4].label = "VALUES"; - + return PAGE_UPDATE; }; };