Compare commits

...

4 Commits

16 changed files with 323 additions and 222 deletions

View File

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

View File

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

View File

@ -2,41 +2,10 @@
#ifndef _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
A Angular displacement
C Temperature
@ -69,8 +38,77 @@ 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
enum class fmtDate {DE, EN, GB, ISO};
enum class fmtDate {DE, GB, US, ISO};
enum class fmtTime {MMHH, MMHHSS};
enum class fmtLength {METER, FEET, FATHOM, CABLE};
enum class fmtDepth {METER, FEET, FATHOM};
@ -106,6 +144,7 @@ private:
String windspeedFormat = "kn"; // [m/s|km/h|kn|bft]
String tempFormat = "C"; // [K|°C|°F]
String dateFormat = "ISO"; // [DE|GB|US|ISO]
fmtDate dateFmt;
bool usesimudata = false; // [on|off]
String precision = "2"; // [1|2]
@ -115,12 +154,16 @@ private:
public:
Formatter(GwConfigHandler *config);
fmtType stringToFormat(const char* formatStr);
fmtDate getDateFormat(String sformat);
fmtTime getTimeFormat(String sformat);
FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata);
String placeholder = "---";
};
// Standard format functions without overhead
String formatDate(String fmttype, uint16_t year, uint8_t month, uint8_t day);
String formatTime(char fmttype, uint8_t hour, uint8_t minute, uint8_t second);
// Standard format functions without class and overhead
String formatDate(fmtDate fmttype, uint16_t year, uint8_t month, uint8_t day);
String formatTime(fmtTime fmttype, uint8_t hour, uint8_t minute, uint8_t second);
String formatLatitude(double lat);
String formatLongitude(double lon);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -65,8 +65,8 @@ void OBP60Init(GwApi *api){
#endif
// Settings for e-paper display
String fastrefresh = api->getConfig()->getConfigItem(api->getConfig()->fastRefresh,true)->asString();
logger->logDebug(GwLog::DEBUG,"Fast Refresh Mode is: %s", fastrefresh.c_str());
String fastrefresh = config->getConfigItem(config->fastRefresh,true)->asString();
logger->logDebug(GwLog::DEBUG, "Fast Refresh Mode is: %s", fastrefresh.c_str());
#ifdef DISPLAY_GDEY042T81
if(fastrefresh == "true"){
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);
// Settings for backlight
String backlightMode = api->getConfig()->getConfigItem(api->getConfig()->backlight,true)->asString();
logger->logDebug(GwLog::DEBUG,"Backlight Mode is: %s", backlightMode.c_str());
uint brightness = uint(api->getConfig()->getConfigItem(api->getConfig()->blBrightness,true)->asInt());
String backlightColor = api->getConfig()->getConfigItem(api->getConfig()->blColor,true)->asString();
if(String(backlightMode) == "On"){
setBacklightLED(brightness, colorMapping(backlightColor));
String backlightMode = config->getConfigItem(config->backlight,true)->asString();
logger->logDebug(GwLog::DEBUG, "Backlight Mode is: %s", backlightMode.c_str());
uint brightness = uint(config->getConfigItem(config->blBrightness,true)->asInt());
String backlightColor = config->getConfigItem(config->blColor,true)->asString();
if (backlightMode == "On") {
setBacklightLED(brightness, colorMapping(backlightColor));
}
else if(String(backlightMode) == "Off"){
setBacklightLED(0, COLOR_BLACK); // Backlight LEDs off (blue without britghness)
else if (backlightMode == "Off") {
setBacklightLED(0, COLOR_BLACK); // Backlight LEDs off (blue without britghness)
}
else if(String(backlightMode) == "Control by Key"){
setBacklightLED(0, COLOR_BLUE); // Backlight LEDs off (blue without britghness)
else if (backlightMode == "Control by Key") {
setBacklightLED(0, COLOR_BLUE); // Backlight LEDs off (blue without britghness)
}
// Settings flash LED mode
String ledMode = api->getConfig()->getConfigItem(api->getConfig()->flashLED,true)->asString();
String ledMode = config->getConfigItem(config->flashLED,true)->asString();
logger->logDebug(GwLog::DEBUG,"LED Mode is: %s", ledMode.c_str());
if(String(ledMode) == "Off"){
if (ledMode == "Off") {
setBlinkingLED(false);
}
@ -114,7 +114,7 @@ void OBP60Init(GwApi *api){
initComplete = true;
// Buzzer tone for initialization finish
setBuzzerPower(uint(api->getConfig()->getConfigItem(api->getConfig()->buzzerPower,true)->asInt()));
setBuzzerPower(uint(config->getConfigItem(config->buzzerPower,true)->asInt()));
buzzer(TONE4, 500);
}
@ -156,7 +156,7 @@ class BoatValueList{
//additionally we put the necessary values into the paga data - see below
GwApi::BoatValue *allBoatValues[MAXVALUES];
int numValues=0;
bool addValueToList(GwApi::BoatValue *v){
for (int i=0;i<numValues;i++){
if (allBoatValues[i] == v){
@ -186,7 +186,6 @@ class BoatValueList{
//this way each page can easily be added here
//needs some minor tricks for the safe static initialization
typedef std::vector<PageDescription*> Pages;
//the page list class
class PageList{
public:
Pages pages;
@ -280,64 +279,62 @@ void registerAllPages(GwLog *logger, PageList &list){
}
// Undervoltage detection for shutdown display
void underVoltageDetection(GwApi *api, CommonData &common){
// Read settings
double voffset = (api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asString()).toFloat();
double vslope = (api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asString()).toFloat();
void underVoltageError(CommonData &common) {
#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
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
#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
#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;
#endif
double calVoltage = actVoltage * vslope + voffset; // Calibration
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).
}
}
float calVoltage = actVoltage * vslope + voffset; // Calibration
return (calVoltage < minVoltage);
}
// Calculate true wind data and add to obp60task boat data list
@ -541,8 +538,8 @@ void handleHstryBuf(GwApi* api, BoatValueList* boatValues, tBoatHstryData hstryB
void OBP60Task(GwApi *api){
// vTaskDelete(NULL);
// return;
GwLog *logger=api->getLogger();
GwConfigHandler *config=api->getConfig();
GwLog *logger = api->getLogger();
GwConfigHandler *config = api->getConfig();
#ifdef HARDWARE_V21
startLedTask(api);
#endif
@ -566,8 +563,8 @@ void OBP60Task(GwApi *api){
}
// Init E-Ink display
String displaymode = api->getConfig()->getConfigItem(api->getConfig()->display,true)->asString();
String displaycolor = api->getConfig()->getConfigItem(api->getConfig()->displaycolor,true)->asString();
String displaymode = config->getConfigItem(config->display,true)->asString();
String displaycolor = config->getConfigItem(config->displaycolor,true)->asString();
if (displaycolor == "Normal") {
commonData.fgcolor = GxEPD_BLACK;
commonData.bgcolor = GxEPD_WHITE;
@ -576,12 +573,12 @@ void OBP60Task(GwApi *api){
commonData.fgcolor = GxEPD_WHITE;
commonData.bgcolor = GxEPD_BLACK;
}
String systemname = api->getConfig()->getConfigItem(api->getConfig()->systemName,true)->asString();
String wifipass = api->getConfig()->getConfigItem(api->getConfig()->apPassword,true)->asString();
bool refreshmode = api->getConfig()->getConfigItem(api->getConfig()->refresh,true)->asBoolean();
String systemname = config->getConfigItem(config->systemName, true)->asString();
String wifipass = config->getConfigItem(config->apPassword, true)->asString();
bool refreshmode = config->getConfigItem(config->refresh, true)->asBoolean();
bool symbolmode = (config->getString(config->headerFormat) == "ICON");
String fastrefresh = api->getConfig()->getConfigItem(api->getConfig()->fastRefresh,true)->asString();
uint fullrefreshtime = uint(api->getConfig()->getConfigItem(api->getConfig()->fullRefreshTime,true)->asInt());
String fastrefresh = config->getConfigItem(config->fastRefresh, true)->asString();
uint fullrefreshtime = uint(config->getConfigItem(config->fullRefreshTime, true)->asInt());
#ifdef BOARD_OBP40S3
bool syspage_enabled = config->getBool(config->systemPage);
#endif
@ -738,21 +735,23 @@ void OBP60Task(GwApi *api){
//####################################################################################
// Configuration values for main loop
String gpsFix = api->getConfig()->getConfigItem(api->getConfig()->flashLED,true)->asString();
String gpsOn=api->getConfig()->getConfigItem(api->getConfig()->useGPS,true)->asString();
float tz = api->getConfig()->getConfigItem(api->getConfig()->timeZone,true)->asFloat();
String gpsFix = config->getConfigItem(config->flashLED,true)->asString();
String gpsOn = config->getConfigItem(config->useGPS,true)->asString();
float tz = config->getConfigItem(config->timeZone,true)->asFloat();
commonData.backlight.mode = backlightMapping(config->getConfigItem(config->backlight,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.powermode = api->getConfig()->getConfigItem(api->getConfig()->powerMode,true)->asString();
commonData.backlight.mode = backlightMapping(config->getConfigItem(config->backlight, 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.powermode = api->getConfig()->getConfigItem(api->getConfig()->powerMode, true)->asString();
bool uvoltage = api->getConfig()->getConfigItem(api->getConfig()->underVoltage,true)->asBoolean();
String cpuspeed = api->getConfig()->getConfigItem(api->getConfig()->cpuSpeed,true)->asString();
uint hdopAccuracy = uint(api->getConfig()->getConfigItem(api->getConfig()->hdopAccuracy,true)->asInt());
bool uvoltage = config->getConfigItem(config->underVoltage, true)->asBoolean();
float voffset = (config->getConfigItem(config->vOffset,true)->asString()).toFloat();
float vslope = (config->getConfigItem(config->vSlope,true)->asString()).toFloat();
String cpuspeed = config->getConfigItem(config->cpuSpeed, true)->asString();
uint hdopAccuracy = uint(config->getConfigItem(config->hdopAccuracy, true)->asInt());
double homelat = commonData.config->getString(commonData.config->homeLAT).toDouble();
double homelon = commonData.config->getString(commonData.config->homeLON).toDouble();
double homelat = config->getString(config->homeLAT).toDouble();
double homelon = config->getString(config->homeLON).toDouble();
bool homevalid = homelat >= -180.0 and homelat <= 180 and homelon >= -90.0 and homelon <= 90.0;
if (homevalid) {
logger->logDebug(GwLog::LOG, "Home location set to lat=%f, lon=%f", homelat, homelon);
@ -796,8 +795,11 @@ void OBP60Task(GwApi *api){
bool keypressed = false;
// Undervoltage detection
if(uvoltage == true){
underVoltageDetection(api, commonData);
if (uvoltage == true) {
if (underVoltageDetection(voffset, vslope)) {
LOG_DEBUG(GwLog::ERROR, "Undervoltage detected, shutting down!");
underVoltageError(commonData);
}
}
// Set CPU speed after boot after 1min

View File

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