mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-29 05:33:05 +01:00
Add PageDigitalOut
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
#if defined BOARD_OBP60S3 || defined BOARD_OBP40S3
|
#if defined BOARD_OBP60S3 || defined BOARD_OBP40S3
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <PCF8574.h> // Driver for PCF8574 output modul from Horter
|
|
||||||
#include <Wire.h> // I2C
|
#include <Wire.h> // I2C
|
||||||
#include <RTClib.h> // Driver for DS1388 RTC
|
#include <RTClib.h> // Driver for DS1388 RTC
|
||||||
|
#include <PCF8574.h> // PCF8574 modules from Horter
|
||||||
#include "SunRise.h" // Lib for sunrise and sunset calculation
|
#include "SunRise.h" // Lib for sunrise and sunset calculation
|
||||||
#include "Pagedata.h"
|
#include "Pagedata.h"
|
||||||
#include "OBP60Hardware.h"
|
#include "OBP60Hardware.h"
|
||||||
@@ -88,10 +88,11 @@ void hardwareInit(GwApi *api)
|
|||||||
|
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
// Init PCF8574 digital outputs
|
// Init PCF8574 digital outputs
|
||||||
Wire.setClock(I2C_SPEED); // 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_Out.begin()){ // Initialize PCF8574
|
||||||
pcf8574_Out.write8(255); // Clear all outputs
|
pcf8574_Out.write8(255); // Clear all outputs
|
||||||
}
|
}
|
||||||
|
Wire.setClock(I2C_SPEED); // Set I2C clock on 100 kHz
|
||||||
fram = Adafruit_FRAM_I2C();
|
fram = Adafruit_FRAM_I2C();
|
||||||
if (esp_reset_reason() == ESP_RST_POWERON) {
|
if (esp_reset_reason() == ESP_RST_POWERON) {
|
||||||
// help initialize FRAM
|
// help initialize FRAM
|
||||||
@@ -192,6 +193,15 @@ void powerInit(String powermode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setPCF8574PortPin(uint 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
|
||||||
|
}
|
||||||
|
Wire.setClock(I2C_SPEED); // Set I2C clock on 100 kHz
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void setPortPin(uint pin, bool value){
|
void setPortPin(uint pin, bool value){
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
digitalWrite(pin, value);
|
digitalWrite(pin, value);
|
||||||
|
|||||||
@@ -89,8 +89,8 @@ 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 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
|
||||||
|
|
||||||
Color colorMapping(const String &colorString); // Color mapping string to CHSV colors
|
Color colorMapping(const String &colorString); // Color mapping string to CHSV colors
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
// Direction pin for RS485 NMEA0183
|
// Direction pin for RS485 NMEA0183
|
||||||
#define OBP_DIRECTION_PIN 18
|
#define OBP_DIRECTION_PIN 18
|
||||||
// I2C
|
// I2C
|
||||||
#define I2C_SPEED 10000UL // 10kHz clock speed on I2C bus
|
#define I2C_SPEED 10000UL // 100kHz clock speed on I2C bus
|
||||||
|
#define I2C_SPEED_LOW 1000UL // 10kHz clock speed on I2C bus for external bus
|
||||||
#define OBP_I2C_SDA 47
|
#define OBP_I2C_SDA 47
|
||||||
#define OBP_I2C_SCL 21
|
#define OBP_I2C_SCL 21
|
||||||
// DS1388 RTC
|
// DS1388 RTC
|
||||||
@@ -84,7 +85,8 @@
|
|||||||
// Direction pin for RS485 NMEA0183
|
// Direction pin for RS485 NMEA0183
|
||||||
#define OBP_DIRECTION_PIN 8
|
#define OBP_DIRECTION_PIN 8
|
||||||
// I2C
|
// I2C
|
||||||
#define I2C_SPEED 100000UL // 100kHz clock speed on I2C bus
|
#define I2C_SPEED 100000UL // 100kHz clock speed on I2C bus
|
||||||
|
#define I2C_SPEED_LOW 1000UL // 10kHz clock speed on I2C bus for external bus
|
||||||
#define OBP_I2C_SDA 21
|
#define OBP_I2C_SDA 21
|
||||||
#define OBP_I2C_SCL 38
|
#define OBP_I2C_SCL 38
|
||||||
// DS1388 RTC
|
// DS1388 RTC
|
||||||
|
|||||||
131
lib/obp60task/PageDigitalOut.cpp
Normal file
131
lib/obp60task/PageDigitalOut.cpp
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
#if defined BOARD_OBP60S3 || defined BOARD_OBP40S3
|
||||||
|
|
||||||
|
#include <PCF8574.h> // PCF8574 modules from Horter
|
||||||
|
#include "Pagedata.h"
|
||||||
|
#include "OBP60Extensions.h"
|
||||||
|
|
||||||
|
#include "images/OBP_400x300.xbm" // OBP Logo
|
||||||
|
#ifdef BOARD_OBP60S3
|
||||||
|
#include "images/OBP60_400x300.xbm" // MFD with logo
|
||||||
|
#endif
|
||||||
|
#ifdef BOARD_OBP40S3
|
||||||
|
#include "images/OBP40_400x300.xbm" // MFD with logo
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class PageDigitalOut : public Page
|
||||||
|
{
|
||||||
|
|
||||||
|
// Status values
|
||||||
|
bool button1 = false;
|
||||||
|
bool button2 = false;
|
||||||
|
bool button3 = false;
|
||||||
|
bool button4 = false;
|
||||||
|
bool button5 = false;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PageDigitalOut(CommonData &common){
|
||||||
|
commonData = &common;
|
||||||
|
common.logger->logDebug(GwLog::LOG,"Instantiate PageDigitalOut");
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int handleKey(int key){
|
||||||
|
// Code for keylock
|
||||||
|
if(key == 11){
|
||||||
|
commonData->keylock = !commonData->keylock;
|
||||||
|
return 0; // Commit the key
|
||||||
|
}
|
||||||
|
// Code for button 1
|
||||||
|
if(key == 1){
|
||||||
|
button1 = !button1;
|
||||||
|
setPCF8574PortPin(0, button1 ? 0 : 1); // Attention! Inverse logic for PCF8574
|
||||||
|
return 0; // Commit the key
|
||||||
|
}
|
||||||
|
// Code for button 2
|
||||||
|
if(key == 2){
|
||||||
|
button2 = !button2;
|
||||||
|
setPCF8574PortPin(1, button2 ? 0 : 1); // Attention! Inverse logic for PCF8574
|
||||||
|
return 0; // Commit the key
|
||||||
|
}
|
||||||
|
// Code for button 3
|
||||||
|
if(key == 3){
|
||||||
|
button3 = !button3;
|
||||||
|
setPCF8574PortPin(2, button3 ? 0 : 1); // Attention! Inverse logic for PCF8574
|
||||||
|
return 0; // Commit the key
|
||||||
|
}
|
||||||
|
// Code for button 4
|
||||||
|
if(key == 4){
|
||||||
|
button4 = !button4;
|
||||||
|
setPCF8574PortPin(3, button4 ? 0 : 1); // Attention! Inverse logic for PCF8574
|
||||||
|
return 0; // Commit the key
|
||||||
|
}
|
||||||
|
// Code for button 5
|
||||||
|
if(key == 5){
|
||||||
|
button5 = !button5;
|
||||||
|
setPCF8574PortPin(4, button5 ? 0 : 1); // Attention! Inverse logic for PCF8574
|
||||||
|
return 0; // Commit the key
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
int displayPage(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);
|
||||||
|
bool holdvalues = config->getBool(config->holdvalues);
|
||||||
|
String flashLED = config->getString(config->flashLED);
|
||||||
|
String backlightMode = config->getString(config->backlight);
|
||||||
|
|
||||||
|
// Optical warning by limit violation (unused)
|
||||||
|
if(String(flashLED) == "Limit Violation"){
|
||||||
|
setBlinkingLED(false);
|
||||||
|
setFlashLED(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logging boat values
|
||||||
|
LOG_DEBUG(GwLog::LOG,"Drawing at PageDigitalOut");
|
||||||
|
|
||||||
|
// Draw page
|
||||||
|
//***********************************************************
|
||||||
|
|
||||||
|
// Set display in partial refresh mode
|
||||||
|
getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update
|
||||||
|
getdisplay().setTextColor(commonData->fgcolor);
|
||||||
|
getdisplay().setFont(&Ubuntu_Bold12pt8b);
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
static Page* createPage(CommonData &common){
|
||||||
|
return new PageDigitalOut(common);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* with the code below we make this page known to the PageTask
|
||||||
|
* we give it a type (name) that can be selected in the config
|
||||||
|
* we define which function is to be called
|
||||||
|
* and we provide the number of user parameters we expect
|
||||||
|
* this will be number of BoatValue pointers in pageData.values
|
||||||
|
*/
|
||||||
|
PageDescription registerPageDigitalOut(
|
||||||
|
"DigitalOut", // Page name
|
||||||
|
createPage, // Action
|
||||||
|
0, // Number of bus values depends on selection in Web configuration
|
||||||
|
true // Show display header on/off
|
||||||
|
);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -39,7 +39,7 @@ public:
|
|||||||
commonData->keylock = !commonData->keylock;
|
commonData->keylock = !commonData->keylock;
|
||||||
return 0; // Commit the key
|
return 0; // Commit the key
|
||||||
}
|
}
|
||||||
// Cood for zoom -
|
// Code for zoom -
|
||||||
if(key == 1){
|
if(key == 1){
|
||||||
zoom --; // Zoom -
|
zoom --; // Zoom -
|
||||||
if(zoom <7){
|
if(zoom <7){
|
||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
}
|
}
|
||||||
return 0; // Commit the key
|
return 0; // Commit the key
|
||||||
}
|
}
|
||||||
// Cood for zoom -
|
// Code for zoom -
|
||||||
if(key == 2){
|
if(key == 2){
|
||||||
zoom ++; // Zoom +
|
zoom ++; // Zoom +
|
||||||
if(zoom >17){
|
if(zoom >17){
|
||||||
@@ -68,7 +68,7 @@ public:
|
|||||||
|
|
||||||
// Get config data
|
// Get config data
|
||||||
String lengthformat = config->getString(config->lengthFormat);
|
String lengthformat = config->getString(config->lengthFormat);
|
||||||
// bool simulation = config->getBool(config->useSimuData);
|
bool simulation = config->getBool(config->useSimuData);
|
||||||
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);
|
||||||
|
|||||||
@@ -1364,6 +1364,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -1663,6 +1664,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -1954,6 +1956,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -2237,6 +2240,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -2512,6 +2516,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -2779,6 +2784,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -3038,6 +3044,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -3289,6 +3296,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -3532,6 +3540,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -3767,6 +3776,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
|
|||||||
@@ -1387,6 +1387,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -1716,6 +1717,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -2036,6 +2038,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -2347,6 +2350,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -2649,6 +2653,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -2942,6 +2947,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -3226,6 +3232,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -3501,6 +3508,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -3767,6 +3775,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
@@ -4024,6 +4033,7 @@
|
|||||||
"Battery2",
|
"Battery2",
|
||||||
"Clock",
|
"Clock",
|
||||||
"Compass",
|
"Compass",
|
||||||
|
"DigitalOut",
|
||||||
"DST810",
|
"DST810",
|
||||||
"Fluid",
|
"Fluid",
|
||||||
"FourValues",
|
"FourValues",
|
||||||
|
|||||||
@@ -262,6 +262,8 @@ void registerAllPages(PageList &list){
|
|||||||
list.add(®isterPageSkyView);
|
list.add(®isterPageSkyView);
|
||||||
extern PageDescription registerPageNavigation;
|
extern PageDescription registerPageNavigation;
|
||||||
list.add(®isterPageNavigation);
|
list.add(®isterPageNavigation);
|
||||||
|
extern PageDescription registerPageDigitalOut;
|
||||||
|
list.add(®isterPageDigitalOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Undervoltage detection for shutdown display
|
// Undervoltage detection for shutdown display
|
||||||
|
|||||||
Reference in New Issue
Block a user