Display header working
This commit is contained in:
parent
f9c61369a0
commit
d39c233a39
|
@ -1,4 +1,5 @@
|
|||
#include <Arduino.h>
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60Hardware.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
|
||||
|
@ -104,37 +105,85 @@ void setBuzzerPower(uint power){
|
|||
buzzerpower = power;
|
||||
}
|
||||
|
||||
/*
|
||||
void underVoltageDetection(){
|
||||
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // V = 1/20 * Vin
|
||||
long starttime;
|
||||
static bool undervoltage = false;
|
||||
void displayHeader(CommonData &commonData, GwApi::BoatValue *hdop, GwApi::BoatValue *date, GwApi::BoatValue *time){
|
||||
|
||||
if(actVoltage < MIN_VOLTAGE){
|
||||
if(undervoltage == false){
|
||||
starttime = millis();
|
||||
undervoltage = true;
|
||||
static bool heartbeat = false;
|
||||
static unsigned long usbRxOld = 0;
|
||||
static unsigned long usbTxOld = 0;
|
||||
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(millis() > starttime + POWER_FAIL_TIME){
|
||||
// Timer1.detach(); // Stop Timer1
|
||||
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).
|
||||
// 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");
|
||||
}
|
||||
else{
|
||||
display.print("LOT");
|
||||
}
|
||||
}
|
||||
else{
|
||||
undervoltage = false;
|
||||
display.print("No GPS data");
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
|
@ -33,6 +33,6 @@ void setBlinkingLED(bool on); // Set blinking LED active
|
|||
void buzzer(uint frequency, uint duration); // Buzzer function
|
||||
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
|
|
@ -205,15 +205,18 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
|
|||
rotation = 0.04 + float(random(0, 10)) / 100.0;
|
||||
}
|
||||
rotation = rotation * 57.2958; // Unit conversion form rad/s to deg/s
|
||||
result.unit = "deg/s";
|
||||
if(rotation < 10){
|
||||
snprintf(buffer,bsize,"%2.1f",rotation);
|
||||
result.unit = "Deg/s";
|
||||
if(rotation < -100){
|
||||
rotation = -99;
|
||||
}
|
||||
if(rotation >= 10 && rotation < 100){
|
||||
snprintf(buffer,bsize,"%2.1f",rotation);
|
||||
if(rotation > 100){
|
||||
rotation = 99;
|
||||
}
|
||||
if(rotation >= 100){
|
||||
snprintf(buffer,bsize,"%3.0f",rotation);
|
||||
if(rotation > -10 && rotation < 10){
|
||||
snprintf(buffer,bsize,"%1.1f",rotation);
|
||||
}
|
||||
if(rotation <= -10 || rotation >= 10){
|
||||
snprintf(buffer,bsize,"%2.0f",rotation);
|
||||
}
|
||||
}
|
||||
//########################################################
|
||||
|
|
|
@ -7,6 +7,9 @@ class PageOneValue : public Page{
|
|||
GwConfigHandler *config = commonData.config;
|
||||
GwLog *logger=commonData.logger;
|
||||
|
||||
static String svalue1old = "";
|
||||
static String unit1old = "";
|
||||
|
||||
// Get config data
|
||||
String lengthformat = config->getString(config->lengthFormat);
|
||||
bool simulation = config->getBool(config->useSimuData);
|
||||
|
@ -16,12 +19,13 @@ class PageOneValue : public Page{
|
|||
String backlightMode = config->getString(config->backlight);
|
||||
|
||||
// Get boat values
|
||||
GwApi::BoatValue *bvalue=pageData.values[0]; // First element in list (only one value by PageOneValue)
|
||||
String name1 = bvalue->getName().c_str(); // Value name
|
||||
GwApi::BoatValue *bvalue1 = pageData.values[0]; // First element in list (only one value by PageOneValue)
|
||||
String name1 = bvalue1->getName().c_str(); // Value name
|
||||
name1 = name1.substring(0, 6); // String length limit for value name
|
||||
double value1 = bvalue->value; // Value as double in SI unit
|
||||
String svalue1 = formatValue(bvalue, commonData).svalue; // Formatted value as string including unit conversion and switching decimal places
|
||||
String unit1 = formatValue(bvalue, commonData).unit; // Unit of value
|
||||
double value1 = bvalue1->value; // Value as double in SI unit
|
||||
bool valid1 = bvalue1->valid; // Valid information
|
||||
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)
|
||||
if(String(flashLED) == "Limit Violation"){
|
||||
|
@ -30,13 +34,13 @@ class PageOneValue : public Page{
|
|||
}
|
||||
|
||||
// Logging boat values
|
||||
if (bvalue == NULL) return;
|
||||
if (bvalue1 == NULL) return;
|
||||
LOG_DEBUG(GwLog::LOG,"Drawing at PageOneValue, p=%s, v=%f", name1, value1);
|
||||
|
||||
// Draw page
|
||||
//***********************************************************
|
||||
|
||||
// Clear display, set background color and text color
|
||||
// Set background color and text color
|
||||
int textcolor = GxEPD_BLACK;
|
||||
int pixelcolor = GxEPD_BLACK;
|
||||
int bgcolor = GxEPD_WHITE;
|
||||
|
@ -50,7 +54,7 @@ class PageOneValue : public Page{
|
|||
pixelcolor = GxEPD_WHITE;
|
||||
bgcolor = GxEPD_BLACK;
|
||||
}
|
||||
// Clear display in obp60task.cpp in main loop
|
||||
// Clear display by call in obp60task.cpp in main loop
|
||||
|
||||
// Show name
|
||||
display.setFont(&Ubuntu_Bold32pt7b);
|
||||
|
@ -60,14 +64,19 @@ class PageOneValue : public Page{
|
|||
// Show unit
|
||||
display.setFont(&Ubuntu_Bold20pt7b);
|
||||
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
|
||||
if(bvalue->getFormat() == "formatLatitude" || bvalue->getFormat() == "formatLongitude"){
|
||||
if(bvalue1->getFormat() == "formatLatitude" || bvalue1->getFormat() == "formatLongitude"){
|
||||
display.setFont(&Ubuntu_Bold20pt7b);
|
||||
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.setCursor(20, 200);
|
||||
}
|
||||
|
@ -77,12 +86,26 @@ class PageOneValue : public Page{
|
|||
}
|
||||
|
||||
// Show bus data or using simulation data
|
||||
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
|
||||
display.setFont(&Ubuntu_Bold8pt7b);
|
||||
display.setCursor(115, 290);
|
||||
if(commonData.keylock == false){
|
||||
display.print(" [ <<<<<< >>>>>> ]");
|
||||
}
|
||||
else{
|
||||
display.print(" [ Keylock active ]");
|
||||
}
|
||||
if(String(backlightMode) == "Control by Key"){
|
||||
display.setCursor(343, 290);
|
||||
display.print("[ILUM]");
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
String displaycolor = config->getString(config->displaycolor);
|
||||
bool holdvalues = config->getBool(config->holdvalues);
|
||||
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 backlightMode = config->getString(config->backlight);
|
||||
|
||||
|
@ -86,7 +86,12 @@ public:
|
|||
display.setFont(&DSEG7Classic_BoldItalic60pt7b);
|
||||
display.setCursor(20, 240);
|
||||
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
|
||||
display.print(value1,1);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ typedef struct{
|
|||
GwApi::Status status;
|
||||
GwLog *logger=NULL;
|
||||
GwConfigHandler *config=NULL;
|
||||
bool keylock = false;
|
||||
} CommonData;
|
||||
|
||||
//a base class that all pages must inherit from
|
||||
|
|
|
@ -97,12 +97,13 @@
|
|||
{
|
||||
"name": "batteryVoltage",
|
||||
"label": "Battery Voltage [V]",
|
||||
"type": "number",
|
||||
"default": "12",
|
||||
"check": "checkMinMax",
|
||||
"min": 0,
|
||||
"max": 1000,
|
||||
"description": "Fuel tank capacity [0...1000V]",
|
||||
"type": "list",
|
||||
"default": "12V",
|
||||
"description": "Battery Voltage [12V|24V]",
|
||||
"list": [
|
||||
"12V",
|
||||
"24V"
|
||||
],
|
||||
"category": "OBP60 Settings",
|
||||
"capabilities": {
|
||||
"obp60":"true"
|
||||
|
@ -376,7 +377,7 @@
|
|||
"name": "backlight",
|
||||
"label": "Backlight Mode",
|
||||
"type": "list",
|
||||
"default": "Off",
|
||||
"default": "Control by Key",
|
||||
"description": "Settings for display mode",
|
||||
"list": [
|
||||
"Off",
|
||||
|
@ -479,7 +480,7 @@
|
|||
"check": "checkMinMax",
|
||||
"min": 1,
|
||||
"max": 4,
|
||||
"default":"1",
|
||||
"default":"4",
|
||||
"category":"OBP60 Pages",
|
||||
"capabilities": {
|
||||
"obp60":"true"
|
||||
|
@ -555,7 +556,8 @@
|
|||
"category": "OBP60 Page 2",
|
||||
"capabilities": {
|
||||
"obp60":"true"
|
||||
}
|
||||
},
|
||||
"condition":[{"visiblePages":"2"},{"visiblePages":"3"},{"visiblePages":"4"}]
|
||||
},
|
||||
{
|
||||
"name": "page2value1",
|
||||
|
@ -615,7 +617,8 @@
|
|||
"category": "OBP60 Page 3",
|
||||
"capabilities": {
|
||||
"obp60":"true"
|
||||
}
|
||||
},
|
||||
"condition":[{"visiblePages":"3"},{"visiblePages":"4"}]
|
||||
},
|
||||
{
|
||||
"name": "page3value1",
|
||||
|
@ -675,7 +678,8 @@
|
|||
"category": "OBP60 Page 4",
|
||||
"capabilities": {
|
||||
"obp60":"true"
|
||||
}
|
||||
},
|
||||
"condition":[{"visiblePages":"4"}]
|
||||
},
|
||||
{
|
||||
"name": "page4value1",
|
||||
|
|
|
@ -21,11 +21,7 @@
|
|||
#include "MFD_OBP60_400x300_sw.h" // MFD with logo
|
||||
#include "Logo_OBP_400x300_sw.h" // OBP Logo
|
||||
#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;
|
||||
tNMEA0183 NMEA0183;
|
||||
|
||||
|
@ -39,6 +35,7 @@ void underVoltageDetection();
|
|||
Ticker Timer1(underVoltageDetection, 1); // Start Timer1 with maximum speed with 1ms
|
||||
Ticker Timer2(blinkingFlashLED, 500);
|
||||
|
||||
// Undervoltage function for shutdown display
|
||||
void underVoltageDetection(){
|
||||
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // V = 1/20 * Vin
|
||||
long starttime;
|
||||
|
@ -414,6 +411,8 @@ void OBP60Task(GwApi *api){
|
|||
|
||||
// Boat values for main loop
|
||||
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");
|
||||
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.update(); // Full update
|
||||
}
|
||||
// #11 Keylock
|
||||
/*
|
||||
if (keyboardMessage == 11)
|
||||
{
|
||||
commonData.keylock = !commonData.keylock; // Toggle keylock
|
||||
}
|
||||
*/
|
||||
}
|
||||
LOG_DEBUG(GwLog::LOG,"set pagenumber to %d",pageNumber);
|
||||
}
|
||||
|
@ -504,13 +510,10 @@ void OBP60Task(GwApi *api){
|
|||
api->getStatus(commonData.status);
|
||||
|
||||
// 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){
|
||||
//build some header and footer using commonData
|
||||
display.setTextColor(textcolor);
|
||||
display.setFont(&Ubuntu_Bold8pt7b);
|
||||
display.setCursor(0, 15);
|
||||
display.print("AP TCP GPS");
|
||||
displayHeader(commonData, hdop, date, time);
|
||||
}
|
||||
|
||||
// Call the particular page
|
||||
|
|
Loading…
Reference in New Issue