Display header working

This commit is contained in:
norbert-walter 2022-02-26 18:51:42 +01:00
parent f9c61369a0
commit d39c233a39
8 changed files with 163 additions and 75 deletions

View File

@ -1,4 +1,5 @@
#include <Arduino.h> #include <Arduino.h>
#include "Pagedata.h"
#include "OBP60Hardware.h" #include "OBP60Hardware.h"
#include "OBP60ExtensionPort.h" #include "OBP60ExtensionPort.h"
@ -104,37 +105,85 @@ void setBuzzerPower(uint power){
buzzerpower = power; buzzerpower = power;
} }
/* void displayHeader(CommonData &commonData, GwApi::BoatValue *hdop, GwApi::BoatValue *date, GwApi::BoatValue *time){
void underVoltageDetection(){
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // V = 1/20 * Vin
long starttime;
static bool undervoltage = false;
if(actVoltage < MIN_VOLTAGE){ static bool heartbeat = false;
if(undervoltage == false){ static unsigned long usbRxOld = 0;
starttime = millis(); static unsigned long usbTxOld = 0;
undervoltage = true; static unsigned long serRxOld = 0;
static unsigned long serTxOld = 0;
static unsigned long tcpSerRxOld = 0;
static unsigned long tcpSerTxOld = 0;
static unsigned long tcpClRxOld = 0;
static unsigned long tcpClTxOld = 0;
static unsigned long n2kRxOld = 0;
static unsigned long n2kTxOld = 0;
// Show status info
display.setFont(&Ubuntu_Bold8pt7b);
display.setTextColor(GxEPD_BLACK);
display.setCursor(0, 15);
if(commonData.status.wifiApOn){
display.print(" AP ");
}
// If receive new telegram data then display bus name
if(commonData.status.tcpClRx != tcpClRxOld || commonData.status.tcpClTx != tcpClTxOld || commonData.status.tcpSerRx != tcpSerRxOld || commonData.status.tcpSerTx != tcpSerTxOld){
display.print("TCP ");
}
if(commonData.status.n2kRx != n2kRxOld || commonData.status.n2kTx != n2kTxOld){
display.print("N2K ");
}
if(commonData.status.serRx != serRxOld || commonData.status.serTx != serTxOld){
display.print("183 ");
}
if(commonData.status.usbRx != usbRxOld || commonData.status.usbTx != usbTxOld){
display.print("USB ");
}
if(commonData.config->getBool(commonData.config->useGPS) == true && hdop->valid == true && hdop->value <= 50){
display.print("GPS");
}
// Save old telegram counter
tcpClRxOld = commonData.status.tcpClRx;
tcpClTxOld = commonData.status.tcpClTx;
tcpSerRxOld = commonData.status.tcpSerRx;
tcpSerTxOld = commonData.status.tcpSerTx;
n2kRxOld = commonData.status.n2kRx;
n2kTxOld = commonData.status.n2kTx;
serRxOld = commonData.status.serRx;
serTxOld = commonData.status.serTx;
usbRxOld = commonData.status.usbRx;
usbTxOld = commonData.status.usbTx;
// Heartbeat as dot
display.setFont(&Ubuntu_Bold32pt7b);
display.setCursor(205, 14);
if(heartbeat == true){
display.print(".");
}
else{
display.print(" ");
}
heartbeat = !heartbeat;
// Date and time
display.setFont(&Ubuntu_Bold8pt7b);
display.setCursor(230, 15);
if(hdop->valid == true && hdop->value <= 50){
String acttime = formatValue(time, commonData).svalue;
acttime = acttime.substring(0, 5);
String actdate = formatValue(date, commonData).svalue;
display.print(acttime);
display.print(" ");
display.print(actdate);
display.print(" ");
if(commonData.config->getInt(commonData.config->timeZone) == 0){
display.print("UTC");
} }
if(millis() > starttime + POWER_FAIL_TIME){ else{
// Timer1.detach(); // Stop Timer1 display.print("LOT");
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
setPortPin(OBP_FLASH_LED, false); // Flash LED Off
buzzer(TONE4, 20); // Buzzer tone 4kHz 20% 20ms
// Shutdown EInk display
display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE); // Draw white sreen
display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, false); // Partial update
setPortPin(OBP_POWER_50, false); // Power rail 5.0V Off
setPortPin(OBP_POWER_33, false); // Power rail 3.3V Off
// display._sleep(); // Display shut dow
// Stop system
while(true){
esp_deep_sleep_start(); // Deep Sleep without weakup. Weakup only after power cycle (restart).
}
} }
} }
else{ else{
undervoltage = false; display.print("No GPS data");
} }
} }
*/

View File

@ -33,6 +33,6 @@ void setBlinkingLED(bool on); // Set blinking LED active
void buzzer(uint frequency, uint duration); // Buzzer function void buzzer(uint frequency, uint duration); // Buzzer function
void setBuzzerPower(uint power); // Set buzzer power void setBuzzerPower(uint power); // Set buzzer power
// void underVoltageDetection(); // Function for 12V undervoltage detection void displayHeader(CommonData &commonData, GwApi::BoatValue *hdop, GwApi::BoatValue *date, GwApi::BoatValue *time); // Draw display header
#endif #endif

View File

@ -205,15 +205,18 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
rotation = 0.04 + float(random(0, 10)) / 100.0; rotation = 0.04 + float(random(0, 10)) / 100.0;
} }
rotation = rotation * 57.2958; // Unit conversion form rad/s to deg/s rotation = rotation * 57.2958; // Unit conversion form rad/s to deg/s
result.unit = "deg/s"; result.unit = "Deg/s";
if(rotation < 10){ if(rotation < -100){
snprintf(buffer,bsize,"%2.1f",rotation); rotation = -99;
} }
if(rotation >= 10 && rotation < 100){ if(rotation > 100){
snprintf(buffer,bsize,"%2.1f",rotation); rotation = 99;
} }
if(rotation >= 100){ if(rotation > -10 && rotation < 10){
snprintf(buffer,bsize,"%3.0f",rotation); snprintf(buffer,bsize,"%1.1f",rotation);
}
if(rotation <= -10 || rotation >= 10){
snprintf(buffer,bsize,"%2.0f",rotation);
} }
} }
//######################################################## //########################################################

View File

@ -7,6 +7,9 @@ class PageOneValue : public Page{
GwConfigHandler *config = commonData.config; GwConfigHandler *config = commonData.config;
GwLog *logger=commonData.logger; GwLog *logger=commonData.logger;
static String svalue1old = "";
static String unit1old = "";
// 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);
@ -16,12 +19,13 @@ class PageOneValue : public Page{
String backlightMode = config->getString(config->backlight); String backlightMode = config->getString(config->backlight);
// Get boat values // Get boat values
GwApi::BoatValue *bvalue=pageData.values[0]; // First element in list (only one value by PageOneValue) GwApi::BoatValue *bvalue1 = pageData.values[0]; // First element in list (only one value by PageOneValue)
String name1 = bvalue->getName().c_str(); // Value name String name1 = bvalue1->getName().c_str(); // Value name
name1 = name1.substring(0, 6); // String length limit for value name name1 = name1.substring(0, 6); // String length limit for value name
double value1 = bvalue->value; // Value as double in SI unit double value1 = bvalue1->value; // Value as double in SI unit
String svalue1 = formatValue(bvalue, commonData).svalue; // Formatted value as string including unit conversion and switching decimal places bool valid1 = bvalue1->valid; // Valid information
String unit1 = formatValue(bvalue, commonData).unit; // Unit of value String svalue1 = formatValue(bvalue1, commonData).svalue; // Formatted value as string including unit conversion and switching decimal places
String unit1 = formatValue(bvalue1, commonData).unit; // Unit of value
// Optical warning by limit violation (unused) // Optical warning by limit violation (unused)
if(String(flashLED) == "Limit Violation"){ if(String(flashLED) == "Limit Violation"){
@ -30,13 +34,13 @@ class PageOneValue : public Page{
} }
// Logging boat values // Logging boat values
if (bvalue == NULL) return; if (bvalue1 == 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 // Draw page
//*********************************************************** //***********************************************************
// Clear display, set background color and text color // Set background color and text color
int textcolor = GxEPD_BLACK; int textcolor = GxEPD_BLACK;
int pixelcolor = GxEPD_BLACK; int pixelcolor = GxEPD_BLACK;
int bgcolor = GxEPD_WHITE; int bgcolor = GxEPD_WHITE;
@ -50,7 +54,7 @@ class PageOneValue : public Page{
pixelcolor = GxEPD_WHITE; pixelcolor = GxEPD_WHITE;
bgcolor = GxEPD_BLACK; bgcolor = GxEPD_BLACK;
} }
// Clear display in obp60task.cpp in main loop // Clear display by call in obp60task.cpp in main loop
// Show name // Show name
display.setFont(&Ubuntu_Bold32pt7b); display.setFont(&Ubuntu_Bold32pt7b);
@ -60,14 +64,19 @@ class PageOneValue : public Page{
// Show unit // Show unit
display.setFont(&Ubuntu_Bold20pt7b); display.setFont(&Ubuntu_Bold20pt7b);
display.setCursor(270, 100); display.setCursor(270, 100);
display.print(unit1); if(holdvalues == false){
display.print(unit1); // Unit
}
else{
display.print(unit1old);
}
// Switch font if format for any values // Switch font if format for any values
if(bvalue->getFormat() == "formatLatitude" || bvalue->getFormat() == "formatLongitude"){ if(bvalue1->getFormat() == "formatLatitude" || bvalue1->getFormat() == "formatLongitude"){
display.setFont(&Ubuntu_Bold20pt7b); display.setFont(&Ubuntu_Bold20pt7b);
display.setCursor(20, 180); display.setCursor(20, 180);
} }
else if(bvalue->getFormat() == "formatTime" || bvalue->getFormat() == "formatDate"){ else if(bvalue1->getFormat() == "formatTime" || bvalue1->getFormat() == "formatDate"){
display.setFont(&Ubuntu_Bold32pt7b); display.setFont(&Ubuntu_Bold32pt7b);
display.setCursor(20, 200); display.setCursor(20, 200);
} }
@ -77,12 +86,26 @@ class PageOneValue : public Page{
} }
// Show bus data or using simulation data // Show bus data or using simulation data
display.print(svalue1); // Real value as formated string if(holdvalues == false){
display.print(svalue1); // Real value as formated string
}
else{
display.print(svalue1old); // Old value as formated string
}
if(valid1 == true){
svalue1old = svalue1; // Save the old value
unit1old = unit1; // Save the old unit
}
// Key Layout // Key Layout
display.setFont(&Ubuntu_Bold8pt7b); display.setFont(&Ubuntu_Bold8pt7b);
display.setCursor(115, 290); display.setCursor(115, 290);
display.print(" [ <<<<<< >>>>>> ]"); if(commonData.keylock == false){
display.print(" [ <<<<<< >>>>>> ]");
}
else{
display.print(" [ Keylock active ]");
}
if(String(backlightMode) == "Control by Key"){ if(String(backlightMode) == "Control by Key"){
display.setCursor(343, 290); display.setCursor(343, 290);
display.print("[ILUM]"); display.print("[ILUM]");

View File

@ -28,7 +28,7 @@ public:
String displaycolor = config->getString(config->displaycolor); String displaycolor = config->getString(config->displaycolor);
bool holdvalues = config->getBool(config->holdvalues); bool holdvalues = config->getBool(config->holdvalues);
String flashLED = config->getString(config->flashLED); String flashLED = config->getString(config->flashLED);
int batVoltage = config->getInt(config->batteryVoltage); String batVoltage = config->getString(config->batteryVoltage);
String batType = config->getString(config->batteryType); String batType = config->getString(config->batteryType);
String backlightMode = config->getString(config->backlight); String backlightMode = config->getString(config->backlight);
@ -86,7 +86,12 @@ public:
display.setFont(&DSEG7Classic_BoldItalic60pt7b); display.setFont(&DSEG7Classic_BoldItalic60pt7b);
display.setCursor(20, 240); display.setCursor(20, 240);
if(simulation == true){ if(simulation == true){
value1 = batVoltage; if(batVoltage == "12V"){
value1 = 12.0;
}
if(batVoltage == "24V"){
value1 = 24.0;
}
value1 += float(random(0, 5)) / 10; // Simulation data value1 += float(random(0, 5)) / 10; // Simulation data
display.print(value1,1); display.print(value1,1);
} }

View File

@ -16,6 +16,7 @@ typedef struct{
GwApi::Status status; GwApi::Status status;
GwLog *logger=NULL; GwLog *logger=NULL;
GwConfigHandler *config=NULL; GwConfigHandler *config=NULL;
bool keylock = false;
} CommonData; } CommonData;
//a base class that all pages must inherit from //a base class that all pages must inherit from

View File

@ -97,12 +97,13 @@
{ {
"name": "batteryVoltage", "name": "batteryVoltage",
"label": "Battery Voltage [V]", "label": "Battery Voltage [V]",
"type": "number", "type": "list",
"default": "12", "default": "12V",
"check": "checkMinMax", "description": "Battery Voltage [12V|24V]",
"min": 0, "list": [
"max": 1000, "12V",
"description": "Fuel tank capacity [0...1000V]", "24V"
],
"category": "OBP60 Settings", "category": "OBP60 Settings",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"
@ -376,7 +377,7 @@
"name": "backlight", "name": "backlight",
"label": "Backlight Mode", "label": "Backlight Mode",
"type": "list", "type": "list",
"default": "Off", "default": "Control by Key",
"description": "Settings for display mode", "description": "Settings for display mode",
"list": [ "list": [
"Off", "Off",
@ -479,7 +480,7 @@
"check": "checkMinMax", "check": "checkMinMax",
"min": 1, "min": 1,
"max": 4, "max": 4,
"default":"1", "default":"4",
"category":"OBP60 Pages", "category":"OBP60 Pages",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"
@ -555,7 +556,8 @@
"category": "OBP60 Page 2", "category": "OBP60 Page 2",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"
} },
"condition":[{"visiblePages":"2"},{"visiblePages":"3"},{"visiblePages":"4"}]
}, },
{ {
"name": "page2value1", "name": "page2value1",
@ -615,7 +617,8 @@
"category": "OBP60 Page 3", "category": "OBP60 Page 3",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"
} },
"condition":[{"visiblePages":"3"},{"visiblePages":"4"}]
}, },
{ {
"name": "page3value1", "name": "page3value1",
@ -675,7 +678,8 @@
"category": "OBP60 Page 4", "category": "OBP60 Page 4",
"capabilities": { "capabilities": {
"obp60":"true" "obp60":"true"
} },
"condition":[{"visiblePages":"4"}]
}, },
{ {
"name": "page4value1", "name": "page4value1",

View File

@ -21,11 +21,7 @@
#include "MFD_OBP60_400x300_sw.h" // MFD with logo #include "MFD_OBP60_400x300_sw.h" // MFD with logo
#include "Logo_OBP_400x300_sw.h" // OBP Logo #include "Logo_OBP_400x300_sw.h" // OBP Logo
#include "OBP60QRWiFi.h" // Functions lib for WiFi QR code #include "OBP60QRWiFi.h" // Functions lib for WiFi QR code
/*
// Timer Interrupts for hardware functions
Ticker Timer1; // Under voltage detection
Ticker Timer2; // Binking flash LED
*/
tNMEA0183Msg NMEA0183Msg; tNMEA0183Msg NMEA0183Msg;
tNMEA0183 NMEA0183; tNMEA0183 NMEA0183;
@ -39,6 +35,7 @@ void underVoltageDetection();
Ticker Timer1(underVoltageDetection, 1); // Start Timer1 with maximum speed with 1ms Ticker Timer1(underVoltageDetection, 1); // Start Timer1 with maximum speed with 1ms
Ticker Timer2(blinkingFlashLED, 500); Ticker Timer2(blinkingFlashLED, 500);
// Undervoltage function for shutdown display
void underVoltageDetection(){ void underVoltageDetection(){
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // V = 1/20 * Vin float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // V = 1/20 * Vin
long starttime; long starttime;
@ -413,7 +410,9 @@ void OBP60Task(GwApi *api){
// bgcolor defined in init section // bgcolor defined in init section
// Boat values for main loop // Boat values for main loop
GwApi::BoatValue *hdop = boatValues.findValueOrCreate("HDOP"); // Load HDOP GwApi::BoatValue *hdop = boatValues.findValueOrCreate("HDOP"); // Load HDOP
GwApi::BoatValue *date = boatValues.findValueOrCreate("GpsDate"); // Load GpsDate
GwApi::BoatValue *time = boatValues.findValueOrCreate("GpsTime"); // Load GpsTime
LOG_DEBUG(GwLog::LOG,"obp60task: start mainloop"); LOG_DEBUG(GwLog::LOG,"obp60task: start mainloop");
int pageNumber=0; int pageNumber=0;
@ -485,6 +484,13 @@ void OBP60Task(GwApi *api){
display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Needs partial update before full update to refresh the frame buffer display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Needs partial update before full update to refresh the frame buffer
display.update(); // Full update display.update(); // Full update
} }
// #11 Keylock
/*
if (keyboardMessage == 11)
{
commonData.keylock = !commonData.keylock; // Toggle keylock
}
*/
} }
LOG_DEBUG(GwLog::LOG,"set pagenumber to %d",pageNumber); LOG_DEBUG(GwLog::LOG,"set pagenumber to %d",pageNumber);
} }
@ -504,13 +510,10 @@ void OBP60Task(GwApi *api){
api->getStatus(commonData.status); api->getStatus(commonData.status);
// Show header if enabled // Show header if enabled
display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, bgcolor); // Clear sreen display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, bgcolor); // Clear display
if (pages[pageNumber].description && pages[pageNumber].description->header){ if (pages[pageNumber].description && pages[pageNumber].description->header){
//build some header and footer using commonData //build some header and footer using commonData
display.setTextColor(textcolor); displayHeader(commonData, hdop, date, time);
display.setFont(&Ubuntu_Bold8pt7b);
display.setCursor(0, 15);
display.print("AP TCP GPS");
} }
// Call the particular page // Call the particular page