Some code cleanup
This commit is contained in:
parent
1e0acf2a8f
commit
672a3843d1
|
@ -474,6 +474,7 @@ 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
|
||||||
|
|
|
@ -86,12 +86,7 @@ FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &common
|
||||||
else{
|
else{
|
||||||
snprintf(buffer, bsize, "01.01.2022");
|
snprintf(buffer, bsize, "01.01.2022");
|
||||||
}
|
}
|
||||||
if(timeZone == 0){
|
result.unit = ((timeZone == 0) ? "UTC" : "LOT");
|
||||||
result.unit = "UTC";
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
result.unit = "LOT";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//########################################################
|
//########################################################
|
||||||
else if(value->getFormat() == "formatTime"){
|
else if(value->getFormat() == "formatTime"){
|
||||||
|
@ -121,12 +116,7 @@ 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();
|
||||||
}
|
}
|
||||||
if(timeZone == 0){
|
result.unit = ((timeZone == 0) ? "UTC" : "LOT");
|
||||||
result.unit = "UTC";
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
result.unit = "LOT";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//########################################################
|
//########################################################
|
||||||
else if (value->getFormat() == "formatFixed0"){
|
else if (value->getFormat() == "formatFixed0"){
|
||||||
|
@ -286,13 +276,13 @@ FormattedData Formatter::formatValue(GwApi::BoatValue *value, CommonData &common
|
||||||
if (rotation < -100){
|
if (rotation < -100){
|
||||||
rotation = -99;
|
rotation = -99;
|
||||||
}
|
}
|
||||||
if (rotation > 100){
|
else 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);
|
||||||
}
|
}
|
||||||
if (rotation <= -10 || rotation >= 10){
|
else {
|
||||||
snprintf(buffer, bsize, "%3.0f", rotation);
|
snprintf(buffer, bsize, "%3.0f", rotation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -330,12 +320,7 @@ 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);
|
||||||
if (lat > 0){
|
latdir = (lat > 0) ? "N" : "S";
|
||||||
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());
|
||||||
|
@ -354,12 +339,7 @@ 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);
|
||||||
if (lon > 0){
|
londir = (lon > 0) ? "E" : "W";
|
||||||
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());
|
||||||
|
@ -381,7 +361,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;
|
depth = depth * 3.28084; // TODO use global defined factor
|
||||||
result.unit = "ft";
|
result.unit = "ft";
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -411,7 +391,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;
|
xte = xte * 0.000539957; // TODO use global defined factor
|
||||||
result.unit = "nm";
|
result.unit = "nm";
|
||||||
} else {
|
} else {
|
||||||
result.unit = "m";
|
result.unit = "m";
|
||||||
|
@ -473,7 +453,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;
|
distance = distance * 0.000539957; // TODO use global defined factor
|
||||||
result.unit = "nm";
|
result.unit = "nm";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -177,10 +177,15 @@ 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) epd->print(value2, 2);
|
// TODO use formatter for this?
|
||||||
if(value2 > 9.9 && value2 <= 99.9)epd->print(value2, 1);
|
if (value2 <= 9.9) {
|
||||||
if(value2 > 99.9) epd->print(value2, 0);
|
epd->print(value2, 2);
|
||||||
|
} else if (value2 <= 99.9) {
|
||||||
|
epd->print(value2, 1);
|
||||||
|
} else {
|
||||||
|
epd->print(value2, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
epd->print(commonData->fmt->placeholder);
|
epd->print(commonData->fmt->placeholder);
|
||||||
|
@ -191,10 +196,14 @@ public:
|
||||||
// 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) epd->print(value3, 2);
|
if(value3 <= 9.9) {
|
||||||
if(value3 > 9.9 && value3 <= 99.9)epd->print(value3, 1);
|
epd->print(value3, 2);
|
||||||
if(value3 > 99.9) epd->print(value3, 0);
|
} else if (value3 <= 99.9) {
|
||||||
|
epd->print(value3, 1);
|
||||||
|
} else {
|
||||||
|
epd->print(value3, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
epd->print(commonData->fmt->placeholder);
|
epd->print(commonData->fmt->placeholder);
|
||||||
|
|
|
@ -160,9 +160,13 @@ 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) epd->print(value1, 2);
|
if (value1 <= 9.9) {
|
||||||
if(value1 > 9.9 && value1 <= 99.9)epd->print(value1, 1);
|
epd->print(value1, 2);
|
||||||
if(value1 > 99.9) epd->print(value1, 0);
|
} else if (value1 <= 99.9) {
|
||||||
|
epd->print(value1, 1);
|
||||||
|
} else {
|
||||||
|
epd->print(value1, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
epd->print(commonData->fmt->placeholder); // Missing bus data
|
epd->print(commonData->fmt->placeholder); // Missing bus data
|
||||||
|
@ -174,10 +178,14 @@ 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) 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 {
|
else {
|
||||||
epd->print(commonData->fmt->placeholder);
|
epd->print(commonData->fmt->placeholder);
|
||||||
|
@ -188,10 +196,14 @@ public:
|
||||||
// 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) epd->print(value3, 2);
|
if (value3 <= 9.9) {
|
||||||
if(value3 > 9.9 && value3 <= 99.9)epd->print(value3, 1);
|
epd->print(value3, 2);
|
||||||
if(value3 > 99.9) epd->print(value3, 0);
|
} else if (value3 <= 99.9) {
|
||||||
|
epd->print(value3, 1);
|
||||||
|
} else {
|
||||||
|
epd->print(value3, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
epd->print(commonData->fmt->placeholder);
|
epd->print(commonData->fmt->placeholder);
|
||||||
|
|
|
@ -8,9 +8,10 @@ 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.
|
|
||||||
|
|
||||||
Identation is 4 spaces
|
Some rules:
|
||||||
|
- Preprocessor directives go to column zero
|
||||||
|
- Identation is 4 spaces
|
||||||
|
|
||||||
Git commands
|
Git commands
|
||||||
------------
|
------------
|
||||||
|
|
|
@ -65,7 +65,7 @@ void OBP60Init(GwApi *api){
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Settings for e-paper display
|
// Settings for e-paper display
|
||||||
String fastrefresh = api->getConfig()->getConfigItem(api->getConfig()->fastRefresh,true)->asString();
|
String fastrefresh = config->getConfigItem(config->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"){
|
||||||
|
@ -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 = api->getConfig()->getConfigItem(api->getConfig()->backlight,true)->asString();
|
String backlightMode = config->getConfigItem(config->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(api->getConfig()->getConfigItem(api->getConfig()->blBrightness,true)->asInt());
|
uint brightness = uint(config->getConfigItem(config->blBrightness,true)->asInt());
|
||||||
String backlightColor = api->getConfig()->getConfigItem(api->getConfig()->blColor,true)->asString();
|
String backlightColor = config->getConfigItem(config->blColor,true)->asString();
|
||||||
if(String(backlightMode) == "On"){
|
if (backlightMode == "On") {
|
||||||
setBacklightLED(brightness, colorMapping(backlightColor));
|
setBacklightLED(brightness, colorMapping(backlightColor));
|
||||||
}
|
}
|
||||||
else if(String(backlightMode) == "Off"){
|
else if (backlightMode == "Off") {
|
||||||
setBacklightLED(0, COLOR_BLACK); // Backlight LEDs off (blue without britghness)
|
setBacklightLED(0, COLOR_BLACK); // Backlight LEDs off (blue without britghness)
|
||||||
}
|
}
|
||||||
else if(String(backlightMode) == "Control by Key"){
|
else if (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 = 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());
|
logger->logDebug(GwLog::DEBUG,"LED Mode is: %s", ledMode.c_str());
|
||||||
if(String(ledMode) == "Off"){
|
if (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(api->getConfig()->getConfigItem(api->getConfig()->buzzerPower,true)->asInt()));
|
setBuzzerPower(uint(config->getConfigItem(config->buzzerPower,true)->asInt()));
|
||||||
buzzer(TONE4, 500);
|
buzzer(TONE4, 500);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -563,8 +563,8 @@ void OBP60Task(GwApi *api){
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init E-Ink display
|
// Init E-Ink display
|
||||||
String displaymode = api->getConfig()->getConfigItem(api->getConfig()->display,true)->asString();
|
String displaymode = config->getConfigItem(config->display,true)->asString();
|
||||||
String displaycolor = api->getConfig()->getConfigItem(api->getConfig()->displaycolor,true)->asString();
|
String displaycolor = config->getConfigItem(config->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 +573,12 @@ void OBP60Task(GwApi *api){
|
||||||
commonData.fgcolor = GxEPD_WHITE;
|
commonData.fgcolor = GxEPD_WHITE;
|
||||||
commonData.bgcolor = GxEPD_BLACK;
|
commonData.bgcolor = GxEPD_BLACK;
|
||||||
}
|
}
|
||||||
String systemname = api->getConfig()->getConfigItem(api->getConfig()->systemName,true)->asString();
|
String systemname = config->getConfigItem(config->systemName, true)->asString();
|
||||||
String wifipass = api->getConfig()->getConfigItem(api->getConfig()->apPassword,true)->asString();
|
String wifipass = config->getConfigItem(config->apPassword, true)->asString();
|
||||||
bool refreshmode = api->getConfig()->getConfigItem(api->getConfig()->refresh,true)->asBoolean();
|
bool refreshmode = config->getConfigItem(config->refresh, true)->asBoolean();
|
||||||
bool symbolmode = (config->getString(config->headerFormat) == "ICON");
|
bool symbolmode = (config->getString(config->headerFormat) == "ICON");
|
||||||
String fastrefresh = api->getConfig()->getConfigItem(api->getConfig()->fastRefresh,true)->asString();
|
String fastrefresh = config->getConfigItem(config->fastRefresh, true)->asString();
|
||||||
uint fullrefreshtime = uint(api->getConfig()->getConfigItem(api->getConfig()->fullRefreshTime,true)->asInt());
|
uint fullrefreshtime = uint(config->getConfigItem(config->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,9 +735,9 @@ void OBP60Task(GwApi *api){
|
||||||
//####################################################################################
|
//####################################################################################
|
||||||
|
|
||||||
// Configuration values for main loop
|
// Configuration values for main loop
|
||||||
String gpsFix = api->getConfig()->getConfigItem(api->getConfig()->flashLED,true)->asString();
|
String gpsFix = config->getConfigItem(config->flashLED,true)->asString();
|
||||||
String gpsOn=api->getConfig()->getConfigItem(api->getConfig()->useGPS,true)->asString();
|
String gpsOn = config->getConfigItem(config->useGPS,true)->asString();
|
||||||
float tz = api->getConfig()->getConfigItem(api->getConfig()->timeZone,true)->asFloat();
|
float tz = config->getConfigItem(config->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());
|
||||||
|
@ -747,11 +747,11 @@ void OBP60Task(GwApi *api){
|
||||||
bool uvoltage = config->getConfigItem(config->underVoltage, true)->asBoolean();
|
bool uvoltage = config->getConfigItem(config->underVoltage, true)->asBoolean();
|
||||||
float voffset = (config->getConfigItem(config->vOffset,true)->asString()).toFloat();
|
float voffset = (config->getConfigItem(config->vOffset,true)->asString()).toFloat();
|
||||||
float vslope = (config->getConfigItem(config->vSlope,true)->asString()).toFloat();
|
float vslope = (config->getConfigItem(config->vSlope,true)->asString()).toFloat();
|
||||||
String cpuspeed = api->getConfig()->getConfigItem(api->getConfig()->cpuSpeed,true)->asString();
|
String cpuspeed = config->getConfigItem(config->cpuSpeed, true)->asString();
|
||||||
uint hdopAccuracy = uint(api->getConfig()->getConfigItem(api->getConfig()->hdopAccuracy,true)->asInt());
|
uint hdopAccuracy = uint(config->getConfigItem(config->hdopAccuracy, true)->asInt());
|
||||||
|
|
||||||
double homelat = commonData.config->getString(commonData.config->homeLAT).toDouble();
|
double homelat = config->getString(config->homeLAT).toDouble();
|
||||||
double homelon = commonData.config->getString(commonData.config->homeLON).toDouble();
|
double homelon = config->getString(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);
|
||||||
|
|
Loading…
Reference in New Issue