From 601d56ee49ee79945779987bf14660ea723db8a6 Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Fri, 29 Aug 2025 19:21:29 +0200 Subject: [PATCH] Calibration feature switchable as compiler option, new page code example by page windrose --- lib/obp60task/OBP60Extensions.cpp | 9 +- lib/obp60task/OBP60Extensions.h | 2 +- lib/obp60task/PageFourValues.cpp | 11 ++ lib/obp60task/PageFourValues2.cpp | 8 ++ lib/obp60task/PageOneValue.cpp | 5 + lib/obp60task/PageRudderPosition.cpp | 8 +- lib/obp60task/PageSixValues.cpp | 5 + lib/obp60task/PageThreeValues.cpp | 17 ++- lib/obp60task/PageTwoValues.cpp | 7 + lib/obp60task/PageWind.cpp | 7 + lib/obp60task/PageWindRose.cpp | 191 +++++++++++++-------------- lib/obp60task/PageWindRoseFlex.cpp | 15 +++ lib/obp60task/obp60task.cpp | 11 +- lib/obp60task/platformio.ini | 8 +- 14 files changed, 191 insertions(+), 113 deletions(-) diff --git a/lib/obp60task/OBP60Extensions.cpp b/lib/obp60task/OBP60Extensions.cpp index 346e820..ab4dc26 100644 --- a/lib/obp60task/OBP60Extensions.cpp +++ b/lib/obp60task/OBP60Extensions.cpp @@ -346,11 +346,14 @@ void setBuzzerPower(uint power){ buzzerpower = power; } -// Delete xdr prefix from string -String xdrDelete(String input){ - if(input.substring(0,3) == "xdr"){ +// Delete xdr prefix from string and optional limit length +String xdrDelete(String input, uint8_t maxlen) { + if (input.substring(0, 3) == "xdr") { input = input.substring(3, input.length()); } + if (maxlen > 0) { + return input.substring(0, maxlen); + } return input; } diff --git a/lib/obp60task/OBP60Extensions.h b/lib/obp60task/OBP60Extensions.h index 4caf5ed..25015cd 100644 --- a/lib/obp60task/OBP60Extensions.h +++ b/lib/obp60task/OBP60Extensions.h @@ -102,7 +102,7 @@ void setBlinkingLED(bool on); // Set blinking flash LED active void buzzer(uint frequency, uint duration); // Buzzer function void setBuzzerPower(uint power); // Set buzzer power -String xdrDelete(String input); // Delete xdr prefix from string +String xdrDelete(String input, uint8_t maxlen = 0); // Delete xdr prefix from string and optional limit length void drawTextCenter(int16_t cx, int16_t cy, String text); void drawTextRalign(int16_t x, int16_t y, String text); diff --git a/lib/obp60task/PageFourValues.cpp b/lib/obp60task/PageFourValues.cpp index 1fd99bb..f8746a0 100644 --- a/lib/obp60task/PageFourValues.cpp +++ b/lib/obp60task/PageFourValues.cpp @@ -3,7 +3,10 @@ #include "Pagedata.h" #include "OBP60Extensions.h" + +#ifdef ENABLE_CALIBRATION #include "BoatDataCalibration.h" +#endif class PageFourValues : public Page { @@ -54,7 +57,9 @@ public: GwApi::BoatValue *bvalue1 = pageData.values[0]; // First element in list (only one value by PageOneValue) String name1 = xdrDelete(bvalue1->getName()); // Value name name1 = name1.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue1, logger); // Check if boat data value is to be calibrated +#endif double value1 = bvalue1->value; // Value as double in SI unit bool valid1 = bvalue1->valid; // Valid information String svalue1 = commonData->fmt->formatValue(bvalue1, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -64,7 +69,9 @@ public: GwApi::BoatValue *bvalue2 = pageData.values[1]; // Second element in list String name2 = xdrDelete(bvalue2->getName()); // Value name name2 = name2.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue2, logger); // Check if boat data value is to be calibrated +#endif double value2 = bvalue2->value; // Value as double in SI unit bool valid2 = bvalue2->valid; // Valid information String svalue2 = commonData->fmt->formatValue(bvalue2, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -74,7 +81,9 @@ public: GwApi::BoatValue *bvalue3 = pageData.values[2]; // Third element in list String name3 = xdrDelete(bvalue3->getName()); // Value name name3 = name3.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue3, logger); // Check if boat data value is to be calibrated +#endif double value3 = bvalue3->value; // Value as double in SI unit bool valid3 = bvalue3->valid; // Valid information String svalue3 = commonData->fmt->formatValue(bvalue3, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -84,7 +93,9 @@ public: GwApi::BoatValue *bvalue4 = pageData.values[3]; // Fourth element in list String name4 = xdrDelete(bvalue4->getName()); // Value name name4 = name4.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue4, logger); // Check if boat data value is to be calibrated +#endif double value4 = bvalue4->value; // Value as double in SI unit bool valid4 = bvalue4->valid; // Valid information String svalue4 = commonData->fmt->formatValue(bvalue4, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places diff --git a/lib/obp60task/PageFourValues2.cpp b/lib/obp60task/PageFourValues2.cpp index 51dfa06..c02822e 100644 --- a/lib/obp60task/PageFourValues2.cpp +++ b/lib/obp60task/PageFourValues2.cpp @@ -54,7 +54,9 @@ public: GwApi::BoatValue *bvalue1 = pageData.values[0]; // First element in list (only one value by PageOneValue) String name1 = xdrDelete(bvalue1->getName()); // Value name name1 = name1.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue1, logger); // Check if boat data value is to be calibrated +#endif double value1 = bvalue1->value; // Value as double in SI unit bool valid1 = bvalue1->valid; // Valid information String svalue1 = commonData->fmt->formatValue(bvalue1, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -64,7 +66,9 @@ public: GwApi::BoatValue *bvalue2 = pageData.values[1]; // Second element in list (only one value by PageOneValue) String name2 = xdrDelete(bvalue2->getName()); // Value name name2 = name2.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue2, logger); // Check if boat data value is to be calibrated +#endif double value2 = bvalue2->value; // Value as double in SI unit bool valid2 = bvalue2->valid; // Valid information String svalue2 = commonData->fmt->formatValue(bvalue2, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -74,7 +78,9 @@ public: GwApi::BoatValue *bvalue3 = pageData.values[2]; // Second element in list (only one value by PageOneValue) String name3 = xdrDelete(bvalue3->getName()); // Value name name3 = name3.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue3, logger); // Check if boat data value is to be calibrated +#endif double value3 = bvalue3->value; // Value as double in SI unit bool valid3 = bvalue3->valid; // Valid information String svalue3 = commonData->fmt->formatValue(bvalue3, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -84,7 +90,9 @@ public: GwApi::BoatValue *bvalue4 = pageData.values[3]; // Second element in list (only one value by PageOneValue) String name4 = xdrDelete(bvalue4->getName()); // Value name name4 = name4.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue4, logger); // Check if boat data value is to be calibrated +#endif double value4 = bvalue4->value; // Value as double in SI unit bool valid4 = bvalue4->valid; // Valid information String svalue4 = commonData->fmt->formatValue(bvalue4, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places diff --git a/lib/obp60task/PageOneValue.cpp b/lib/obp60task/PageOneValue.cpp index c7dbc33..cf3a5fa 100644 --- a/lib/obp60task/PageOneValue.cpp +++ b/lib/obp60task/PageOneValue.cpp @@ -3,7 +3,10 @@ #include "Pagedata.h" #include "OBP60Extensions.h" + +#ifdef ENABLE_CALIBRATION #include "BoatDataCalibration.h" +#endif class PageOneValue : public Page { @@ -49,7 +52,9 @@ public: GwApi::BoatValue *bvalue1 = pageData.values[0]; // First element in list (only one value by PageOneValue) String name1 = xdrDelete(bvalue1->getName()); // Value name name1 = name1.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue1, logger); // Check if boat data value is to be calibrated +#endif double value1 = bvalue1->value; // Value as double in SI unit bool valid1 = bvalue1->valid; // Valid information String svalue1 = commonData->fmt->formatValue(bvalue1, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places diff --git a/lib/obp60task/PageRudderPosition.cpp b/lib/obp60task/PageRudderPosition.cpp index 93a6504..1d150bf 100644 --- a/lib/obp60task/PageRudderPosition.cpp +++ b/lib/obp60task/PageRudderPosition.cpp @@ -3,7 +3,10 @@ #include "Pagedata.h" #include "OBP60Extensions.h" + +#ifdef ENABLE_CALIBRATION #include "BoatDataCalibration.h" +#endif class PageRudderPosition : public Page { @@ -49,7 +52,9 @@ public: GwApi::BoatValue *bvalue1 = pageData.values[0]; // First element in list String name1 = bvalue1->getName().c_str(); // Value name name1 = name1.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue1, logger); // Check if boat data value is to be calibrated +#endif value1 = bvalue1->value; // Raw value without unit convertion bool valid1 = bvalue1->valid; // Valid information String svalue1 = commonData->fmt->formatValue(bvalue1, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -67,8 +72,7 @@ public: } } - // Logging boat values - if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? + // Log boat values logger->logDebug(GwLog::LOG, "Drawing at PageRudderPosition, %s:%f", name1.c_str(), value1); // Draw page diff --git a/lib/obp60task/PageSixValues.cpp b/lib/obp60task/PageSixValues.cpp index 5745731..252cacc 100644 --- a/lib/obp60task/PageSixValues.cpp +++ b/lib/obp60task/PageSixValues.cpp @@ -3,7 +3,10 @@ #include "Pagedata.h" #include "OBP60Extensions.h" + +#ifdef ENABLE_CALIBRATION #include "BoatDataCalibration.h" +#endif const int SixValues_x1 = 5; const int SixValues_DeltaX = 200; @@ -65,7 +68,9 @@ public: bvalue = pageData.values[i]; DataName[i] = xdrDelete(bvalue->getName()); DataName[i] = DataName[i].substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue, logger); // Check if boat data value is to be calibrated +#endif DataValue[i] = bvalue->value; // Value as double in SI unit DataValid[i] = bvalue->valid; DataText[i] = commonData->fmt->formatValue(bvalue, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places diff --git a/lib/obp60task/PageThreeValues.cpp b/lib/obp60task/PageThreeValues.cpp index f40c73a..7292bfd 100644 --- a/lib/obp60task/PageThreeValues.cpp +++ b/lib/obp60task/PageThreeValues.cpp @@ -3,7 +3,10 @@ #include "Pagedata.h" #include "OBP60Extensions.h" + +#ifdef ENABLE_CALIBRATION #include "BoatDataCalibration.h" +#endif class PageThreeValues : public Page { @@ -52,7 +55,9 @@ public: GwApi::BoatValue *bvalue1 = pageData.values[0]; // First element in list (only one value by PageOneValue) String name1 = xdrDelete(bvalue1->getName()); // Value name name1 = name1.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue1, logger); // Check if boat data value is to be calibrated +#endif double value1 = bvalue1->value; // Value as double in SI unit bool valid1 = bvalue1->valid; // Valid information String svalue1 = commonData->fmt->formatValue(bvalue1, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -62,7 +67,9 @@ public: GwApi::BoatValue *bvalue2 = pageData.values[1]; // Second element in list String name2 = xdrDelete(bvalue2->getName()); // Value name name2 = name2.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue2, logger); // Check if boat data value is to be calibrated +#endif double value2 = bvalue2->value; // Value as double in SI unit bool valid2 = bvalue2->valid; // Valid information String svalue2 = commonData->fmt->formatValue(bvalue2, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -72,15 +79,19 @@ public: GwApi::BoatValue *bvalue3 = pageData.values[2]; // Third element in list String name3 = xdrDelete(bvalue3->getName()); // Value name name3 = name3.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue3, logger); // Check if boat data value is to be calibrated +#endif double value3 = bvalue3->value; // Value as double in SI unit bool valid3 = bvalue3->valid; // Valid information String svalue3 = commonData->fmt->formatValue(bvalue3, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places String unit3 = commonData->fmt->formatValue(bvalue3, *commonData).unit; // Unit of value - // Logging boat values - if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? - logger->logDebug(GwLog::LOG, "Drawing at PageThreeValues, %s: %f, %s: %f, %s: %f", name1.c_str(), value1, name2.c_str(), value2, name3.c_str(), value3); + // Log boat values + logger->logDebug(GwLog::LOG, "Drawing at PageThreeValues, %s: %f, %s: %f, %s: %f", + name1.c_str(), value1, + name2.c_str(), value2, + name3.c_str(), value3); // Draw page //*********************************************************** diff --git a/lib/obp60task/PageTwoValues.cpp b/lib/obp60task/PageTwoValues.cpp index 53e9fc4..176eeed 100644 --- a/lib/obp60task/PageTwoValues.cpp +++ b/lib/obp60task/PageTwoValues.cpp @@ -3,7 +3,10 @@ #include "Pagedata.h" #include "OBP60Extensions.h" + +#ifdef ENABLE_CALIBRATION #include "BoatDataCalibration.h" +#endif class PageTwoValues : public Page { @@ -51,7 +54,9 @@ public: GwApi::BoatValue *bvalue1 = pageData.values[0]; // First element in list (only one value by PageOneValue) String name1 = xdrDelete(bvalue1->getName()); // Value name name1 = name1.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue1, logger); // Check if boat data value is to be calibrated +#endif double value1 = bvalue1->value; // Value as double in SI unit bool valid1 = bvalue1->valid; // Valid information String svalue1 = commonData->fmt->formatValue(bvalue1, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -61,7 +66,9 @@ public: GwApi::BoatValue *bvalue2 = pageData.values[1]; // Second element in list String name2 = xdrDelete(bvalue2->getName()); // Value name name2 = name2.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue2, logger); // Check if boat data value is to be calibrated +#endif double value2 = bvalue2->value; // Value as double in SI unit bool valid2 = bvalue2->valid; // Valid information String svalue2 = commonData->fmt->formatValue(bvalue2, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places diff --git a/lib/obp60task/PageWind.cpp b/lib/obp60task/PageWind.cpp index ec5c457..6aff0b0 100644 --- a/lib/obp60task/PageWind.cpp +++ b/lib/obp60task/PageWind.cpp @@ -4,7 +4,10 @@ #include "Pagedata.h" #include "OBP60Extensions.h" #include "N2kMessages.h" + +#ifdef ENABLE_CALIBRATION #include "BoatDataCalibration.h" +#endif #define front_width 120 #define front_height 162 @@ -331,7 +334,9 @@ public: } String name1 = bvalue1->getName().c_str(); // Value name name1 = name1.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue1, logger); // Check if boat data value is to be calibrated +#endif double value1 = bvalue1->value; // Value as double in SI unit // bool valid1 = bvalue1->valid; // Valid information String svalue1 = commonData->fmt->formatValue(bvalue1, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -345,7 +350,9 @@ public: } String name2 = bvalue2->getName().c_str(); // Value name name2 = name2.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue2, logger); // Check if boat data value is to be calibrated +#endif double value2 = bvalue2->value; // Value as double in SI unit // bool valid2 = bvalue2->valid; // Valid information if (simulation) { diff --git a/lib/obp60task/PageWindRose.cpp b/lib/obp60task/PageWindRose.cpp index 57da0f3..1d5e024 100644 --- a/lib/obp60task/PageWindRose.cpp +++ b/lib/obp60task/PageWindRose.cpp @@ -3,7 +3,10 @@ #include "Pagedata.h" #include "OBP60Extensions.h" + +#ifdef ENABLE_CALIBRATION #include "BoatDataCalibration.h" +#endif class PageWindRose : public Page { @@ -42,7 +45,14 @@ public: int displayPage(PageData &pageData) { - static String svalue1old = ""; + // storage for hold valued + static FormattedData bvf_awa_old; + static FormattedData bvf_aws_old; + static FormattedData bvf_twd_old; + static FormattedData bvf_tws_old; + static FormattedData bvf_dbt_old; + static FormattedData bvf_stw_old; + /* static String svalue1old = ""; static String unit1old = ""; static String svalue2old = ""; static String unit2old = ""; @@ -53,116 +63,102 @@ public: static String svalue5old = ""; static String unit5old = ""; static String svalue6old = ""; - static String unit6old = ""; + static String unit6old = ""; */ // Get boat value for AWA - GwApi::BoatValue *bvalue1 = pageData.values[0]; // First element in list (only one value by PageOneValue) - String name1 = xdrDelete(bvalue1->getName()); // Value name - name1 = name1.substring(0, 6); // String length limit for value name - calibrationData.calibrateInstance(bvalue1, logger); // Check if boat data value is to be calibrated - double value1 = bvalue1->value; // Value as double in SI unit - bool valid1 = bvalue1->valid; // Valid information - value1 = commonData->fmt->formatValue(bvalue1, *commonData).value;// Format only nesaccery for simulation data for pointer - String svalue1 = commonData->fmt->formatValue(bvalue1, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places - String unit1 = commonData->fmt->formatValue(bvalue1, *commonData).unit; // Unit of value - if(valid1 == true){ - svalue1old = svalue1; // Save old value - unit1old = unit1; // Save old unit + GwApi::BoatValue *bv_awa = pageData.values[0]; // First element in list + String name_awa = xdrDelete(bv_awa->getName(), 6); // get name without prefix and limit length +#ifdef ENABLE_CALIBRATION + calibrationData.calibrateInstance(bv_awa, logger); // Check if boat data value is to be calibrated +#endif + FormattedData bvf_awa = commonData->fmt->formatValue(bv_awa, *commonData); + if (bv_awa->valid) { // Save formatted data for hold feature + bvf_awa_old = bvf_awa; } // Get boat value for AWS - GwApi::BoatValue *bvalue2 = pageData.values[1]; // Second element in list - String name2 = xdrDelete(bvalue2->getName()); // Value name - name2 = name2.substring(0, 6); // String length limit for value name - calibrationData.calibrateInstance(bvalue2, logger); // Check if boat data value is to be calibrated - double value2 = bvalue2->value; // Value as double in SI unit - bool valid2 = bvalue2->valid; // Valid information - String svalue2 = commonData->fmt->formatValue(bvalue2, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places - String unit2 = commonData->fmt->formatValue(bvalue2, *commonData).unit; // Unit of value - if(valid2 == true){ - svalue2old = svalue2; // Save old value - unit2old = unit2; // Save old unit + GwApi::BoatValue *bv_aws = pageData.values[1]; // Second element in list + String name_aws = xdrDelete(bv_aws->getName(), 6); // get name without prefix and limit length +#ifdef ENABLE_CALIBRATION + calibrationData.calibrateInstance(bv_aws, logger); // Check if boat data value is to be calibrated +#endif + FormattedData bvf_aws = commonData->fmt->formatValue(bv_aws, *commonData); + if (bv_aws->valid) { // Save formatted data for hold feature + bvf_aws_old = bvf_aws; } // Get boat value for TWD - GwApi::BoatValue *bvalue3 = pageData.values[2]; // Third element in list - String name3 = xdrDelete(bvalue3->getName()); // Value name - name3 = name3.substring(0, 6); // String length limit for value name - calibrationData.calibrateInstance(bvalue3, logger); // Check if boat data value is to be calibrated - double value3 = bvalue3->value; // Value as double in SI unit - bool valid3 = bvalue3->valid; // Valid information - String svalue3 = commonData->fmt->formatValue(bvalue3, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places - String unit3 = commonData->fmt->formatValue(bvalue3, *commonData).unit; // Unit of value - if(valid3 == true){ - svalue3old = svalue3; // Save old value - unit3old = unit3; // Save old unit + GwApi::BoatValue *bv_twd = pageData.values[2]; // Third element in list + String name_twd = xdrDelete(bv_twd->getName(), 6); // get name without prefix and limit length +#ifdef ENABLE_CALIBRATION + calibrationData.calibrateInstance(bv_twd, logger); // Check if boat data value is to be calibrated +#endif + FormattedData bvf_twd = commonData->fmt->formatValue(bv_twd, *commonData); + if (bv_twd->valid) { // Save formatted data for hold feature + bvf_twd_old = bvf_twd; } // Get boat value for TWS - GwApi::BoatValue *bvalue4 = pageData.values[3]; // Fourth element in list - String name4 = xdrDelete(bvalue4->getName()); // Value name - name4 = name4.substring(0, 6); // String length limit for value name - calibrationData.calibrateInstance(bvalue4, logger); // Check if boat data value is to be calibrated - double value4 = bvalue4->value; // Value as double in SI unit - bool valid4 = bvalue4->valid; // Valid information - String svalue4 = commonData->fmt->formatValue(bvalue4, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places - String unit4 = commonData->fmt->formatValue(bvalue4, *commonData).unit; // Unit of value - if(valid4 == true){ - svalue4old = svalue4; // Save old value - unit4old = unit4; // Save old unit + GwApi::BoatValue *bv_tws = pageData.values[3]; // Fourth element in list + String name_tws = xdrDelete(bv_tws->getName(), 6); // get name without prefix and limit length +#ifdef ENABLE_CALIBRATION + calibrationData.calibrateInstance(bv_tws, logger); // Check if boat data value is to be calibrated +#endif + FormattedData bvf_tws = commonData->fmt->formatValue(bv_tws, *commonData); + if (bv_tws->valid) { // Save formatted data for hold feature + bvf_tws_old = bvf_tws; } // Get boat value for DBT - GwApi::BoatValue *bvalue5 = pageData.values[4]; // Fifth element in list - String name5 = xdrDelete(bvalue5->getName()); // Value name - name5 = name5.substring(0, 6); // String length limit for value name - calibrationData.calibrateInstance(bvalue5, logger); // Check if boat data value is to be calibrated - double value5 = bvalue5->value; // Value as double in SI unit - bool valid5 = bvalue5->valid; // Valid information - String svalue5 = commonData->fmt->formatValue(bvalue5, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places - String unit5 = commonData->fmt->formatValue(bvalue5, *commonData).unit; // Unit of value - if(valid5 == true){ - svalue5old = svalue5; // Save old value - unit5old = unit5; // Save old unit + GwApi::BoatValue *bv_dbt = pageData.values[4]; // Fifth element in list + String name_dbt = xdrDelete(bv_dbt->getName(), 6); // get name without prefix and limit length +#ifdef ENABLE_CALIBRATION + calibrationData.calibrateInstance(bv_dbt, logger); // Check if boat data value is to be calibrated +#endif + FormattedData bvf_dbt = commonData->fmt->formatValue(bv_dbt, *commonData); + if (bv_dbt->valid) { // Save formatted data for hold feature + bvf_dbt_old = bvf_dbt; } // Get boat value for STW - GwApi::BoatValue *bvalue6 = pageData.values[5]; // Sixth element in list - String name6 = xdrDelete(bvalue6->getName()); // Value name - name6 = name6.substring(0, 6); // String length limit for value name - calibrationData.calibrateInstance(bvalue6, logger); // Check if boat data value is to be calibrated - double value6 = bvalue6->value; // Value as double in SI unit - bool valid6 = bvalue6->valid; // Valid information - String svalue6 = commonData->fmt->formatValue(bvalue6, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places - String unit6 = commonData->fmt->formatValue(bvalue6, *commonData).unit; // Unit of value - if(valid6 == true){ - svalue6old = svalue6; // Save old value - unit6old = unit6; // Save old unit + GwApi::BoatValue *bv_stw = pageData.values[5]; // Sixth element in list + String name_stw = xdrDelete(bv_stw->getName(), 6); // get name without prefix and limit length +#ifdef ENABLE_CALIBRATION + calibrationData.calibrateInstance(bv_stw, logger); // Check if boat data value is to be calibrated +#endif + FormattedData bvf_stw = commonData->fmt->formatValue(bv_stw, *commonData); + if (bv_stw->valid) { // Save formatted data for hold feature + bvf_stw_old = bvf_stw; } - // Logging boat values - if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? - logger->logDebug(GwLog::LOG, "Drawing at PageWindRose, %s:%f, %s:%f, %s:%f, %s:%f, %s:%f, %s:%f", name1.c_str(), value1, name2.c_str(), value2, name3.c_str(), value3, name4.c_str(), value4, name5.c_str(), value5, name6.c_str(), value6); + // Log boat values + logger->logDebug(GwLog::LOG, "Drawing at PageWindRose, %s:%f, %s:%f, %s:%f, %s:%f, %s:%f, %s:%f", + name_awa.c_str(), bv_awa->value, + name_aws.c_str(), bv_aws->value, + name_twd.c_str(), bv_twd->value, + name_tws.c_str(), bv_tws->value, + name_dbt.c_str(), bv_dbt->value, + name_stw.c_str(), bv_stw->value); // Draw page - //*********************************************************** + // ********************************************************************* // Set display in partial refresh mode - epd->setPartialWindow(0, 0, epd->width(), epd->height()); // Set partial update + epd->setPartialWindow(0, 0, epd->width(), epd->height()); epd->setTextColor(commonData->fgcolor); // Show values AWA epd->setFont(&DSEG7Classic_BoldItalic20pt7b); epd->setCursor(10, 65); - epd->print(svalue1); // Value + epd->print(holdvalues ? bvf_awa_old.value : bvf_awa.value); epd->setFont(&Ubuntu_Bold12pt8b); epd->setCursor(10, 95); - epd->print(name1); // Name + epd->print(name_awa); epd->setFont(&Ubuntu_Bold8pt8b); epd->setCursor(10, 115); epd->print(" "); - epd->print(holdvalues ? unit1old : unit1); + epd->print(holdvalues ? bvf_awa_old.unit : bvf_awa.unit); // Horizintal separator left epd->fillRect(0, 149, 60, 3, commonData->fgcolor); @@ -170,31 +166,32 @@ public: // Show values AWS epd->setFont(&DSEG7Classic_BoldItalic20pt7b); epd->setCursor(10, 270); - epd->print(svalue2); // Value + epd->print(holdvalues ? bvf_aws_old.value : bvf_aws.value); epd->setFont(&Ubuntu_Bold12pt8b); epd->setCursor(10, 220); - epd->print(name2); // Name + epd->print(name_aws); epd->setFont(&Ubuntu_Bold8pt8b); epd->setCursor(10, 190); epd->print(" "); - epd->print(holdvalues ? unit2old : unit2); + epd->print(holdvalues ? bvf_aws_old.unit : bvf_aws.unit); - // Show values TWD + // Show value TWD epd->setFont(&DSEG7Classic_BoldItalic20pt7b); epd->setCursor(295, 65); - if (valid3 == true) { - epd->print(abs(value3 * 180 / PI), 0); // Value + // TODO WTF? Der Formatter sollte das korrekt machen + if (bv_twd->valid) { + epd->print(abs(bv_twd->value * 180 / PI), 0); // Value } else { epd->print(commonData->fmt->placeholder); } epd->setFont(&Ubuntu_Bold12pt8b); epd->setCursor(335, 95); - epd->print(name3); // Name + epd->print(name_twd); // Name epd->setFont(&Ubuntu_Bold8pt8b); epd->setCursor(335, 115); epd->print(" "); - epd->print(holdvalues ? unit3old : unit3); + epd->print(holdvalues ? bvf_twd_old.unit : bvf_twd.unit); // Horizintal separator right epd->fillRect(340, 149, 80, 3, commonData->fgcolor); @@ -202,16 +199,16 @@ public: // Show values TWS epd->setFont(&DSEG7Classic_BoldItalic20pt7b); epd->setCursor(295, 270); - epd->print(svalue4); // Value + epd->print(name_tws); epd->setFont(&Ubuntu_Bold12pt8b); epd->setCursor(335, 220); - epd->print(name4); // Name + epd->print(holdvalues ? bvf_tws_old.value : bvf_tws.value); epd->setFont(&Ubuntu_Bold8pt8b); epd->setCursor(335, 190); epd->print(" "); - epd->print(holdvalues ? unit4old : unit4); + epd->print(holdvalues ? bvf_tws_old.unit : bvf_tws.unit); -//******************************************************************************************* + // ********************************************************************* // Draw wind rose int rInstrument = 110; // Radius of grafic instrument @@ -279,9 +276,9 @@ public: // Draw wind pointer float startwidth = 8; // Start width of pointer - if(valid2 == true || holdvalues == true || simulation == true){ - float sinx=sin(value1); // Wind direction - float cosx=cos(value1); + if (bv_aws->valid|| holdvalues || simulation) { + float sinx = sin(bv_awa->value); // Wind direction + float cosx = cos(bv_awa->value); // Normal pointer // Pointer as triangle with center base 2*width float xx1 = -startwidth; @@ -307,25 +304,25 @@ public: epd->fillCircle(200, 150, startwidth + 6, commonData->bgcolor); epd->fillCircle(200, 150, startwidth + 4, commonData->fgcolor); -//******************************************************************************************* + // ********************************************************************* // Show values DBT epd->setFont(&DSEG7Classic_BoldItalic16pt7b); epd->setCursor(160, 200); - epd->print(svalue5); // Value + epd->print(holdvalues ? bvf_dbt_old.value : bvf_dbt.value); epd->setFont(&Ubuntu_Bold8pt8b); epd->setCursor(190, 215); epd->print(" "); - epd->print(holdvalues ? unit5old : unit5); + epd->print(holdvalues ? bvf_dbt_old.unit : bvf_dbt.unit); // Show values STW epd->setFont(&DSEG7Classic_BoldItalic16pt7b); epd->setCursor(160, 130); - epd->print(svalue6); // Value + epd->print(holdvalues ? bvf_stw_old.value : bvf_stw.value); epd->setFont(&Ubuntu_Bold8pt8b); epd->setCursor(190, 90); epd->print(" "); - epd->print(holdvalues ? unit6old : unit6); + epd->print(holdvalues ? bvf_stw_old.unit : bvf_stw.unit); return PAGE_UPDATE; }; diff --git a/lib/obp60task/PageWindRoseFlex.cpp b/lib/obp60task/PageWindRoseFlex.cpp index 117b697..31300ae 100644 --- a/lib/obp60task/PageWindRoseFlex.cpp +++ b/lib/obp60task/PageWindRoseFlex.cpp @@ -3,7 +3,10 @@ #include "Pagedata.h" #include "OBP60Extensions.h" + +#ifdef ENABLE_CALIBRATION #include "BoatDataCalibration.h" +#endif class PageWindRoseFlex : public Page { @@ -73,7 +76,9 @@ public: } String name1 = bvalue1->getName().c_str(); // Value name name1 = name1.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue1, logger); // Check if boat data value is to be calibrated +#endif double value1 = bvalue1->value; // Value as double in SI unit bool valid1 = bvalue1->valid; // Valid information String svalue1 = commonData->fmt->formatValue(bvalue1, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -91,7 +96,9 @@ public: } String name2 = bvalue2->getName().c_str(); // Value name name2 = name2.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue2, logger); // Check if boat data value is to be calibrated +#endif double value2 = bvalue2->value; // Value as double in SI unit bool valid2 = bvalue2->valid; // Valid information if (simulation) { @@ -108,7 +115,9 @@ public: GwApi::BoatValue *bvalue3 = pageData.values[0]; String name3 = xdrDelete(bvalue3->getName()); // Value name name3 = name3.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue3, logger); // Check if boat data value is to be calibrated +#endif double value3 = bvalue3->value; // Value as double in SI unit bool valid3 = bvalue3->valid; // Valid information String svalue3 = commonData->fmt->formatValue(bvalue3, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -122,7 +131,9 @@ public: GwApi::BoatValue *bvalue4 = pageData.values[1]; String name4 = xdrDelete(bvalue4->getName()); // Value name name4 = name4.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue4, logger); // Check if boat data value is to be calibrated +#endif double value4 = bvalue4->value; // Value as double in SI unit bool valid4 = bvalue4->valid; // Valid information String svalue4 = commonData->fmt->formatValue(bvalue4, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -136,7 +147,9 @@ public: GwApi::BoatValue *bvalue5 = pageData.values[2]; String name5 = xdrDelete(bvalue5->getName()); // Value name name5 = name5.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue5, logger); // Check if boat data value is to be calibrated +#endif double value5 = bvalue5->value; // Value as double in SI unit bool valid5 = bvalue5->valid; // Valid information String svalue5 = commonData->fmt->formatValue(bvalue5, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places @@ -150,7 +163,9 @@ public: GwApi::BoatValue *bvalue6 = pageData.values[3]; String name6 = xdrDelete(bvalue6->getName()); // Value name name6 = name6.substring(0, 6); // String length limit for value name +#ifdef ENABLE_CALIBRATION calibrationData.calibrateInstance(bvalue6, logger); // Check if boat data value is to be calibrated +#endif double value6 = bvalue6->value; // Value as double in SI unit bool valid6 = bvalue6->valid; // Valid information String svalue6 = commonData->fmt->formatValue(bvalue6, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index 93467f6..55157cd 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -383,6 +383,7 @@ bool addTrueWind(GwApi* api, BoatValueList* boatValues) { return isCalculated; } + // Init history buffers for selected boat data void initHstryBuf(GwApi* api, BoatValueList* boatValues, tBoatHstryData hstryBufList) { @@ -700,11 +701,11 @@ void OBP60Task(GwApi *api){ calibrationData.readConfig(config, logger); // Check user setting for true wind calculation - bool calcTrueWnds = api->getConfig()->getBool(api->getConfig()->calcTrueWnds, false); + //bool calcTrueWnds = api->getConfig()->getBool(api->getConfig()->calcTrueWnds, false); bool simulation = api->getConfig()->getBool(api->getConfig()->useSimuData, false); // Initialize history buffer for certain boat data - initHstryBuf(api, &boatValues, hstryBufList); + //initHstryBuf(api, &boatValues, hstryBufList); // Display screenshot handler for HTTP request // http://192.168.15.1/api/user/OBP60Task/screenshot @@ -1017,11 +1018,11 @@ void OBP60Task(GwApi *api){ api->getBoatDataValues(boatValues.numValues,boatValues.allBoatValues); api->getStatus(commonData.status); - if (calcTrueWnds) { + /*if (calcTrueWnds) { addTrueWind(api, &boatValues); - } + }*/ // Handle history buffers for TWD, TWS for wind plot page and other usage - handleHstryBuf(api, &boatValues, hstryBufList, simulation); + //handleHstryBuf(api, &boatValues, hstryBufList, simulation); // Clear display // epd->fillRect(0, 0, epd->width(), epd->height(), commonData.bgcolor); diff --git a/lib/obp60task/platformio.ini b/lib/obp60task/platformio.ini index 6af4c95..cc1a6f1 100644 --- a/lib/obp60task/platformio.ini +++ b/lib/obp60task/platformio.ini @@ -51,6 +51,8 @@ build_flags= # -D DISPLAY_GYE042A87 #alternativ E-Ink display from Genyo Optical, R10 2.2 ohm - medium # -D DISPLAY_SE0420NQ04 #alternativ E-Ink display from SID Technology, R10 2.2 ohm - bad (burn in effects) # -D DISPLAY_ZJY400300-042CAAMFGN #alternativ E-Ink display from ZZE Technology, R10 2.2 ohm - very good +# -D ENABLE_TRUEWIND # calculate true wind data (default off) +# -D ENABLE_CALIBRATION # boat data calibration (default off) ${env.build_flags} #CONFIG_ESP_TASK_WDT_TIMEOUT_S = 10 #Task Watchdog timeout period (seconds) [1...60] 5 default upload_port = /dev/ttyACM0 #OBP60 download via USB-C direct @@ -92,8 +94,10 @@ build_flags= -D HARDWARE_V10 #OBP40 hardware revision V1.0 SKU:DIE07300S V1.1 (CrowPanel 4.2) -D DISPLAY_GDEY042T81 #new E-Ink display from Good Display (Waveshare), R10 2.2 ohm - good (contast lost by shunshine) #-D DISPLAY_ZJY400300-042CAAMFGN #alternativ E-Ink display from ZZE Technology, R10 2.2 ohm - very good - #-D LIPO_ACCU_1200 #Hardware extension, LiPo accu 3,7V 1200mAh - #-D VOLTAGE_SENSOR #Hardware extension, LiPo voltage sensor with two resistors +# -D LIPO_ACCU_1200 #Hardware extension, LiPo accu 3,7V 1200mAh +# -D VOLTAGE_SENSOR #Hardware extension, LiPo voltage sensor with two resistors +# -D ENABLE_TRUEWIND # calculate true wind data (default off) +# -D ENABLE_CALIBRATION # boat data calibration (default off) ${env.build_flags} upload_port = /dev/ttyUSB0 #OBP40 download via external USB/Serail converter upload_protocol = esptool #firmware upload via USB OTG seriell, by first upload need to set the ESP32-S3 in the upload mode with shortcut GND to Pin27