Add unit parameter and unit conversion

This commit is contained in:
norbert-walter 2022-01-14 15:43:26 +01:00
parent 25c9ec0afe
commit 9d0799f2cf
6 changed files with 164 additions and 42 deletions

View File

@ -235,6 +235,11 @@ void OBP60Task(void *param){
// OBP60 Settings
bool exampleSwitch = api->getConfig()->getConfigItem(api->getConfig()->obp60Config,true)->asBoolean();
LOG_DEBUG(GwLog::DEBUG,"example switch ist %s",exampleSwitch?"true":"false");
api->getConfig()->getConfigItem(api->getConfig()->lengthFormat,true)->asString().toCharArray(busInfo.lengthformat, 16);
api->getConfig()->getConfigItem(api->getConfig()->distanceFormat,true)->asString().toCharArray(busInfo.distanceformat, 16);
api->getConfig()->getConfigItem(api->getConfig()->speedFormat,true)->asString().toCharArray(busInfo.speedformat, 16);
api->getConfig()->getConfigItem(api->getConfig()->windspeedFormat,true)->asString().toCharArray(busInfo.windspeedformat, 16);
api->getConfig()->getConfigItem(api->getConfig()->tempFormat,true)->asString().toCharArray(busInfo.tempformat, 16);
api->getConfig()->getConfigItem(api->getConfig()->dateFormat,true)->asString().toCharArray(busInfo.dateformat, 3);
busInfo.timezone = api->getConfig()->getConfigItem(api->getConfig()->timeZone,true)->asInt();
busInfo.draft = api->getConfig()->getConfigItem(api->getConfig()->draft,true)->asString().toFloat();
@ -255,6 +260,7 @@ void OBP60Task(void *param){
api->getConfig()->getConfigItem(api->getConfig()->display,true)->asString().toCharArray(busInfo.displaymode, 16);
busInfo.statusline = api->getConfig()->getConfigItem(api->getConfig()->statusLine,true)->asBoolean();
busInfo.refresh = api->getConfig()->getConfigItem(api->getConfig()->refresh,true)->asBoolean();
busInfo.holdvalues = api->getConfig()->getConfigItem(api->getConfig()->holdvalues,true)->asBoolean();
api->getConfig()->getConfigItem(api->getConfig()->backlight,true)->asString().toCharArray(busInfo.backlight, 16);
api->getConfig()->getConfigItem(api->getConfig()->powerMode,true)->asString().toCharArray(busInfo.powermode, 16);
// OBP60 Buzzer

View File

@ -7,7 +7,7 @@
#define ESP32_CAN_TX_PIN GPIO_NUM_13
#define ESP32_CAN_RX_PIN GPIO_NUM_12
// Bus load in 50mA steps
#define N2K_LOAD_LEVEL 5 // 250mA max bus load with back light on
#define N2K_LOAD_LEVEL 5 // 5x50mA = 250mA max bus load with back light on
// RS485 NMEA0183
#define GWSERIAL_TX 26
#define GWSERIAL_RX 14

View File

@ -3,6 +3,10 @@
#include <Arduino.h>
float convert_m2ft(float inputvalue){
return inputvalue * 3.28084;
}
typedef struct{ // Sub structure for bus data
float fvalue = 0; // Float value
char svalue[16] = ""; // Char value
@ -38,7 +42,12 @@ typedef struct{
char wificlientssid[32] = ""; // Wifi client SSID
char wificlientpass[32] = ""; // Wifi client password
// OBP60 Settings
char dateformat[3] = "GB"; // Date format for status line [DE|GB|US]
char lengthformat[16] = ""; // Length format [m|ft]
char distanceformat[16] = ""; // Distance format [m|km|nm]
char speedformat[16] = ""; // Speed format [m/s|km/h|kn]
char windspeedformat[16] = ""; // Speed format [m/s|km/h|kn|bft]
char tempformat[16] = ""; // Temperature format [K|C|F]
char dateformat[3] = ""; // Date format for status line [DE|GB|US]
int timezone = 0; // Time zone [-12...+12]
float draft = 0; // Boat draft up to keel [m]
float fueltank = 0; // Fuel tank capacity [0...10m]
@ -46,25 +55,26 @@ typedef struct{
float watertank = 0; // Water tank kapacity [0...5000l]
float wastetank = 0; // Waste tank kapacity [0...5000l]
float batvoltage = 0; // Battery voltage [0...1000V]
char battype[16] = "Pb"; // Battery type [Pb|Gel|AGM|LiFePo4]
char battype[16] = ""; // Battery type [Pb|Gel|AGM|LiFePo4]
float batcapacity = 0; // Battery capacity [0...10000Ah]
// OBP60 Hardware
bool gps = false; // Internal GPS [on|off]
bool bme280 = false; // Internat BME280 [on|off]
bool onewire = false; // Internal 1Wire bus [on|off]
char powermode[16] = "Max Power"; // Power mode [Max Power|Only 3.3V|Only 5.0V|Min Power]
char powermode[16] = ""; // Power mode [Max Power|Only 3.3V|Only 5.0V|Min Power]
bool simulation = false; // Simulation data [on|off]
// OBP60 Display
char displaymode[16] = "Logo + QR Code"; // Dislpay mode [White Screen|Logo|Logo + QR Code|Off]
char displaymode[16] = ""; // Dislpay mode [White Screen|Logo|Logo + QR Code|Off]
bool statusline = true; // Show status line [on|off]
bool refresh = false; // Refresh display after select a new page [on|off]
char backlight[16] = "Control by Key"; // Backlight mode [Off|Control by Sun|Control by Bus|Control by Time|Control by Key|On]
char flashled[16] = "Off"; // Flash LED mode [Off|Bus Data|GPX Fix|Limits Overrun]
bool holdvalues = false; // Hold values on missing data stream [on|off]
char backlight[16] = ""; // Backlight mode [Off|Control by Sun|Control by Bus|Control by Time|Control by Key|On]
char flashled[16] = ""; // Flash LED mode [Off|Bus Data|GPX Fix|Limits Overrun]
// OBP60 Buzzer
bool buzerror = false; // Buzzer error [on|off]
bool buzgps = false; // Buzzer by GPS error [on|off]
bool buzlimits = false; // Buzzer by limit underruns and overruns [on|off]
char buzmode[16] = "Off"; // Buzzer mode [Off|Short Single Beep|Lond Single Beep|Beep until Confirmation]
char buzmode[16] = ""; // Buzzer mode [Off|Short Single Beep|Lond Single Beep|Beep until Confirmation]
int buzpower = 0; // Buzzer power [0...100%]
// OBP60 Pages
int numpages = 1; // Numper of listed pages

View File

@ -1,4 +1,5 @@
// Other pin definititins see GwOBP60Task.h
// General hardware definitions
// CAN bus pin definitions see GwOBP60Task.h
// Direction pin for RS485 NMEA0183
#define OBP_DIRECTION_PIN 27

View File

@ -5,14 +5,20 @@
#include "OBP60Hardware.h"
void page_0(busData pvalues){
// Name and unit
// Show name
display.setFont(&Ubuntu_Bold32pt7b);
display.setTextColor(GxEPD_BLACK);
display.setCursor(20, 100);
display.print("Depth");
display.setFont(&Ubuntu_Bold20pt7b);
display.setCursor(270, 100);
// Show unit
if(String(pvalues.lengthformat) == "m"){
display.print("m");
}
if(String(pvalues.lengthformat) == "ft"){
display.print("ft");
}
display.setFont(&DSEG7Classic_BoldItalic60pt7b);
display.setCursor(20, 240);
@ -24,8 +30,16 @@ void page_0(busData pvalues){
display.print(depth,1);
}
else{
if(pvalues.WaterDepth.valid == true){ // Check vor valid real data
depth = pvalues.WaterDepth.fvalue; // Real bus data
// Check vor valid real data, display also if hold values activated
if(pvalues.WaterDepth.valid == true || pvalues.holdvalues == true){
// Unit conversion
if(String(pvalues.lengthformat) == "m"){
depth = pvalues.WaterDepth.fvalue; // Real bus data m
}
if(String(pvalues.lengthformat) == "ft"){
depth = convert_m2ft(pvalues.WaterDepth.fvalue); // Bus data in ft
}
// Resolution switching
if(depth <= 99.9){
display.print(depth,1);
}

View File

@ -10,22 +10,6 @@
"obp60":"true"
}
},
{
"name": "dateFormat",
"label": "Date Format",
"type": "list",
"default": "GB",
"description": "Date format [DE|GB|US] DE: 31.12.2022, GB: 31/12/2022, US: 12/31/2022",
"list": [
"DE",
"GB",
"US"
],
"category": "OBP60 Settings",
"capabilities": {
"obp60":"true"
}
},
{
"name": "timeZone",
"label": "Time Zone",
@ -155,6 +139,102 @@
"obp60":"true"
}
},
{
"name": "lengthFormat",
"label": "Length Format",
"type": "list",
"default": "m",
"description": "Length format [m|ft]",
"list": [
"m",
"ft"
],
"category": "OBP60 Units",
"capabilities": {
"obp60":"true"
}
},
{
"name": "distanceFormat",
"label": "Distance Format",
"type": "list",
"default": "m",
"description": "Distance format [m|km|nm]",
"list": [
"m",
"km",
"nm"
],
"category": "OBP60 Units",
"capabilities": {
"obp60":"true"
}
},
{
"name": "speedFormat",
"label": "Speed Format",
"type": "list",
"default": "m/s",
"description": "Distance format [m/s|km/h|kn]",
"list": [
"m/s",
"km/h",
"kn"
],
"category": "OBP60 Units",
"capabilities": {
"obp60":"true"
}
},
{
"name": "windspeedFormat",
"label": "Wind Speed Format",
"type": "list",
"default": "m/s",
"description": "Distance format [m/s|km/h|kn|bft]",
"list": [
"m/s",
"km/h",
"kn",
"bft"
],
"category": "OBP60 Units",
"capabilities": {
"obp60":"true"
}
},
{
"name": "tempFormat",
"label": "Temperature Format",
"type": "list",
"default": "C",
"description": "Length format [K|°C|°F]",
"list": [
"K",
"C",
"F"
],
"category": "OBP60 Units",
"capabilities": {
"obp60":"true"
}
},
{
"name": "dateFormat",
"label": "Date Format",
"type": "list",
"default": "GB",
"description": "Date format [DE|GB|US] DE: 31.12.2022, GB: 31/12/2022, US: 12/31/2022",
"list": [
"DE",
"GB",
"US"
],
"category": "OBP60 Units",
"capabilities": {
"obp60":"true"
}
},
{
"name": "useGPS",
"label": "GPS NEO-6M",
@ -235,7 +315,7 @@
},
{
"name": "statusLine",
"label": "Status line",
"label": "Status Line",
"type": "boolean",
"default": "true",
"description": "Show status line [on|off]",
@ -255,6 +335,17 @@
"obp60":"true"
}
},
{
"name": "holdvalues",
"label": "Hold Values",
"type": "boolean",
"default": "false",
"description": "Hold old measuring values by missing data stream [on|off]",
"category": "OBP60 Display",
"capabilities": {
"obp60":"true"
}
},
{
"name": "backlight",
"label": "Backlight Mode",
@ -296,7 +387,7 @@
"label": "Buzzer Error",
"type": "boolean",
"default": "false",
"description": "Settings for buzzer",
"description": "Sound on error",
"category": "OBP60 Buzzer",
"capabilities": {
"obp60":"true"
@ -307,7 +398,7 @@
"label": "Buzzer GPS Fix",
"type": "boolean",
"default": "false",
"description": "Settings for buzzer",
"description": "Sound on missing or lost GPS fix",
"category": "OBP60 Buzzer",
"capabilities": {
"obp60":"true"
@ -318,7 +409,7 @@
"label": "Buzzer by Limits",
"type": "boolean",
"default": "false",
"description": "Tone by limit overrun",
"description": "Sound on limit overrun",
"category": "OBP60 Buzzer",
"capabilities": {
"obp60":"true"