1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2026-02-11 15:13:06 +01:00

Merge branch 'norbert-walter:master' into master

This commit is contained in:
TobiasE-github
2026-01-31 08:32:06 +01:00
committed by GitHub
6 changed files with 165 additions and 43 deletions

View File

@@ -90,7 +90,7 @@ void hardwareInit(GwApi *api)
// 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_Modul1.begin()){ // Initialize PCF8574 if(pcf8574_Modul1.begin()){ // Initialize PCF8574
pcf8574_Modul1.write8(255); // Clear all outputs pcf8574_Modul1.write8(255); // Clear all outputs (low activ)
} }
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,26 +193,23 @@ void powerInit(String powermode) {
} }
} }
/* Old function void setPCF8574PortPinModul1(uint8_t pin, uint8_t value)
void setPCF8574PortPin(uint8_t pin, uint8_t value){
Wire.setClock(I2C_SPEED_LOW); // Set I2C clock on 10 kHz
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)
{ {
static bool firstRunFinished;
static uint8_t port1; // Retained data for port bits
// If fisrt run then set all outputs to low
if(firstRunFinished == false){
port1 = 255; // Low active
firstRunFinished = true;
}
if (pin > 7) return; if (pin > 7) return;
Wire.setClock(I2C_SPEED_LOW); Wire.setClock(I2C_SPEED_LOW); // Set I2C clock on 10 kHz for longer wires
if (pcf8574_Modul1.begin()) // Set bit
if (pcf8574_Modul1.begin(port1)) // Check module availability
{ {
uint8_t port = pcf8574_Modul1.read8(); // Read all 8 bits if (value == LOW) port1 &= ~(1 << pin); // Set bit
if (value == LOW) port &= ~(1 << pin); // Set bit else port1 |= (1 << pin);
else port |= (1 << pin); pcf8574_Modul1.write8(port1); // Write byte
pcf8574_Modul1.write8(port); // Write byte
} }
Wire.setClock(I2C_SPEED); // Set I2C clock on 100 kHz Wire.setClock(I2C_SPEED); // Set I2C clock on 100 kHz
} }
@@ -458,17 +455,19 @@ void drawButtonCenter(int16_t cx, int16_t cy, int8_t sx, int8_t sy, String text,
int16_t x1, y1; int16_t x1, y1;
uint16_t w, h; uint16_t w, h;
uint16_t color; 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 getdisplay().getTextBounds(text, cx, cy, &x1, &y1, &w, &h); // Find text center
getdisplay().setCursor(cx - w/2, cy + h/2); // Set cursor to center
//getdisplay().drawPixel(cx, cy, fg); // Debug pixel for center position
if (inverted) { if (inverted) {
getdisplay().fillRoundRect(cx - sx / 2, cy - sy / 2, sx, sy, 5, fg); // Draw button
getdisplay().setTextColor(bg); getdisplay().setTextColor(bg);
getdisplay().print(text); // Draw text getdisplay().print(text); // Draw text
getdisplay().fillRoundRect(cx - sx / 2, cy + sy / 2, sx, sy, 5, fg); // Draw button
} }
else{ else{
getdisplay().drawRoundRect(cx - sx / 2, cy - sy / 2, sx, sy, 5, fg); // Draw button
getdisplay().setTextColor(fg); getdisplay().setTextColor(fg);
getdisplay().print(text); // Draw text getdisplay().print(text); // Draw text
getdisplay().drawRoundRect(cx - sx / 2, cy + sy / 2, sx, sy, 5, fg); // Draw button
} }
} }

View File

@@ -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(uint8_t pin, uint8_t value);// Set PCF8574 port pin void setPCF8574PortPinModul1(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

View File

@@ -31,11 +31,11 @@ bool button5 = false;
// Set botton labels // Set botton labels
virtual void setupKeys(){ virtual void setupKeys(){
Page::setupKeys(); Page::setupKeys();
commonData->keydata[0].label = "BTN 1"; commonData->keydata[0].label = "1";
commonData->keydata[1].label = "BTN 2"; commonData->keydata[1].label = "2";
commonData->keydata[2].label = "BTN 3"; commonData->keydata[2].label = "3";
commonData->keydata[3].label = "BTN 4"; commonData->keydata[3].label = "4";
commonData->keydata[4].label = "BTN 5"; commonData->keydata[4].label = "5";
} }
virtual int handleKey(int key){ virtual int handleKey(int key){
@@ -47,31 +47,31 @@ bool button5 = false;
// Code for button 1 // Code for button 1
if(key == 1){ if(key == 1){
button1 = !button1; button1 = !button1;
setPCF8574PortPin(0, button1 ? 0 : 1); // Attention! Inverse logic for PCF8574 setPCF8574PortPinModul1(0, button1 ? 0 : 1); // Attention! Inverse logic for PCF8574
return 0; // Commit the key return 0; // Commit the key
} }
// Code for button 2 // Code for button 2
if(key == 2){ if(key == 2){
button2 = !button2; button2 = !button2;
setPCF8574PortPin(1, button2 ? 0 : 1); // Attention! Inverse logic for PCF8574 setPCF8574PortPinModul1(1, button2 ? 0 : 1); // Attention! Inverse logic for PCF8574
return 0; // Commit the key return 0; // Commit the key
} }
// Code for button 3 // Code for button 3
if(key == 3){ if(key == 3){
button3 = !button3; button3 = !button3;
setPCF8574PortPin(2, button3 ? 0 : 1); // Attention! Inverse logic for PCF8574 setPCF8574PortPinModul1(2, button3 ? 0 : 1); // Attention! Inverse logic for PCF8574
return 0; // Commit the key return 0; // Commit the key
} }
// Code for button 4 // Code for button 4
if(key == 4){ if(key == 4){
button4 = !button4; button4 = !button4;
setPCF8574PortPin(3, button4 ? 0 : 1); // Attention! Inverse logic for PCF8574 setPCF8574PortPinModul1(3, button4 ? 0 : 1); // Attention! Inverse logic for PCF8574
return 0; // Commit the key return 0; // Commit the key
} }
// Code for button 5 // Code for button 5
if(key == 5){ if(key == 5){
button5 = !button5; button5 = !button5;
setPCF8574PortPin(4, button5 ? 0 : 1); // Attention! Inverse logic for PCF8574 setPCF8574PortPinModul1(4, button5 ? 0 : 1); // Attention! Inverse logic for PCF8574
return 0; // Commit the key return 0; // Commit the key
} }
return key; return key;
@@ -87,6 +87,11 @@ bool button5 = false;
bool holdvalues = config->getBool(config->holdvalues); bool holdvalues = config->getBool(config->holdvalues);
String flashLED = config->getString(config->flashLED); String flashLED = config->getString(config->flashLED);
String backlightMode = config->getString(config->backlight); String backlightMode = config->getString(config->backlight);
String name1 = config->getString(config->mod1Out1);
String name2 = config->getString(config->mod1Out2);
String name3 = config->getString(config->mod1Out3);
String name4 = config->getString(config->mod1Out4);
String name5 = config->getString(config->mod1Out5);
// Optical warning by limit violation (unused) // Optical warning by limit violation (unused)
if(String(flashLED) == "Limit Violation"){ if(String(flashLED) == "Limit Violation"){
@@ -104,15 +109,23 @@ bool button5 = false;
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); // Write text
drawButtonCenter(50, 30, 40, 20, "2", commonData->fgcolor, commonData->bgcolor, button2); getdisplay().setCursor(100, 50 + 8);
drawButtonCenter(50, 30, 40, 20, "3", commonData->fgcolor, commonData->bgcolor, button3); getdisplay().print(name1);
drawButtonCenter(50, 30, 40, 20, "4", commonData->fgcolor, commonData->bgcolor, button4); getdisplay().setCursor(100, 100 + 8);
drawButtonCenter(50, 30, 40, 20, "5", commonData->fgcolor, commonData->bgcolor, button5); getdisplay().print(name2);
getdisplay().fillRoundRect(200, 250 , 200, 25, 5, commonData->fgcolor); // Black rect getdisplay().setCursor(100, 150 + 8);
getdisplay().fillRoundRect(202, 252 , 196, 21, 5, commonData->bgcolor); // White rect getdisplay().print(name3);
getdisplay().setCursor(210, 270); getdisplay().setCursor(100,200 + 8);
getdisplay().print("Map server lost"); getdisplay().print(name4);
getdisplay().setCursor(100, 250 + 8);
getdisplay().print(name5);
// Draw bottons
drawButtonCenter(50, 50, 40, 27, "1", commonData->fgcolor, commonData->bgcolor, button1);
drawButtonCenter(50, 100, 40, 27, "2", commonData->fgcolor, commonData->bgcolor, button2);
drawButtonCenter(50, 150, 40, 27, "3", commonData->fgcolor, commonData->bgcolor, button3);
drawButtonCenter(50, 200, 40, 27, "4", commonData->fgcolor, commonData->bgcolor, button4);
drawButtonCenter(50, 250, 40, 27, "5", commonData->fgcolor, commonData->bgcolor, button5);
return PAGE_UPDATE; return PAGE_UPDATE;
}; };

View File

@@ -40,7 +40,7 @@ bool showValues = false; // Show values HDT, SOG, DBT in navigation map
commonData->keydata[1].label = "ZOOM +"; commonData->keydata[1].label = "ZOOM +";
commonData->keydata[4].label = "VALUES"; 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){

View File

@@ -661,6 +661,61 @@
"obp60":"true" "obp60":"true"
} }
}, },
{
"name": "mod1Out1",
"label": "Name1",
"type": "string",
"default": "text1",
"description": "Button name",
"category": "OBP60 IO-Modul1",
"capabilities": {
"obp60":"true"
}
},
{
"name": "mod1Out2",
"label": "Name2",
"type": "string",
"default": "text2",
"description": "Button name",
"category": "OBP60 IO-Modul1",
"capabilities": {
"obp60":"true"
}
},
{
"name": "mod1Out3",
"label": "Name3",
"type": "string",
"default": "text3",
"description": "Button name",
"category": "OBP60 IO-Modul1",
"capabilities": {
"obp60":"true"
}
},
{
"name": "mod1Out4",
"label": "Name4",
"type": "string",
"default": "text4",
"description": "Button name",
"category": "OBP60 IO-Modul1",
"capabilities": {
"obp60":"true"
}
},
{
"name": "mod1Out5",
"label": "Name5",
"type": "string",
"default": "text5",
"description": "Button name",
"category": "OBP60 IO-Modul1",
"capabilities": {
"obp60":"true"
}
},
{ {
"name": "tSensitivity", "name": "tSensitivity",
"label": "Touch Sensitivity [%]", "label": "Touch Sensitivity [%]",

View File

@@ -672,6 +672,61 @@
"obp40": "true" "obp40": "true"
} }
}, },
{
"name": "mod1Out1",
"label": "Name1",
"type": "string",
"default": "text1",
"description": "Button name",
"category": "OBP60 IO-Modul1",
"capabilities": {
"obp40":"true"
}
},
{
"name": "mod1Out2",
"label": "Name2",
"type": "string",
"default": "text2",
"description": "Button name",
"category": "OBP60 IO-Modul1",
"capabilities": {
"obp40":"true"
}
},
{
"name": "mod1Out3",
"label": "Name3",
"type": "string",
"default": "text3",
"description": "Button name",
"category": "OBP60 IO-Modul1",
"capabilities": {
"obp40":"true"
}
},
{
"name": "mod1Out4",
"label": "Name4",
"type": "string",
"default": "text4",
"description": "Button name",
"category": "OBP60 IO-Modul1",
"capabilities": {
"obp40":"true"
}
},
{
"name": "mod1Out5",
"label": "Name5",
"type": "string",
"default": "text5",
"description": "Button name",
"category": "OBP60 IO-Modul1",
"capabilities": {
"obp40":"true"
}
},
{ {
"name": "tSensitivity", "name": "tSensitivity",
"label": "Touch Sensitivity [%]", "label": "Touch Sensitivity [%]",