Compare commits

..

No commits in common. "c932724473c2b231931a7e7e73db0dc77d986a31" and "cba21574cbe5caefee3083f1aa0613179054e8cd" have entirely different histories.

16 changed files with 222 additions and 323 deletions

View File

@ -474,7 +474,6 @@ void displayHeader(CommonData &commonData, bool symbolmode, GwApi::BoatValue *da
uint16_t symbol_x = 2; uint16_t symbol_x = 2;
static const uint16_t symbol_offset = 20; static const uint16_t symbol_offset = 20;
// TODO invert and get rid of the if
if(commonData.config->getBool(commonData.config->statusLine) == true){ if(commonData.config->getBool(commonData.config->statusLine) == true){
// Show status info // Show status info
@ -584,7 +583,7 @@ void displayHeader(CommonData &commonData, bool symbolmode, GwApi::BoatValue *da
heartbeat = !heartbeat; heartbeat = !heartbeat;
// Date and time // Date and time
fmtDate fmttype = commonData.fmt->getDateFormat(commonData.config->getString(commonData.config->dateFormat)); String fmttype = commonData.config->getString(commonData.config->dateFormat);
String timesource = commonData.config->getString(commonData.config->timeSource); String timesource = commonData.config->getString(commonData.config->timeSource);
double tz = commonData.config->getString(commonData.config->timeZone).toDouble(); double tz = commonData.config->getString(commonData.config->timeZone).toDouble();
epd->setTextColor(commonData.fgcolor); epd->setTextColor(commonData.fgcolor);
@ -595,7 +594,7 @@ void displayHeader(CommonData &commonData, bool symbolmode, GwApi::BoatValue *da
if (commonData.data.rtcValid) { if (commonData.data.rtcValid) {
time_t tv = mktime(&commonData.data.rtcTime) + (int)(tz * 3600); time_t tv = mktime(&commonData.data.rtcTime) + (int)(tz * 3600);
struct tm *local_tm = localtime(&tv); struct tm *local_tm = localtime(&tv);
epd->print(formatTime(fmtTime::MMHH, local_tm->tm_hour, local_tm->tm_min, 0)); epd->print(formatTime('m', local_tm->tm_hour, local_tm->tm_min, 0));
epd->print(" "); epd->print(" ");
epd->print(formatDate(fmttype, local_tm->tm_year + 1900, local_tm->tm_mon + 1, local_tm->tm_mday)); epd->print(formatDate(fmttype, local_tm->tm_year + 1900, local_tm->tm_mon + 1, local_tm->tm_mday));
epd->print(" "); epd->print(" ");

View File

@ -20,7 +20,6 @@ Formatter::Formatter(GwConfigHandler *config) {
windspeedFormat = config->getString(config->windspeedFormat); windspeedFormat = config->getString(config->windspeedFormat);
tempFormat = config->getString(config->tempFormat); tempFormat = config->getString(config->tempFormat);
dateFormat = config->getString(config->dateFormat); dateFormat = config->getString(config->dateFormat);
dateFmt = getDateFormat(dateFormat);
usesimudata = config->getBool(config->useSimuData); usesimudata = config->getBool(config->useSimuData);
precision = config->getString(config->valueprecision); precision = config->getString(config->valueprecision);
@ -36,37 +35,6 @@ Formatter::Formatter(GwConfigHandler *config) {
} }
fmtType Formatter::stringToFormat(const char* formatStr) {
auto it = formatMap.find(formatStr);
if (it != formatMap.end()) {
return it->second;
}
return fmtType::XDR_G; // generic as default
}
fmtDate Formatter::getDateFormat(String sformat) {
if (sformat == "DE") {
return fmtDate::DE;
}
if (sformat == "GB") {
return fmtDate::GB;
}
if (sformat == "US") {
return fmtDate::US;
}
return fmtDate::ISO; // default
}
fmtTime Formatter::getTimeFormat(String sformat) {
if (sformat == "MMHH") {
return fmtTime::MMHH;
}
if (sformat == "MMHHSS") {
return fmtTime::MMHHSS;
}
return fmtTime::MMHH; // default
}
FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &commondata){ FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &commondata){
GwLog *logger = commondata.logger; GwLog *logger = commondata.logger;
FormattedData result; FormattedData result;
@ -75,7 +43,7 @@ FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &common
// If boat value not valid // If boat value not valid
if (! value->valid && !usesimudata){ if (! value->valid && !usesimudata){
result.svalue = placeholder; result.svalue = "---";
return result; return result;
} }
@ -118,7 +86,12 @@ FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &common
else{ else{
snprintf(buffer, bsize, "01.01.2022"); snprintf(buffer, bsize, "01.01.2022");
} }
result.unit = ((timeZone == 0) ? "UTC" : "LOT"); if(timeZone == 0){
result.unit = "UTC";
}
else{
result.unit = "LOT";
}
} }
//######################################################## //########################################################
else if(value->getFormat() == "formatTime"){ else if(value->getFormat() == "formatTime"){
@ -148,7 +121,12 @@ FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &common
snprintf(buffer, bsize, "11:36:%02i", int(sec)); snprintf(buffer, bsize, "11:36:%02i", int(sec));
lasttime = millis(); lasttime = millis();
} }
result.unit = ((timeZone == 0) ? "UTC" : "LOT"); if(timeZone == 0){
result.unit = "UTC";
}
else{
result.unit = "LOT";
}
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatFixed0"){ else if (value->getFormat() == "formatFixed0"){
@ -308,13 +286,13 @@ FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &common
if (rotation < -100){ if (rotation < -100){
rotation = -99; rotation = -99;
} }
else if (rotation > 100){ if (rotation > 100){
rotation = 99; rotation = 99;
} }
if (rotation > -10 && rotation < 10){ if (rotation > -10 && rotation < 10){
snprintf(buffer, bsize, "%3.2f", rotation); snprintf(buffer, bsize, "%3.2f", rotation);
} }
else { if (rotation <= -10 || rotation >= 10){
snprintf(buffer, bsize, "%3.0f", rotation); snprintf(buffer, bsize, "%3.0f", rotation);
} }
} }
@ -352,7 +330,12 @@ FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &common
String latdir = ""; String latdir = "";
float degree = abs(int(lat)); float degree = abs(int(lat));
float minute = abs((lat - int(lat)) * 60); float minute = abs((lat - int(lat)) * 60);
latdir = (lat > 0) ? "N" : "S"; if (lat > 0){
latdir = "N";
}
else {
latdir = "S";
}
latitude = String(degree,0) + "\x90 " + String(minute,4) + "' " + latdir; latitude = String(degree,0) + "\x90 " + String(minute,4) + "' " + latdir;
result.unit = ""; result.unit = "";
strcpy(buffer, latitude.c_str()); strcpy(buffer, latitude.c_str());
@ -371,7 +354,12 @@ FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &common
String londir = ""; String londir = "";
float degree = abs(int(lon)); float degree = abs(int(lon));
float minute = abs((lon - int(lon)) * 60); float minute = abs((lon - int(lon)) * 60);
londir = (lon > 0) ? "E" : "W"; if (lon > 0){
londir = "E";
}
else {
londir = "W";
}
longitude = String(degree,0) + "\x90 " + String(minute,4) + "' " + londir; longitude = String(degree,0) + "\x90 " + String(minute,4) + "' " + londir;
result.unit = ""; result.unit = "";
strcpy(buffer, longitude.c_str()); strcpy(buffer, longitude.c_str());
@ -393,7 +381,7 @@ FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &common
depth = rawvalue; depth = rawvalue;
} }
if(String(lengthFormat) == "ft"){ if(String(lengthFormat) == "ft"){
depth = depth * 3.28084; // TODO use global defined factor depth = depth * 3.28084;
result.unit = "ft"; result.unit = "ft";
} }
else{ else{
@ -423,7 +411,7 @@ FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &common
xte = xte * 0.001; xte = xte * 0.001;
result.unit = "km"; result.unit = "km";
} else if (distanceFormat == "nm") { } else if (distanceFormat == "nm") {
xte = xte * 0.000539957; // TODO use global defined factor xte = xte * 0.000539957;
result.unit = "nm"; result.unit = "nm";
} else { } else {
result.unit = "m"; result.unit = "m";
@ -459,7 +447,7 @@ FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &common
else{ else{
result.unit = "K"; result.unit = "K";
} }
if (temp < 10) { if(temp < 10) {
snprintf(buffer, bsize, fmt_dec_1, temp); snprintf(buffer, bsize, fmt_dec_1, temp);
} }
else if (temp < 100) { else if (temp < 100) {
@ -485,7 +473,7 @@ FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &common
result.unit = "km"; result.unit = "km";
} }
else if (String(distanceFormat) == "nm") { else if (String(distanceFormat) == "nm") {
distance = distance * 0.000539957; // TODO use global defined factor distance = distance * 0.000539957;
result.unit = "nm"; result.unit = "nm";
} }
else { else {
@ -814,35 +802,31 @@ FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &common
return result; return result;
} }
String formatDate(fmtDate fmttype, uint16_t year, uint8_t month, uint8_t day) { String formatDate(String fmttype, uint16_t year, uint8_t month, uint8_t day) {
char buffer[12]; char buffer[12];
if (fmttype == fmtDate::GB) { if (fmttype == "GB") {
snprintf(buffer, 12, "%02d/%02d/%04d", day , month, year); snprintf(buffer, 12, "%02d/%02d/%04d", day , month, year);
} }
else if (fmttype == fmtDate::US) { else if (fmttype == "US") {
snprintf(buffer, 12, "%02d/%02d/%04d", month, day, year); snprintf(buffer, 12, "%02d/%02d/%04d", month, day, year);
} }
else if (fmttype == fmtDate::ISO) { else if (fmttype == "ISO") {
snprintf(buffer, 12, "%04d-%02d-%02d", year, month, day); snprintf(buffer, 12, "%04d-%02d-%02d", year, month, day);
} }
else if (fmttype == fmtDate::DE) { else {
snprintf(buffer, 12, "%02d.%02d.%04d", day, month, year); snprintf(buffer, 12, "%02d.%02d.%04d", day, month, year);
} else {
snprintf(buffer, 12, "%04d-%02d-%02d", year, month, day);
} }
return String(buffer); return String(buffer);
} }
String formatTime(fmtTime fmttype, uint8_t hour, uint8_t minute, uint8_t second) { String formatTime(char fmttype, uint8_t hour, uint8_t minute, uint8_t second) {
// fmttype: s: with seconds, m: only minutes
char buffer[10]; char buffer[10];
if (fmttype == fmtTime::MMHH) { if (fmttype == 'm') {
snprintf(buffer, 10, "%02d:%02d", hour , minute); snprintf(buffer, 10, "%02d:%02d", hour , minute);
} }
else if (fmttype == fmtTime::MMHHSS) {
snprintf(buffer, 10, "%02d:%02d:%02d", hour, minute, second);
}
else { else {
snprintf(buffer, 10, "%02d%02d%02d", hour, minute, second); snprintf(buffer, 10, "%02d:%02d:%02d", hour, minute, second);
} }
return String(buffer); return String(buffer);
} }

View File

@ -2,10 +2,41 @@
#ifndef _OBP60FORMATTER_H #ifndef _OBP60FORMATTER_H
#define _OBP60FORMATTER_H #define _OBP60FORMATTER_H
#include <unordered_map>
/* /*
Formatter names as defined in BoatItemBase
formatCourse
formatKnots
formatWind
formatLatitude
formatLongitude
formatXte
formatFixed0
formatDepth
kelvinToC TODO not a format but conversion
mtr2nm TODO not a format but conversion
formatDop dilution of precision
formatRot
formatDate
formatTime
formatName
XDR Formatter names
formatXdr:P:P // pressure percent
formatXdr:P:B // pressure bar
formatXdr:U:V // voltage volt
formatXdr:I:A // current ampere
formatXdr:C:K // temperature kelvin
formatXdr:C:C // temperature celsius
formatXdr:H:P // humidity percent
formatXdr:V:P // volume percent
formatXdr:V:M // volume cubic meters
formatXdr:R:I // flow liter per second?
formatXdr:G: // generic
formatXdr:A:P // angle percent
formatXdr:A:D // angle degrees
formatXdr:T:R // tachometer rpm
XDR types XDR types
A Angular displacement A Angular displacement
C Temperature C Temperature
@ -38,77 +69,8 @@ XDR units
*/ */
enum class fmtType {
// Formatter names as defined in BoatItemBase
COURSE,
KNOTS,
WIND,
LATITUDE,
LONGITUDE,
XTE,
FIXED0,
DEPTH,
DOP, // dilution of precision
ROT,
DATE,
TIME,
NAME,
kelvinToC, // TODO not a format but conversion
mtr2nm, // TODO not a format but conversion
// XDR Formatter names
XDR_PP, // pressure percent
XDR_PB, // pressure bar
XDR_UV, // voltage volt
XDR_IA, // current ampere
XDR_CK, // temperature kelvin
XDR_CC, // temperature celsius
XDR_HP, // humidity percent
XDR_VP, // volume percent
XDR_VM, // volume cubic meters
XDR_RI, // flow liter per second?
XDR_G, // generic
XDR_AP, // angle percent
XDR_AD, // angle degrees
XDR_TR // tachometer rpm
};
// Hint: String is not supported
static std::unordered_map<const char*, fmtType> formatMap PROGMEM = {
{"formatCourse", fmtType::COURSE},
{"formatKnots", fmtType::KNOTS},
{"formatWind", fmtType::WIND},
{"formatLatitude", fmtType::LATITUDE},
{"formatLongitude", fmtType::LONGITUDE},
{"formatXte", fmtType::XTE},
{"formatFixed0", fmtType::FIXED0},
{"formatDepth", fmtType::DEPTH},
{"formatDop", fmtType::DOP},
{"formatRot", fmtType::ROT},
{"formatDate", fmtType::DATE},
{"formatTime", fmtType::TIME},
{"formatName", fmtType::NAME},
{"kelvinToC", fmtType::kelvinToC},
{"mtr2nm", fmtType::mtr2nm},
{"formatXdr:P:P", fmtType::XDR_PP},
{"formatXdr:P:B", fmtType::XDR_PB},
{"formatXdr:U:V", fmtType::XDR_UV},
{"formatXdr:I:A", fmtType::XDR_IA},
{"formatXdr:C:K", fmtType::XDR_CK},
{"formatXdr:C:C", fmtType::XDR_CC},
{"formatXdr:H:P", fmtType::XDR_HP},
{"formatXdr:V:P", fmtType::XDR_VP},
{"formatXdr:V:M", fmtType::XDR_VM},
{"formatXdr:R:I", fmtType::XDR_RI},
{"formatXdr:G:", fmtType::XDR_G},
{"formatXdr:A:P", fmtType::XDR_AP},
{"formatXdr:A:D", fmtType::XDR_AD},
{"formatXdr:T:R", fmtType::XDR_TR}
};
// Possible formats as scoped enums // Possible formats as scoped enums
enum class fmtDate {DE, GB, US, ISO}; enum class fmtDate {DE, EN, GB, ISO};
enum class fmtTime {MMHH, MMHHSS}; enum class fmtTime {MMHH, MMHHSS};
enum class fmtLength {METER, FEET, FATHOM, CABLE}; enum class fmtLength {METER, FEET, FATHOM, CABLE};
enum class fmtDepth {METER, FEET, FATHOM}; enum class fmtDepth {METER, FEET, FATHOM};
@ -144,7 +106,6 @@ private:
String windspeedFormat = "kn"; // [m/s|km/h|kn|bft] String windspeedFormat = "kn"; // [m/s|km/h|kn|bft]
String tempFormat = "C"; // [K|°C|°F] String tempFormat = "C"; // [K|°C|°F]
String dateFormat = "ISO"; // [DE|GB|US|ISO] String dateFormat = "ISO"; // [DE|GB|US|ISO]
fmtDate dateFmt;
bool usesimudata = false; // [on|off] bool usesimudata = false; // [on|off]
String precision = "2"; // [1|2] String precision = "2"; // [1|2]
@ -154,16 +115,12 @@ private:
public: public:
Formatter(GwConfigHandler *config); Formatter(GwConfigHandler *config);
fmtType stringToFormat(const char* formatStr);
fmtDate getDateFormat(String sformat);
fmtTime getTimeFormat(String sformat);
FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata); FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata);
String placeholder = "---";
}; };
// Standard format functions without class and overhead // Standard format functions without overhead
String formatDate(fmtDate fmttype, uint16_t year, uint8_t month, uint8_t day); String formatDate(String fmttype, uint16_t year, uint8_t month, uint8_t day);
String formatTime(fmtTime fmttype, uint8_t hour, uint8_t minute, uint8_t second); String formatTime(char fmttype, uint8_t hour, uint8_t minute, uint8_t second);
String formatLatitude(double lat); String formatLatitude(double lat);
String formatLongitude(double lon); String formatLongitude(double lon);

View File

@ -227,7 +227,7 @@ public:
epd->print(value1,2); // Real value as formated string epd->print(value1,2); // Real value as formated string
} }
else{ else{
epd->print(commonData->fmt->placeholder); // No sensor data (sensor is off) epd->print("---"); // No sensor data (sensor is off)
} }
// ############### Horizontal Line ################ // ############### Horizontal Line ################
@ -256,7 +256,7 @@ public:
epd->print(value2,1); // Real value as formated string epd->print(value2,1); // Real value as formated string
} }
else{ else{
epd->print(commonData->fmt->placeholder); // No sensor data (sensor is off) epd->print("---"); // No sensor data (sensor is off)
} }
// ############### Horizontal Line ################ // ############### Horizontal Line ################
@ -285,7 +285,7 @@ public:
epd->print(value3,1); // Real value as formated string epd->print(value3,1); // Real value as formated string
} }
else{ else{
epd->print(commonData->fmt->placeholder); // No sensor data (sensor is off) epd->print("---"); // No sensor data (sensor is off)
} }
return PAGE_UPDATE; return PAGE_UPDATE;

View File

@ -286,7 +286,7 @@ public:
if(value1 > 99.9) epd->print(value1, 0); if(value1 > 99.9) epd->print(value1, 0);
} }
else{ else{
epd->print(commonData->fmt->placeholder); // Missing bus data epd->print("---"); // Missing bus data
} }
} }
epd->setFont(&Ubuntu_Bold16pt8b); epd->setFont(&Ubuntu_Bold16pt8b);
@ -300,9 +300,7 @@ public:
if(value2 > 9.9 && value2 <= 99.9)epd->print(value2, 1); if(value2 > 9.9 && value2 <= 99.9)epd->print(value2, 1);
if(value2 > 99.9) epd->print(value2, 0); if(value2 > 99.9) epd->print(value2, 0);
} }
else { else epd->print("---");
epd->print(commonData->fmt->placeholder);
}
epd->setFont(&Ubuntu_Bold16pt8b); epd->setFont(&Ubuntu_Bold16pt8b);
epd->print("A"); epd->print("A");
@ -314,9 +312,7 @@ public:
if(value3 > 9.9 && value3 <= 99.9)epd->print(value3, 1); if(value3 > 9.9 && value3 <= 99.9)epd->print(value3, 1);
if(value3 > 99.9) epd->print(value3, 0); if(value3 > 99.9) epd->print(value3, 0);
} }
else { else epd->print("---");
epd->print(commonData->fmt->placeholder);
}
epd->setFont(&Ubuntu_Bold16pt8b); epd->setFont(&Ubuntu_Bold16pt8b);
epd->print("W"); epd->print("W");

View File

@ -18,7 +18,7 @@
class PageClock : public Page class PageClock : public Page
{ {
private: private:
fmtDate dateformat; String dateformat;
int simtime; int simtime;
bool keylock = false; bool keylock = false;
char source = 'R'; // time source (R)TC | (G)PS | (N)TP char source = 'R'; // time source (R)TC | (G)PS | (N)TP
@ -35,7 +35,7 @@ public:
logger->logDebug(GwLog::LOG, "Instantiate PageClock"); logger->logDebug(GwLog::LOG, "Instantiate PageClock");
// Get config data // Get config data
dateformat = common.fmt->getDateFormat(config->getString(config->dateFormat)); dateformat = config->getString(config->dateFormat);
timezone = config->getString(config->timeZone).toDouble(); timezone = config->getString(config->timeZone).toDouble();
homelat = config->getString(config->homeLAT).toDouble(); homelat = config->getString(config->homeLAT).toDouble();
homelon = config->getString(config->homeLON).toDouble(); homelon = config->getString(config->homeLON).toDouble();
@ -208,7 +208,7 @@ public:
epd->print(formatDate(dateformat, commonData->data.rtcTime.tm_year + 1900, commonData->data.rtcTime.tm_mon + 1, commonData->data.rtcTime.tm_mday)); epd->print(formatDate(dateformat, commonData->data.rtcTime.tm_year + 1900, commonData->data.rtcTime.tm_mon + 1, commonData->data.rtcTime.tm_mday));
} }
} else { } else {
epd->print(commonData->fmt->placeholder); epd->print("---");
} }
} else { } else {
epd->print(svalue2old); epd->print(svalue2old);
@ -229,13 +229,13 @@ public:
} }
else if (commonData->data.rtcValid) { else if (commonData->data.rtcValid) {
if (tz == 'L') { if (tz == 'L') {
epd->print(formatTime(fmtTime::MMHHSS, local_tm->tm_hour, local_tm->tm_min, local_tm->tm_sec)); epd->print(formatTime('s', local_tm->tm_hour, local_tm->tm_min, local_tm->tm_sec));
} }
else { else {
epd->print(formatTime(fmtTime::MMHHSS, commonData->data.rtcTime.tm_hour, commonData->data.rtcTime.tm_min, commonData->data.rtcTime.tm_sec)); epd->print(formatTime('s', commonData->data.rtcTime.tm_hour, commonData->data.rtcTime.tm_min, commonData->data.rtcTime.tm_sec));
} }
} else { } else {
epd->print(commonData->fmt->placeholder); epd->print("---");
} }
} }
else { else {
@ -246,7 +246,7 @@ public:
epd->print("Time"); // Name epd->print("Time"); // Name
// Show values sunrise // Show values sunrise
String sunrise = commonData->fmt->placeholder; String sunrise = "---";
if (((source == 'G') and gpsvalid) or (homevalid and commonData->data.rtcValid)) { if (((source == 'G') and gpsvalid) or (homevalid and commonData->data.rtcValid)) {
sunrise = String(commonData->sundata.sunriseHour) + ":" + String(commonData->sundata.sunriseMinute + 100).substring(1); sunrise = String(commonData->sundata.sunriseHour) + ":" + String(commonData->sundata.sunriseMinute + 100).substring(1);
svalue5old = sunrise; svalue5old = sunrise;
@ -266,7 +266,7 @@ public:
epd->fillRect(340, 149, 80, 3, commonData->fgcolor); epd->fillRect(340, 149, 80, 3, commonData->fgcolor);
// Show values sunset // Show values sunset
String sunset = commonData->fmt->placeholder; String sunset = "---";
if (((source == 'G') and gpsvalid) or (homevalid and commonData->data.rtcValid)) { if (((source == 'G') and gpsvalid) or (homevalid and commonData->data.rtcValid)) {
sunset = String(commonData->sundata.sunsetHour) + ":" + String(commonData->sundata.sunsetMinute + 100).substring(1); sunset = String(commonData->sundata.sunsetHour) + ":" + String(commonData->sundata.sunsetMinute + 100).substring(1);
svalue6old = sunset; svalue6old = sunset;

View File

@ -168,7 +168,7 @@ public:
if(value1 > 99.9) epd->print(value1, 0); if(value1 > 99.9) epd->print(value1, 0);
} }
else{ else{
epd->print(commonData->fmt->placeholder); // Missing bus data epd->print("---"); // Missing bus data
} }
} }
epd->setFont(&Ubuntu_Bold16pt8b); epd->setFont(&Ubuntu_Bold16pt8b);
@ -177,37 +177,24 @@ public:
// Show actual current in A // Show actual current in A
epd->setFont(&DSEG7Classic_BoldItalic20pt7b); epd->setFont(&DSEG7Classic_BoldItalic20pt7b);
epd->setCursor(260, 200); epd->setCursor(260, 200);
if ((powerSensor == "INA219" || powerSensor == "INA226") && (simulation == false)) { if((powerSensor == "INA219" || powerSensor == "INA226") && simulation == false){
// TODO use formatter for this? if(value2 <= 9.9) epd->print(value2, 2);
if (value2 <= 9.9) { if(value2 > 9.9 && value2 <= 99.9)epd->print(value2, 1);
epd->print(value2, 2); if(value2 > 99.9) epd->print(value2, 0);
} else if (value2 <= 99.9) {
epd->print(value2, 1);
} else {
epd->print(value2, 0);
}
}
else {
epd->print(commonData->fmt->placeholder);
} }
else epd->print("---");
epd->setFont(&Ubuntu_Bold16pt8b); epd->setFont(&Ubuntu_Bold16pt8b);
epd->print("A"); epd->print("A");
// Show actual consumption in W // Show actual consumption in W
epd->setFont(&DSEG7Classic_BoldItalic20pt7b); epd->setFont(&DSEG7Classic_BoldItalic20pt7b);
epd->setCursor(260, 260); epd->setCursor(260, 260);
if ((powerSensor == "INA219" || powerSensor == "INA226") && (simulation == false)) { if((powerSensor == "INA219" || powerSensor == "INA226") && simulation == false){
if(value3 <= 9.9) { if(value3 <= 9.9) epd->print(value3, 2);
epd->print(value3, 2); if(value3 > 9.9 && value3 <= 99.9)epd->print(value3, 1);
} else if (value3 <= 99.9) { if(value3 > 99.9) epd->print(value3, 0);
epd->print(value3, 1);
} else {
epd->print(value3, 0);
}
}
else {
epd->print(commonData->fmt->placeholder);
} }
else epd->print("---");
epd->setFont(&Ubuntu_Bold16pt8b); epd->setFont(&Ubuntu_Bold16pt8b);
epd->print("W"); epd->print("W");

View File

@ -88,7 +88,7 @@ public:
// directions // directions
int16_t x1, y1; int16_t x1, y1;
uint16_t w, h; uint16_t w, h;
epd->setFont(&Ubuntu_Bold12pt8b); epd->setFont(&Ubuntu_Bold12pt8b);

View File

@ -160,16 +160,12 @@ public:
// Check for valid real data, display also if hold values activated // Check for valid real data, display also if hold values activated
if(valid1 == true || holdvalues == true){ if(valid1 == true || holdvalues == true){
// Resolution switching // Resolution switching
if (value1 <= 9.9) { if(value1 <= 9.9) epd->print(value1, 2);
epd->print(value1, 2); if(value1 > 9.9 && value1 <= 99.9)epd->print(value1, 1);
} else if (value1 <= 99.9) { if(value1 > 99.9) epd->print(value1, 0);
epd->print(value1, 1);
} else {
epd->print(value1, 0);
}
} }
else { else{
epd->print(commonData->fmt->placeholder); // Missing bus data epd->print("---"); // Missing bus data
} }
} }
epd->setFont(&Ubuntu_Bold16pt8b); epd->setFont(&Ubuntu_Bold16pt8b);
@ -178,36 +174,24 @@ public:
// Show actual current in A // Show actual current in A
epd->setFont(&DSEG7Classic_BoldItalic20pt7b); epd->setFont(&DSEG7Classic_BoldItalic20pt7b);
epd->setCursor(260, 200); epd->setCursor(260, 200);
if ((powerSensor == "INA219" || powerSensor == "INA226") && (simulation == false)) { if((powerSensor == "INA219" || powerSensor == "INA226") && simulation == false){
if (value2 <= 9.9) { if(value2 <= 9.9) epd->print(value2, 2);
epd->print(value2, 2); if(value2 > 9.9 && value2 <= 99.9)epd->print(value2, 1);
} else if (value2 <= 99.9) { if(value2 > 99.9) epd->print(value2, 0);
epd->print(value2, 1);
} else {
epd->print(value2, 0);
}
}
else {
epd->print(commonData->fmt->placeholder);
} }
else epd->print("---");
epd->setFont(&Ubuntu_Bold16pt8b); epd->setFont(&Ubuntu_Bold16pt8b);
epd->print("A"); epd->print("A");
// Show actual consumption in W // Show actual consumption in W
epd->setFont(&DSEG7Classic_BoldItalic20pt7b); epd->setFont(&DSEG7Classic_BoldItalic20pt7b);
epd->setCursor(260, 260); epd->setCursor(260, 260);
if ((powerSensor == "INA219" || powerSensor == "INA226") && (simulation == false)) { if((powerSensor == "INA219" || powerSensor == "INA226") && simulation == false){
if (value3 <= 9.9) { if(value3 <= 9.9) epd->print(value3, 2);
epd->print(value3, 2); if(value3 > 9.9 && value3 <= 99.9)epd->print(value3, 1);
} else if (value3 <= 99.9) { if(value3 > 99.9) epd->print(value3, 0);
epd->print(value3, 1);
} else {
epd->print(value3, 0);
}
}
else {
epd->print(commonData->fmt->placeholder);
} }
else epd->print("---");
epd->setFont(&Ubuntu_Bold16pt8b); epd->setFont(&Ubuntu_Bold16pt8b);
epd->print("W"); epd->print("W");

View File

@ -249,7 +249,7 @@ public:
} }
} }
else{ else{
epd->print(commonData->fmt->placeholder); // Missing bus data epd->print("---"); // Missing bus data
} }
} }

View File

@ -182,11 +182,11 @@ public:
// Show values TWD // Show values TWD
epd->setFont(&DSEG7Classic_BoldItalic20pt7b); epd->setFont(&DSEG7Classic_BoldItalic20pt7b);
epd->setCursor(295, 65); epd->setCursor(295, 65);
if (valid3 == true) { if(valid3 == true){
epd->print(abs(value3 * 180 / PI), 0); // Value epd->print(abs(value3 * 180 / PI), 0); // Value
} }
else { else{
epd->print(commonData->fmt->placeholder); epd->print("---"); // Value
} }
epd->setFont(&Ubuntu_Bold12pt8b); epd->setFont(&Ubuntu_Bold12pt8b);
epd->setCursor(335, 95); epd->setCursor(335, 95);

View File

@ -207,7 +207,7 @@ public:
epd->print(svalue4); // Value epd->print(svalue4); // Value
} }
else{ else{
epd->print(commonData->fmt->placeholder); epd->print("---"); // Value
} }
epd->setFont(&Ubuntu_Bold12pt8b); epd->setFont(&Ubuntu_Bold12pt8b);
epd->setCursor(335, 95); epd->setCursor(335, 95);

View File

@ -208,7 +208,7 @@ class PageDescription{
class PageStruct{ class PageStruct{
public: public:
Page *page = nullptr; Page *page=NULL;
PageData parameters; PageData parameters;
PageDescription *description = nullptr; PageDescription *description=NULL;
}; };

View File

@ -8,10 +8,9 @@ Coding style
------------ ------------
WIP WIP
Please format your new code the same as already existing code. Please format your new code the same as already existing code.
Preprocessor directives go to column zero.
Some rules: Identation is 4 spaces
- Preprocessor directives go to column zero
- Identation is 4 spaces
Git commands Git commands
------------ ------------

View File

@ -65,8 +65,8 @@ void OBP60Init(GwApi *api){
#endif #endif
// Settings for e-paper display // Settings for e-paper display
String fastrefresh = config->getConfigItem(config->fastRefresh,true)->asString(); String fastrefresh = api->getConfig()->getConfigItem(api->getConfig()->fastRefresh,true)->asString();
logger->logDebug(GwLog::DEBUG, "Fast Refresh Mode is: %s", fastrefresh.c_str()); logger->logDebug(GwLog::DEBUG,"Fast Refresh Mode is: %s", fastrefresh.c_str());
#ifdef DISPLAY_GDEY042T81 #ifdef DISPLAY_GDEY042T81
if(fastrefresh == "true"){ if(fastrefresh == "true"){
static const bool useFastFullUpdate = true; // Enable fast full display update only for GDEY042T81 static const bool useFastFullUpdate = true; // Enable fast full display update only for GDEY042T81
@ -88,24 +88,24 @@ void OBP60Init(GwApi *api){
logger->logDebug(GwLog::LOG,"CPU speed at boot: %i MHz", freq); logger->logDebug(GwLog::LOG,"CPU speed at boot: %i MHz", freq);
// Settings for backlight // Settings for backlight
String backlightMode = config->getConfigItem(config->backlight,true)->asString(); String backlightMode = api->getConfig()->getConfigItem(api->getConfig()->backlight,true)->asString();
logger->logDebug(GwLog::DEBUG, "Backlight Mode is: %s", backlightMode.c_str()); logger->logDebug(GwLog::DEBUG,"Backlight Mode is: %s", backlightMode.c_str());
uint brightness = uint(config->getConfigItem(config->blBrightness,true)->asInt()); uint brightness = uint(api->getConfig()->getConfigItem(api->getConfig()->blBrightness,true)->asInt());
String backlightColor = config->getConfigItem(config->blColor,true)->asString(); String backlightColor = api->getConfig()->getConfigItem(api->getConfig()->blColor,true)->asString();
if (backlightMode == "On") { if(String(backlightMode) == "On"){
setBacklightLED(brightness, colorMapping(backlightColor)); setBacklightLED(brightness, colorMapping(backlightColor));
} }
else if (backlightMode == "Off") { else if(String(backlightMode) == "Off"){
setBacklightLED(0, COLOR_BLACK); // Backlight LEDs off (blue without britghness) setBacklightLED(0, COLOR_BLACK); // Backlight LEDs off (blue without britghness)
} }
else if (backlightMode == "Control by Key") { else if(String(backlightMode) == "Control by Key"){
setBacklightLED(0, COLOR_BLUE); // Backlight LEDs off (blue without britghness) setBacklightLED(0, COLOR_BLUE); // Backlight LEDs off (blue without britghness)
} }
// Settings flash LED mode // Settings flash LED mode
String ledMode = config->getConfigItem(config->flashLED,true)->asString(); String ledMode = api->getConfig()->getConfigItem(api->getConfig()->flashLED,true)->asString();
logger->logDebug(GwLog::DEBUG,"LED Mode is: %s", ledMode.c_str()); logger->logDebug(GwLog::DEBUG,"LED Mode is: %s", ledMode.c_str());
if (ledMode == "Off") { if(String(ledMode) == "Off"){
setBlinkingLED(false); setBlinkingLED(false);
} }
@ -114,7 +114,7 @@ void OBP60Init(GwApi *api){
initComplete = true; initComplete = true;
// Buzzer tone for initialization finish // Buzzer tone for initialization finish
setBuzzerPower(uint(config->getConfigItem(config->buzzerPower,true)->asInt())); setBuzzerPower(uint(api->getConfig()->getConfigItem(api->getConfig()->buzzerPower,true)->asInt()));
buzzer(TONE4, 500); buzzer(TONE4, 500);
} }
@ -186,6 +186,7 @@ class BoatValueList{
//this way each page can easily be added here //this way each page can easily be added here
//needs some minor tricks for the safe static initialization //needs some minor tricks for the safe static initialization
typedef std::vector<PageDescription*> Pages; typedef std::vector<PageDescription*> Pages;
//the page list class
class PageList{ class PageList{
public: public:
Pages pages; Pages pages;
@ -279,62 +280,64 @@ void registerAllPages(GwLog *logger, PageList &list){
} }
// Undervoltage detection for shutdown display // Undervoltage detection for shutdown display
void underVoltageError(CommonData &common) { void underVoltageDetection(GwApi *api, CommonData &common){
#if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200 // Read settings
// Switch off all power lines double voffset = (api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asString()).toFloat();
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off double vslope = (api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asString()).toFloat();
setFlashLED(false); // Flash LED Off
buzzer(TONE4, 20); // Buzzer tone 4kHz 20ms
// Shutdown EInk display
epd->setFullWindow(); // Set full Refresh
//epd->setPartialWindow(0, 0, epd->width(), epd->height()); // Set partial update
epd->fillScreen(common.bgcolor);// Clear screen
epd->setTextColor(common.fgcolor);
epd->setFont(&Ubuntu_Bold20pt8b);
epd->setCursor(65, 150);
epd->print("Undervoltage");
epd->setFont(&Ubuntu_Bold8pt8b);
epd->setCursor(65, 175);
epd->print("Charge battery and restart system");
epd->nextPage(); // Partial update
epd->powerOff(); // Display power off
setPortPin(OBP_POWER_EPD, false); // Power off ePaper display
setPortPin(OBP_POWER_SD, false); // Power off SD card
#else
// Switch off all power lines
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
setFlashLED(false); // Flash LED Off
buzzer(TONE4, 20); // Buzzer tone 4kHz 20ms
setPortPin(OBP_POWER_50, false); // Power rail 5.0V Off
// Shutdown EInk display
epd->setPartialWindow(0, 0, epd->width(), epd->height()); // Set partial update
epd->fillScreen(common.bgcolor);// Clear screen
epd->setTextColor(common.fgcolor);
epd->setFont(&Ubuntu_Bold20pt8b);
epd->setCursor(65, 150);
epd->print("Undervoltage");
epd->setFont(&Ubuntu_Bold8pt8b);
epd->setCursor(65, 175);
epd->print("To wake up repower system");
epd->nextPage(); // Partial update
epd->powerOff(); // Display power off
#endif
while (true) {
esp_deep_sleep_start(); // Deep Sleep without wakeup. Wakeup only after power cycle (restart).
}
}
inline bool underVoltageDetection(float voffset, float vslope) {
// Read supply voltage // Read supply voltage
#if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200 #if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40 float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40
float minVoltage = 3.65; // Absolut minimum volatge for 3,7V LiPo accu float minVoltage = 3.65; // Absolut minimum volatge for 3,7V LiPo accu
#else #else
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60 float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
float minVoltage = MIN_VOLTAGE; float minVoltage = MIN_VOLTAGE;
#endif #endif
float calVoltage = actVoltage * vslope + voffset; // Calibration double calVoltage = actVoltage * vslope + voffset; // Calibration
return (calVoltage < minVoltage); if(calVoltage < minVoltage){
#if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200
// Switch off all power lines
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
setFlashLED(false); // Flash LED Off
buzzer(TONE4, 20); // Buzzer tone 4kHz 20ms
// Shutdown EInk display
epd->setFullWindow(); // Set full Refresh
//epd->setPartialWindow(0, 0, epd->width(), epd->height()); // Set partial update
epd->fillScreen(common.bgcolor);// Clear screen
epd->setTextColor(common.fgcolor);
epd->setFont(&Ubuntu_Bold20pt8b);
epd->setCursor(65, 150);
epd->print("Undervoltage");
epd->setFont(&Ubuntu_Bold8pt8b);
epd->setCursor(65, 175);
epd->print("Charge battery and restart system");
epd->nextPage(); // Partial update
epd->powerOff(); // Display power off
setPortPin(OBP_POWER_EPD, false); // Power off ePaper display
setPortPin(OBP_POWER_SD, false); // Power off SD card
#else
// Switch off all power lines
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
setFlashLED(false); // Flash LED Off
buzzer(TONE4, 20); // Buzzer tone 4kHz 20ms
setPortPin(OBP_POWER_50, false); // Power rail 5.0V Off
// Shutdown EInk display
epd->setPartialWindow(0, 0, epd->width(), epd->height()); // Set partial update
epd->fillScreen(common.bgcolor);// Clear screen
epd->setTextColor(common.fgcolor);
epd->setFont(&Ubuntu_Bold20pt8b);
epd->setCursor(65, 150);
epd->print("Undervoltage");
epd->setFont(&Ubuntu_Bold8pt8b);
epd->setCursor(65, 175);
epd->print("To wake up repower system");
epd->nextPage(); // Partial update
epd->powerOff(); // Display power off
#endif
// Stop system
while(true){
esp_deep_sleep_start(); // Deep Sleep without weakup. Weakup only after power cycle (restart).
}
}
} }
// Calculate true wind data and add to obp60task boat data list // Calculate true wind data and add to obp60task boat data list
@ -538,8 +541,8 @@ void handleHstryBuf(GwApi* api, BoatValueList* boatValues, tBoatHstryData hstryB
void OBP60Task(GwApi *api){ void OBP60Task(GwApi *api){
// vTaskDelete(NULL); // vTaskDelete(NULL);
// return; // return;
GwLog *logger = api->getLogger(); GwLog *logger=api->getLogger();
GwConfigHandler *config = api->getConfig(); GwConfigHandler *config=api->getConfig();
#ifdef HARDWARE_V21 #ifdef HARDWARE_V21
startLedTask(api); startLedTask(api);
#endif #endif
@ -563,8 +566,8 @@ void OBP60Task(GwApi *api){
} }
// Init E-Ink display // Init E-Ink display
String displaymode = config->getConfigItem(config->display,true)->asString(); String displaymode = api->getConfig()->getConfigItem(api->getConfig()->display,true)->asString();
String displaycolor = config->getConfigItem(config->displaycolor,true)->asString(); String displaycolor = api->getConfig()->getConfigItem(api->getConfig()->displaycolor,true)->asString();
if (displaycolor == "Normal") { if (displaycolor == "Normal") {
commonData.fgcolor = GxEPD_BLACK; commonData.fgcolor = GxEPD_BLACK;
commonData.bgcolor = GxEPD_WHITE; commonData.bgcolor = GxEPD_WHITE;
@ -573,12 +576,12 @@ void OBP60Task(GwApi *api){
commonData.fgcolor = GxEPD_WHITE; commonData.fgcolor = GxEPD_WHITE;
commonData.bgcolor = GxEPD_BLACK; commonData.bgcolor = GxEPD_BLACK;
} }
String systemname = config->getConfigItem(config->systemName, true)->asString(); String systemname = api->getConfig()->getConfigItem(api->getConfig()->systemName,true)->asString();
String wifipass = config->getConfigItem(config->apPassword, true)->asString(); String wifipass = api->getConfig()->getConfigItem(api->getConfig()->apPassword,true)->asString();
bool refreshmode = config->getConfigItem(config->refresh, true)->asBoolean(); bool refreshmode = api->getConfig()->getConfigItem(api->getConfig()->refresh,true)->asBoolean();
bool symbolmode = (config->getString(config->headerFormat) == "ICON"); bool symbolmode = (config->getString(config->headerFormat) == "ICON");
String fastrefresh = config->getConfigItem(config->fastRefresh, true)->asString(); String fastrefresh = api->getConfig()->getConfigItem(api->getConfig()->fastRefresh,true)->asString();
uint fullrefreshtime = uint(config->getConfigItem(config->fullRefreshTime, true)->asInt()); uint fullrefreshtime = uint(api->getConfig()->getConfigItem(api->getConfig()->fullRefreshTime,true)->asInt());
#ifdef BOARD_OBP40S3 #ifdef BOARD_OBP40S3
bool syspage_enabled = config->getBool(config->systemPage); bool syspage_enabled = config->getBool(config->systemPage);
#endif #endif
@ -735,23 +738,21 @@ void OBP60Task(GwApi *api){
//#################################################################################### //####################################################################################
// Configuration values for main loop // Configuration values for main loop
String gpsFix = config->getConfigItem(config->flashLED,true)->asString(); String gpsFix = api->getConfig()->getConfigItem(api->getConfig()->flashLED,true)->asString();
String gpsOn = config->getConfigItem(config->useGPS,true)->asString(); String gpsOn=api->getConfig()->getConfigItem(api->getConfig()->useGPS,true)->asString();
float tz = config->getConfigItem(config->timeZone,true)->asFloat(); float tz = api->getConfig()->getConfigItem(api->getConfig()->timeZone,true)->asFloat();
commonData.backlight.mode = backlightMapping(config->getConfigItem(config->backlight, true)->asString()); commonData.backlight.mode = backlightMapping(config->getConfigItem(config->backlight,true)->asString());
commonData.backlight.color = colorMapping(config->getConfigItem(config->blColor, true)->asString()); commonData.backlight.color = colorMapping(config->getConfigItem(config->blColor,true)->asString());
commonData.backlight.brightness = 2.55 * uint(config->getConfigItem(config->blBrightness, true)->asInt()); commonData.backlight.brightness = 2.55 * uint(config->getConfigItem(config->blBrightness,true)->asInt());
commonData.powermode = api->getConfig()->getConfigItem(api->getConfig()->powerMode, true)->asString(); commonData.powermode = api->getConfig()->getConfigItem(api->getConfig()->powerMode,true)->asString();
bool uvoltage = config->getConfigItem(config->underVoltage, true)->asBoolean(); bool uvoltage = api->getConfig()->getConfigItem(api->getConfig()->underVoltage,true)->asBoolean();
float voffset = (config->getConfigItem(config->vOffset,true)->asString()).toFloat(); String cpuspeed = api->getConfig()->getConfigItem(api->getConfig()->cpuSpeed,true)->asString();
float vslope = (config->getConfigItem(config->vSlope,true)->asString()).toFloat(); uint hdopAccuracy = uint(api->getConfig()->getConfigItem(api->getConfig()->hdopAccuracy,true)->asInt());
String cpuspeed = config->getConfigItem(config->cpuSpeed, true)->asString();
uint hdopAccuracy = uint(config->getConfigItem(config->hdopAccuracy, true)->asInt());
double homelat = config->getString(config->homeLAT).toDouble(); double homelat = commonData.config->getString(commonData.config->homeLAT).toDouble();
double homelon = config->getString(config->homeLON).toDouble(); double homelon = commonData.config->getString(commonData.config->homeLON).toDouble();
bool homevalid = homelat >= -180.0 and homelat <= 180 and homelon >= -90.0 and homelon <= 90.0; bool homevalid = homelat >= -180.0 and homelat <= 180 and homelon >= -90.0 and homelon <= 90.0;
if (homevalid) { if (homevalid) {
logger->logDebug(GwLog::LOG, "Home location set to lat=%f, lon=%f", homelat, homelon); logger->logDebug(GwLog::LOG, "Home location set to lat=%f, lon=%f", homelat, homelon);
@ -795,11 +796,8 @@ void OBP60Task(GwApi *api){
bool keypressed = false; bool keypressed = false;
// Undervoltage detection // Undervoltage detection
if (uvoltage == true) { if(uvoltage == true){
if (underVoltageDetection(voffset, vslope)) { underVoltageDetection(api, commonData);
LOG_DEBUG(GwLog::ERROR, "Undervoltage detected, shutting down!");
underVoltageError(commonData);
}
} }
// Set CPU speed after boot after 1min // Set CPU speed after boot after 1min

View File

@ -41,10 +41,5 @@
#ifdef BOARD_OBP40S3 #ifdef BOARD_OBP40S3
DECLARE_CAPABILITY(obp40,true) DECLARE_CAPABILITY(obp40,true)
#endif #endif
#ifdef BOARD_OBP60S3 DECLARE_STRING_CAPABILITY(HELP_URL, "https://obp60-v2-docu.readthedocs.io/de/latest/"); // Link to help pages
DECLARE_STRING_CAPABILITY(HELP_URL, "https://obp60-v2-docu.readthedocs.io/en/latest/"); // Link to help pages
#endif
#ifdef BOARD_OBP40S3
DECLARE_STRING_CAPABILITY(HELP_URL, "https://obp40-v1-docu.readthedocs.io/en/latest/"); // Link to help pages
#endif
#endif #endif