real bus data for depth

This commit is contained in:
Norbert Walter 2021-12-17 18:55:57 +01:00
parent 9af2fbcee8
commit 2ca4cfbd38
5 changed files with 120 additions and 47 deletions

View File

@ -31,6 +31,7 @@
#include "Logo_OBP_400x300_sw.h" // OBP Logo
#include "OBP60QRWiFi.h" // Functions lib for WiFi QR code
#include "OBP60Data.h" // Data stucture
#include "Page_0.h" // Page 0 Depth
#include "Page_1.h" // Page 1 Speed
#include "Page_2.h" // Page 2 VBat
@ -186,22 +187,24 @@ void OBP60Task(void *param){
bool hasPosition = false;
// Get some configuration data from webside
bool exampleSwitch=api->getConfig()->getConfigItem(api->getConfig()->obp60Config,true)->asBoolean();
bool exampleSwitch = api->getConfig()->getConfigItem(api->getConfig()->obp60Config,true)->asBoolean();
LOG_DEBUG(GwLog::DEBUG,"example switch ist %s",exampleSwitch?"true":"false");
bool gpsOn=api->getConfig()->getConfigItem(api->getConfig()->useGPS,true)->asBoolean();
bool bme280On=api->getConfig()->getConfigItem(api->getConfig()->useBME280,true)->asBoolean();
bool onewireOn=api->getConfig()->getConfigItem(api->getConfig()->use1Wire,true)->asBoolean();
bool gpsOn = api->getConfig()->getConfigItem(api->getConfig()->useGPS,true)->asBoolean();
bool bme280On = api->getConfig()->getConfigItem(api->getConfig()->useBME280,true)->asBoolean();
bool onewireOn = api->getConfig()->getConfigItem(api->getConfig()->use1Wire,true)->asBoolean();
busInfo.simulation = api->getConfig()->getConfigItem(api->getConfig()->useSimuData,true)->asBoolean();
String powerMode=api->getConfig()->getConfigItem(api->getConfig()->powerMode,true)->asString();
String displayMode=api->getConfig()->getConfigItem(api->getConfig()->display,true)->asString();
String backlightMode=api->getConfig()->getConfigItem(api->getConfig()->backlight,true)->asString();
// Initializing all necessary boat data
double lastWaterDepth=0;
bool lastWaterDepthValid=false;
GwApi::BoatValue *sog=new GwApi::BoatValue(F("SOG"));
GwApi::BoatValue *date=new GwApi::BoatValue(F("DaysSince1970"));
GwApi::BoatValue *time=new GwApi::BoatValue(F("SecondsSinceMidnight"));
GwApi::BoatValue *longitude=new GwApi::BoatValue(F("Longitude"));
GwApi::BoatValue *latitude=new GwApi::BoatValue(F("Latitude"));
GwApi::BoatValue *waterdepth=new GwApi::BoatValue(F("WaterDepth"));
GwApi::BoatValue *valueList[]={longitude, latitude, waterdepth};
GwApi::BoatValue *valueList[]={sog, date, time, longitude, latitude, waterdepth};
//Init E-Ink display
display.init(); // Initialize and clear display
@ -260,16 +263,6 @@ void OBP60Task(void *param){
}
}
// Subtask all 1000ms show pages
if((taskRunCounter % 100) == 0 || first_view == true){
// LOG_DEBUG(GwLog::DEBUG,"Subtask 1");
LOG_DEBUG(GwLog::DEBUG,"Keystatus: %s", keystatus);
LOG_DEBUG(GwLog::DEBUG,"Pagenumber: %d", pageNumber);
if(displayMode == "Logo + QR Code" || displayMode == "Logo" || displayMode == "White Screen"){
showPage();
}
}
// Subtask all 3000ms
if((taskRunCounter % 300) == 0){
// LOG_DEBUG(GwLog::DEBUG,"Subtask 2");
@ -279,12 +272,6 @@ void OBP60Task(void *param){
}
}
// Subtask E-Ink full refresh
if((taskRunCounter % (FULL_REFRESH_TIME * 100)) == 0){
LOG_DEBUG(GwLog::DEBUG,"E-Ink full refresh");
display.update();
}
// Send NMEA0183 GPS data on several bus systems
if(gpsOn == true){ // If config enabled
if(gps_ready = true){
@ -296,22 +283,25 @@ void OBP60Task(void *param){
}
//fetch the current values of the items that we have in itemNames
api->getBoatDataValues(3,valueList);
//check if the values are valid (i.e. the values we requested have been found in boatData)
if (waterdepth->valid){
//both values are there - so we have a valid position
if (! lastWaterDepthValid){
//access to the values via iterator->second (iterator->first would be the name)
LOG_DEBUG(GwLog::LOG,"%s new value %f",waterdepth->getName().c_str(),waterdepth->value);
lastWaterDepthValid=true;
lastWaterDepth=waterdepth->value;
api->getBoatDataValues(6,valueList);
busInfo.WaterDepth.fvalue = waterdepth->value;
busInfo.WaterDepth.valid = int(waterdepth->valid);
busInfo.SOG.fvalue = sog->value;
busInfo.SOG.valid = int(sog->valid);
// Subtask all 1000ms show pages
if((taskRunCounter % 100) == 0 || first_view == true){
LOG_DEBUG(GwLog::DEBUG,"Keystatus: %s", keystatus);
LOG_DEBUG(GwLog::DEBUG,"Pagenumber: %d", pageNumber);
if(displayMode == "Logo + QR Code" || displayMode == "Logo" || displayMode == "White Screen"){
showPage(busInfo);
}
}
else{
if (lastWaterDepthValid){
if (exampleSwitch) LOG_DEBUG(GwLog::LOG,"Water depth lost");
lastWaterDepthValid=false;
}
// Subtask E-Ink full refresh
if((taskRunCounter % (FULL_REFRESH_TIME * 100)) == 0){
LOG_DEBUG(GwLog::DEBUG,"E-Ink full refresh");
display.update();
}
taskRunCounter++;

54
lib/obp60task/OBP60Data.h Normal file
View File

@ -0,0 +1,54 @@
#ifndef _OBP60Data_H
#define _OBP60Data_H
#include <Arduino.h>
typedef struct{
float fvalue = 0; // Float value
char svalue[31] = ""; // Char value
int valid = 0; // Valid flag
} dataContainer;
typedef struct{
bool simulation = false; // Simulate boat data
dataContainer AWA;
dataContainer AWD;
dataContainer AWS;
dataContainer Altitude;
dataContainer BTW;
dataContainer COG;
dataContainer DTW;
dataContainer Date;
dataContainer DepthTransducer;
dataContainer Deviation;
dataContainer HDOP;
dataContainer Heading;
dataContainer Latitude;
dataContainer Log;
dataContainer Longitude;
dataContainer MagneticHeading;
dataContainer MaxAws;
dataContainer MaxTws;
dataContainer PDOP;
dataContainer ROT;
dataContainer RudderPosition;
dataContainer SOG;
dataContainer STW;
dataContainer SatInfo;
dataContainer Time;
dataContainer TWD;
dataContainer TWS;
dataContainer Timezone;
dataContainer TripLog;
dataContainer VDOP;
dataContainer Variation;
dataContainer WPLatitude;
dataContainer WPLongitude;
dataContainer WaterDepth;
dataContainer WaterTemperature;
dataContainer XTE;
} busData;
busData busInfo;
#endif

View File

@ -7,8 +7,7 @@
int pageNumber = 0; // Page number for actual page
bool first_view = true;
void showPage(){
void showPage(busData values){
// Clear display
display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE); // Draw white sreen
@ -24,7 +23,7 @@ void showPage(){
// Read page number
switch (pageNumber) {
case 0:
page_0();
page_0(values);
break;
case 1:
page_1();
@ -42,7 +41,7 @@ void showPage(){
// Statement(s)
break;
default:
page_0();
page_0(values);
break;
}

View File

@ -4,7 +4,7 @@
#include <Arduino.h>
#include "OBP60Hardware.h"
void page_0(){
void page_0(busData pvalues){
// Measuring Values
display.setFont(&Ubuntu_Bold32pt7b);
display.setTextColor(GxEPD_BLACK);
@ -15,9 +15,28 @@ void page_0(){
display.print("m");
display.setFont(&DSEG7Classic_BoldItalic60pt7b);
display.setCursor(20, 240);
float depth = 84;
depth += float(random(0, 13)) / 10;
// Reading bus data or using simulation data
float depth = 0;
if(pvalues.simulation == true){
depth = 84;
depth += float(random(0, 120)) / 10; // Simulation data
display.print(depth,1);
}
else{
if(pvalues.WaterDepth.valid == true){ // Check vor valid real data
depth = pvalues.WaterDepth.fvalue; // Real bus data
if(depth <= 99.9){
display.print(depth,1);
}
else{
display.print(depth,0);
}
}
else{
display.print("---"); // Missing bus data
}
}
// Key Layout
display.setFont(&Ubuntu_Bold8pt7b);

View File

@ -60,6 +60,17 @@
"obp60":"true"
}
},
{
"name": "useSimuData",
"label": "Simulation Data",
"type": "boolean",
"default": "false",
"description": "Can use for simulation data by missing bus data.",
"category": "OBP60",
"capabilities": {
"obp60":"true"
}
},
{
"name": "display",
"label": "Display Mode",