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;
|
||||
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
|
||||
|
|
|
@ -86,12 +86,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 +116,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 +276,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 +320,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 +339,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 +361,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 +391,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 +427,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 +453,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 {
|
||||
|
|
|
@ -177,10 +177,15 @@ 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);
|
||||
|
@ -191,10 +196,14 @@ public:
|
|||
// 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);
|
||||
|
|
|
@ -160,9 +160,13 @@ 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(commonData->fmt->placeholder); // Missing bus data
|
||||
|
@ -174,10 +178,14 @@ 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);
|
||||
|
@ -188,10 +196,14 @@ public:
|
|||
// 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);
|
||||
|
|
|
@ -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
|
||||
------------
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -538,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
|
||||
|
@ -563,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;
|
||||
|
@ -573,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
|
||||
|
@ -735,23 +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 = 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 = api->getConfig()->getConfigItem(api->getConfig()->cpuSpeed,true)->asString();
|
||||
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 = 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);
|
||||
|
|
Loading…
Reference in New Issue