mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2026-02-11 23:23:06 +01:00
Modify PageDigitalOut
This commit is contained in:
@@ -57,7 +57,7 @@ GxEPD2_BW<GxEPD2_420_SE0420NQ04, GxEPD2_420_SE0420NQ04::HEIGHT> & getdisplay(){r
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Horter I2C moduls
|
// 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
|
// FRAM
|
||||||
Adafruit_FRAM_I2C fram;
|
Adafruit_FRAM_I2C fram;
|
||||||
@@ -89,8 +89,8 @@ void hardwareInit(GwApi *api)
|
|||||||
Wire.begin();
|
Wire.begin();
|
||||||
// Init PCF8574 digital outputs
|
// Init PCF8574 digital outputs
|
||||||
Wire.setClock(I2C_SPEED_LOW); // Set I2C clock on 10 kHz
|
Wire.setClock(I2C_SPEED_LOW); // Set I2C clock on 10 kHz
|
||||||
if(pcf8574_Out.begin()){ // Initialize PCF8574
|
if(pcf8574_Modul1.begin()){ // Initialize PCF8574
|
||||||
pcf8574_Out.write8(255); // Clear all outputs
|
pcf8574_Modul1.write8(255); // Clear all outputs
|
||||||
}
|
}
|
||||||
Wire.setClock(I2C_SPEED); // Set I2C clock on 100 kHz
|
Wire.setClock(I2C_SPEED); // Set I2C clock on 100 kHz
|
||||||
fram = Adafruit_FRAM_I2C();
|
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
|
Wire.setClock(I2C_SPEED_LOW); // Set I2C clock on 10 kHz
|
||||||
if(pcf8574_Out.begin()){ // Check available and initialize PCF8574
|
if(pcf8574_Modul1.begin()){ // Check available and initialize PCF8574
|
||||||
pcf8574_Out.write(pin, value); // Toggle pin
|
pcf8574_Modul1.write(pin, value); // Set pin
|
||||||
}
|
}
|
||||||
Wire.setClock(I2C_SPEED); // Set I2C clock on 100 kHz
|
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){
|
void setPortPin(uint pin, bool value){
|
||||||
@@ -437,6 +453,25 @@ void drawTextCenter(int16_t cx, int16_t cy, String text) {
|
|||||||
getdisplay().print(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
|
// Draw right aligned text
|
||||||
void drawTextRalign(int16_t x, int16_t y, String text) {
|
void drawTextRalign(int16_t x, int16_t y, String text) {
|
||||||
int16_t x1, y1;
|
int16_t x1, y1;
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ uint8_t getLastPage();
|
|||||||
void hardwareInit(GwApi *api);
|
void hardwareInit(GwApi *api);
|
||||||
void powerInit(String powermode);
|
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 setPortPin(uint pin, bool value); // Set port pin for extension port
|
||||||
void togglePortPin(uint pin); // Toggle extension port pin
|
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
|
String xdrDelete(String input); // Delete xdr prefix from string
|
||||||
|
|
||||||
void drawTextCenter(int16_t cx, int16_t cy, String text);
|
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 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);
|
void drawTextBoxed(Rect box, String text, uint16_t fg, uint16_t bg, bool inverted, bool border);
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,22 @@ bool button3 = false;
|
|||||||
bool button4 = false;
|
bool button4 = false;
|
||||||
bool button5 = false;
|
bool button5 = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PageDigitalOut(CommonData &common){
|
PageDigitalOut(CommonData &common){
|
||||||
commonData = &common;
|
commonData = &common;
|
||||||
common.logger->logDebug(GwLog::LOG,"Instantiate PageDigitalOut");
|
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){
|
virtual int handleKey(int key){
|
||||||
// Code for keylock
|
// Code for keylock
|
||||||
if(key == 11){
|
if(key == 11){
|
||||||
@@ -94,18 +104,16 @@ public:
|
|||||||
getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update
|
getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update
|
||||||
getdisplay().setTextColor(commonData->fgcolor);
|
getdisplay().setTextColor(commonData->fgcolor);
|
||||||
getdisplay().setFont(&Ubuntu_Bold12pt8b);
|
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(200, 250 , 200, 25, 5, commonData->fgcolor); // Black rect
|
||||||
getdisplay().fillRoundRect(202, 252 , 196, 21, 5, commonData->bgcolor); // White rect
|
getdisplay().fillRoundRect(202, 252 , 196, 21, 5, commonData->bgcolor); // White rect
|
||||||
getdisplay().setCursor(210, 270);
|
getdisplay().setCursor(210, 270);
|
||||||
getdisplay().print("Map server lost");
|
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;
|
return PAGE_UPDATE;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,20 +19,28 @@ bool firstRun = true; // Detect the first page run
|
|||||||
int zoom = 15; // Default zoom level
|
int zoom = 15; // Default zoom level
|
||||||
bool showValues = false; // Show values HDT, SOG, DBT in navigation map
|
bool showValues = false; // Show values HDT, SOG, DBT in navigation map
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t* imageBackupData = nullptr;
|
uint8_t* imageBackupData = nullptr;
|
||||||
int imageBackupWidth = 0;
|
int imageBackupWidth = 0;
|
||||||
int imageBackupHeight = 0;
|
int imageBackupHeight = 0;
|
||||||
size_t imageBackupSize = 0;
|
size_t imageBackupSize = 0;
|
||||||
bool hasImageBackup = false;
|
bool hasImageBackup = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PageNavigation(CommonData &common){
|
PageNavigation(CommonData &common){
|
||||||
commonData = &common;
|
commonData = &common;
|
||||||
common.logger->logDebug(GwLog::LOG,"Instantiate PageNavigation");
|
common.logger->logDebug(GwLog::LOG,"Instantiate PageNavigation");
|
||||||
imageBackupData = (uint8_t*)heap_caps_malloc((GxEPD_WIDTH * GxEPD_HEIGHT), MALLOC_CAP_SPIRAM);
|
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){
|
virtual int handleKey(int key){
|
||||||
// Code for keylock
|
// Code for keylock
|
||||||
if(key == 11){
|
if(key == 11){
|
||||||
@@ -475,12 +483,7 @@ public:
|
|||||||
getdisplay().setCursor(70, 85);
|
getdisplay().setCursor(70, 85);
|
||||||
getdisplay().print(svalue6);
|
getdisplay().print(svalue6);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set botton labels
|
|
||||||
commonData->keydata[0].label = "ZOOM -";
|
|
||||||
commonData->keydata[1].label = "ZOOM +";
|
|
||||||
commonData->keydata[4].label = "VALUES";
|
|
||||||
|
|
||||||
return PAGE_UPDATE;
|
return PAGE_UPDATE;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user