diff --git a/lib/obp60task/OBPcharts.cpp b/lib/obp60task/OBPcharts.cpp index 9830653..2e4aaea 100644 --- a/lib/obp60task/OBPcharts.cpp +++ b/lib/obp60task/OBPcharts.cpp @@ -4,6 +4,15 @@ #include "OBPDataOperations.h" #include "OBPRingBuffer.h" +std::map Chart::dfltChrtDta = { + { "formatWind", { 60.0 * DEG_TO_RAD, 10.0 * DEG_TO_RAD } }, // default course range 60 degrees + { "formatCourse", { 60.0 * DEG_TO_RAD, 10.0 * DEG_TO_RAD } }, // default course range 60 degrees + //{ "formatKnots", { 7.71, 2.57 } }, // default speed range in m/s + { "formatKnots", { 7.71, 2.56 } }, // default speed range in m/s + { "formatDepth", { 15.0, 5.0 } }, // default depth range in m + { "kelvinToC", { 30.0, 5.0 } } // default temp range in °C/K +}; + // --- Class Chart --------------- // Chart - object holding the actual chart, incl. data buffer and format definition @@ -12,11 +21,11 @@ // default range of chart, e.g. 30 = [0..30]; // common program data; required for logger and color data // flag to indicate if simulation data is active -template -Chart::Chart(RingBuffer& dataBuf, char chrtDir, int8_t chrtSz, double dfltRng, CommonData& common, bool useSimuData) +// Chart::Chart(RingBuffer& dataBuf, char chrtDir, int8_t chrtSz, double dfltRng, CommonData& common, bool useSimuData) +Chart::Chart(RingBuffer& dataBuf, double dfltRng, CommonData& common, bool useSimuData) : dataBuf(dataBuf) - , chrtDir(chrtDir) - , chrtSz(chrtSz) + //, chrtDir(chrtDir) + //, chrtSz(chrtSz) , dfltRng(dfltRng) , commonData(&common) , useSimuData(useSimuData) @@ -28,51 +37,51 @@ Chart::Chart(RingBuffer& dataBuf, char chrtDir, int8_t chrtSz, double dflt dWidth = getdisplay().width(); dHeight = getdisplay().height(); - if (chrtDir == 'H') { - // horizontal chart timeline direction - timAxis = dWidth - 1; - switch (chrtSz) { - case 0: - valAxis = dHeight - top - bottom; - cRoot = { 0, top - 1 }; - break; - case 1: - valAxis = (dHeight - top - bottom) / 2 - hGap; - cRoot = { 0, top - 1 }; - break; - case 2: - valAxis = (dHeight - top - bottom) / 2 - hGap; - cRoot = { 0, top + (valAxis + hGap) + hGap - 1 }; - break; - default: - LOG_DEBUG(GwLog::ERROR, "obp60:Chart %s: wrong init parameter", dataBuf.getName()); - return; - } + /* if (chrtDir == 'H') { + // horizontal chart timeline direction + timAxis = dWidth - 1; + switch (chrtSz) { + case 0: + valAxis = dHeight - top - bottom; + cRoot = { 0, top - 1 }; + break; + case 1: + valAxis = (dHeight - top - bottom) / 2 - hGap; + cRoot = { 0, top - 1 }; + break; + case 2: + valAxis = (dHeight - top - bottom) / 2 - hGap; + cRoot = { 0, top + (valAxis + hGap) + hGap - 1 }; + break; + default: + LOG_DEBUG(GwLog::ERROR, "obp60:Chart %s: wrong init parameter", dataBuf.getName()); + return; + } - } else if (chrtDir == 'V') { - // vertical chart timeline direction - timAxis = dHeight - top - bottom; - switch (chrtSz) { - case 0: - valAxis = dWidth - 1; - cRoot = { 0, top - 1 }; - break; - case 1: - valAxis = dWidth / 2 - vGap; - cRoot = { 0, top - 1 }; - break; - case 2: - valAxis = dWidth / 2 - vGap; - cRoot = { dWidth / 2 + vGap - 1, top - 1 }; - break; - default: + } else if (chrtDir == 'V') { + // vertical chart timeline direction + timAxis = dHeight - top - bottom; + switch (chrtSz) { + case 0: + valAxis = dWidth - 1; + cRoot = { 0, top - 1 }; + break; + case 1: + valAxis = dWidth / 2 - vGap; + cRoot = { 0, top - 1 }; + break; + case 2: + valAxis = dWidth / 2 - vGap; + cRoot = { dWidth / 2 + vGap - 1, top - 1 }; + break; + default: + LOG_DEBUG(GwLog::ERROR, "obp60:Chart %s: wrong init parameter", dataBuf.getName()); + return; + } + } else { LOG_DEBUG(GwLog::ERROR, "obp60:Chart %s: wrong init parameter", dataBuf.getName()); return; - } - } else { - LOG_DEBUG(GwLog::ERROR, "obp60:Chart %s: wrong init parameter", dataBuf.getName()); - return; - } + } */ dataBuf.getMetaData(dbName, dbFormat); dbMIN_VAL = dataBuf.getMinVal(); @@ -116,9 +125,6 @@ Chart::Chart(RingBuffer& dataBuf, char chrtDir, int8_t chrtSz, double dflt rngStep = 5.0; } - //chrtMin = dbMIN_VAL; - //chrtMax = dbMAX_VAL; - //chrtMid = dbMAX_VAL; // Initialize chart range values chrtMin = zeroValue; chrtMax = chrtMin + dfltRng; @@ -130,35 +136,93 @@ Chart::Chart(RingBuffer& dataBuf, char chrtDir, int8_t chrtSz, double dflt dWidth, dHeight, timAxis, valAxis, cRoot.x, cRoot.y, dbName, rngStep, chrtDataFmt); }; -template -Chart::~Chart() +Chart::~Chart() { } // Perform all actions to draw chart -// Parameters: chart time interval, current boat data value to be printed, current boat data shall be shown yes/no -template -void Chart::showChrt(GwApi::BoatValue currValue, int8_t& chrtIntv, const bool showCurrValue) +// Parameters: : chart timeline direction: 'H' = horizontal, 'V' = vertical +// : chart size: [0] = full size, [1] = half size left/top, [2] half size right/bottom +// : chart timeline interval +// : current boat data shall be shown [true/false] +// : current boat data value to be printed +// void Chart::showChrt(GwApi::BoatValue currValue, int8_t& chrtIntv, const bool showCurrValue) +void Chart::showChrt(char chrtDir, int8_t chrtSz, int8_t& chrtIntv, bool showCurrValue, GwApi::BoatValue currValue) { - drawChrt(chrtIntv, currValue); - drawChrtTimeAxis(chrtIntv); - drawChrtValAxis(); + // this->chrtDir = chrtDir; + // this->chrtSz = chrtSz; + + if (!setChartDimensions(chrtDir, chrtSz)) { + return; // wrong chart dimension parameters + } + + drawChrt(chrtDir, chrtIntv, currValue); + drawChrtTimeAxis(chrtDir, chrtSz, chrtIntv); + drawChrtValAxis(chrtDir, chrtSz); if (!bufDataValid) { // No valid data available - prntNoValidData(); + prntNoValidData(chrtDir); return; } - if (showCurrValue) { // shows latest value from history buffer; usually this should be the most current one + if (showCurrValue) { // show latest value from history buffer; usually this should be the most current one currValue.value = dataBuf.getLast(); currValue.valid = currValue.value != dbMAX_VAL; - Chart::prntCurrValue(currValue); + prntCurrValue(chrtDir, currValue); } } +// define dimensions and start points for chart +bool Chart::setChartDimensions(const char direction, const int8_t size) +{ + if ((direction != 'H' && direction != 'V') || (size < 0 || size > 2)) { + LOG_DEBUG(GwLog::ERROR, "obp60:setChartDimensions %s: wrong parameters", dataBuf.getName()); + return false; + } + + if (direction == 'H') { + // horizontal chart timeline direction + timAxis = dWidth - 1; + switch (size) { + case 0: + valAxis = dHeight - top - bottom; + cRoot = { 0, top - 1 }; + break; + case 1: + valAxis = (dHeight - top - bottom) / 2 - hGap; + cRoot = { 0, top - 1 }; + break; + case 2: + valAxis = (dHeight - top - bottom) / 2 - hGap; + cRoot = { 0, top + (valAxis + hGap) + hGap - 1 }; + break; + } + + } else if (direction == 'V') { + // vertical chart timeline direction + timAxis = dHeight - top - bottom; + switch (size) { + case 0: + valAxis = dWidth - 1; + cRoot = { 0, top - 1 }; + break; + case 1: + valAxis = dWidth / 2 - vGap; + cRoot = { 0, top - 1 }; + break; + case 2: + valAxis = dWidth / 2 - vGap; + cRoot = { dWidth / 2 + vGap - 1, top - 1 }; + break; + } + } + LOG_DEBUG(GwLog::ERROR, "obp60:setChartDimensions %s: direction: %c, size: %d, dWidth: %d, dHeight: %d, timAxis: %d, valAxis: %d, cRoot{%d, %d}, top: %d, bottom: %d, hGap: %d, vGap: %d", + dataBuf.getName(), direction, size, dWidth, dHeight, timAxis, valAxis, cRoot.x, cRoot.y, top, bottom, hGap, vGap); + return true; +} + // draw chart -template -void Chart::drawChrt(int8_t& chrtIntv, GwApi::BoatValue& currValue) +void Chart::drawChrt(const char chrtDir, int8_t& chrtIntv, GwApi::BoatValue& currValue) { double chrtVal; // Current data value double chrtScl; // Scale for data values in pixels per value @@ -167,9 +231,9 @@ void Chart::drawChrt(int8_t& chrtIntv, GwApi::BoatValue& currValue) getBufStartNSize(chrtIntv); - // LOG_DEBUG(GwLog::DEBUG, "PageOneValue:drawChart: min: %.1f, mid: %.1f, max: %.1f, rng: %.1f", chrtMin, chrtMid, chrtMax, chrtRng); + // LOG_DEBUG(GwLog::DEBUG, "Chart:drawChart: min: %.1f, mid: %.1f, max: %.1f, rng: %.1f", chrtMin, chrtMid, chrtMax, chrtRng); calcChrtBorders(chrtMin, chrtMid, chrtMax, chrtRng); - LOG_DEBUG(GwLog::DEBUG, "PageOneValue:drawChart2: min: %.1f, mid: %.1f, max: %.1f, rng: %.1f", chrtMin, chrtMid, chrtMax, chrtRng); + LOG_DEBUG(GwLog::DEBUG, "Chart:drawChart2: min: %.1f, mid: %.1f, max: %.1f, rng: %.1f", chrtMin, chrtMid, chrtMax, chrtRng); // Chart scale: pixels per value step chrtScl = double(valAxis) / chrtRng; @@ -290,8 +354,7 @@ void Chart::drawChrt(int8_t& chrtIntv, GwApi::BoatValue& currValue) } // Identify buffer size and buffer start position for chart -template -void Chart::getBufStartNSize(int8_t& chrtIntv) +void Chart::getBufStartNSize(int8_t& chrtIntv) { count = dataBuf.getCurrentSize(); currIdx = dataBuf.getLastIdx(); @@ -314,8 +377,7 @@ void Chart::getBufStartNSize(int8_t& chrtIntv) } // check and adjust chart range and set range borders and range middle -template -void Chart::calcChrtBorders(double& rngMin, double& rngMid, double& rngMax, double& rng) +void Chart::calcChrtBorders(double& rngMin, double& rngMid, double& rngMax, double& rng) { if (chrtDataFmt == 'W' || chrtDataFmt == 'R') { // Chart data is of type 'course', 'wind' or 'rot' @@ -413,8 +475,7 @@ void Chart::calcChrtBorders(double& rngMin, double& rngMid, double& rngMax, d } // chart time axis label + lines -template -void Chart::drawChrtTimeAxis(int8_t& chrtIntv) +void Chart::drawChrtTimeAxis(const char chrtDir, const int8_t chrtSz, int8_t& chrtIntv) { float axSlots, intv, i; char sTime[6]; @@ -461,8 +522,7 @@ void Chart::drawChrtTimeAxis(int8_t& chrtIntv) } // chart value axis labels + lines -template -void Chart::drawChrtValAxis() +void Chart::drawChrtValAxis(const char chrtDir, const int8_t chrtSz) { double axLabel; double cVal; @@ -538,8 +598,7 @@ void Chart::drawChrtValAxis() } // Print current data value -template -void Chart::prntCurrValue(GwApi::BoatValue& currValue) +void Chart::prntCurrValue(const char chrtDir, GwApi::BoatValue& currValue) { const int xPosVal = (chrtDir == 'H') ? cRoot.x + (timAxis / 2) - 56 : cRoot.x + 32; const int yPosVal = (chrtDir == 'H') ? cRoot.y + valAxis - 7 : cRoot.y + timAxis - 7; @@ -566,8 +625,7 @@ void Chart::prntCurrValue(GwApi::BoatValue& currValue) } // print message for no valid data availabletemplate -template -void Chart::prntNoValidData() +void Chart::prntNoValidData(const char chrtDir) { int pX, pY; @@ -588,8 +646,7 @@ void Chart::prntNoValidData() } // Get maximum difference of last of dataBuf ringbuffer values to center chart; for angle data only -template -double Chart::getAngleRng(double center, size_t amount) +double Chart::getAngleRng(double center, size_t amount) { size_t count = dataBuf.getCurrentSize(); @@ -624,8 +681,7 @@ double Chart::getAngleRng(double center, size_t amount) } // print horizontal axis label with only three values: top, mid, and bottom -template -void Chart::prntHorizThreeValueAxisLabel(const GFXfont* font) +void Chart::prntHorizThreeValueAxisLabel(const GFXfont* font) { double axLabel; double chrtMin, chrtMid, chrtMax; @@ -637,7 +693,7 @@ void Chart::prntHorizThreeValueAxisLabel(const GFXfont* font) yOffset = 15; } else if (font == &Ubuntu_Bold12pt8b) { xOffset = 51; - yOffset = 17; + yOffset = 18; } getdisplay().setFont(font); @@ -658,8 +714,8 @@ void Chart::prntHorizThreeValueAxisLabel(const GFXfont* font) // print mid axis label axLabel = chrtMid; sVal = formatLabel(axLabel); - getdisplay().fillRect(cRoot.x, cRoot.y + (valAxis / 2) - 9, xOffset + 4, 16, bgColor); // Clear small area to remove potential chart lines - drawTextRalign(cRoot.x + xOffset, cRoot.y + (valAxis / 2) + 5, sVal); // range value + getdisplay().fillRect(cRoot.x, cRoot.y + (valAxis / 2) - 8, xOffset + 4, 16, bgColor); // Clear small area to remove potential chart lines + drawTextRalign(cRoot.x + xOffset, cRoot.y + (valAxis / 2) + 6, sVal); // range value getdisplay().drawLine(cRoot.x + xOffset + 4, cRoot.y + (valAxis / 2), cRoot.x + timAxis, cRoot.y + (valAxis / 2), fgColor); // print bottom axis label @@ -671,8 +727,7 @@ void Chart::prntHorizThreeValueAxisLabel(const GFXfont* font) } // print horizontal axis label with multiple axis lines -template -void Chart::prntHorizMultiValueAxisLabel(const GFXfont* font) +void Chart::prntHorizMultiValueAxisLabel(const GFXfont* font) { double chrtMin, chrtMax, chrtRng; double axSlots, axIntv, axLabel; @@ -724,8 +779,7 @@ void Chart::prntHorizMultiValueAxisLabel(const GFXfont* font) } // Draw chart line with thickness of 2px -template -void Chart::drawBoldLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2) +void Chart::drawBoldLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { int16_t dx = std::abs(x2 - x1); @@ -741,8 +795,7 @@ void Chart::drawBoldLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2) } // Convert and format current axis label to user defined format; helper function for easier handling of OBP60Formatter -template -String Chart::convNformatLabel(double label) +String Chart::convNformatLabel(double label) { GwApi::BoatValue tmpBVal(dbName); // temporary boat value for string formatter String sVal; @@ -759,8 +812,7 @@ String Chart::convNformatLabel(double label) } // Format current axis label for printing w/o data format conversion (has been done earlier) -template -String Chart::formatLabel(const double& label) +String Chart::formatLabel(const double& label) { char sVal[11]; @@ -786,7 +838,4 @@ String Chart::formatLabel(const double& label) return String(sVal); } - -// Explicitly instantiate class with required data types to avoid linker errors -template class Chart; // --- Class Chart --------------- diff --git a/lib/obp60task/OBPcharts.h b/lib/obp60task/OBPcharts.h index db62a3c..c6d24b2 100644 --- a/lib/obp60task/OBPcharts.h +++ b/lib/obp60task/OBPcharts.h @@ -17,15 +17,14 @@ template class RingBuffer; class GwLog; -template class Chart { protected: CommonData* commonData; GwLog* logger; - RingBuffer& dataBuf; // Buffer to display - char chrtDir; // Chart timeline direction: 'H' = horizontal, 'V' = vertical - int8_t chrtSz; // Chart size: [0] = full size, [1] = half size left/top, [2] half size right/bottom + RingBuffer& dataBuf; // Buffer to display + //char chrtDir; // Chart timeline direction: 'H' = horizontal, 'V' = vertical + //int8_t chrtSz; // Chart size: [0] = full size, [1] = half size left/top, [2] half size right/bottom double dfltRng; // Default range of chart, e.g. 30 = [0..30] uint16_t fgColor; // color code for any screen writing uint16_t bgColor; // color code for screen background @@ -72,13 +71,14 @@ protected: static constexpr int8_t THRESHOLD_NO_DATA = 3; static constexpr int8_t VALAXIS_STEP = 60; - void drawChrt(int8_t& chrtIntv, GwApi::BoatValue& currValue); // Draw chart line + bool setChartDimensions(const char direction, const int8_t size); //define dimensions and start points for chart + void drawChrt(const char chrtDir, int8_t& chrtIntv, GwApi::BoatValue& currValue); // Draw chart line void getBufStartNSize(int8_t& chrtIntv); // Identify buffer size and buffer start position for chart void calcChrtBorders(double& rngMin, double& rngMid, double& rngMax, double& rng); // Calculate chart points for value axis and return range between and - void drawChrtTimeAxis(int8_t& chrtIntv); // Draw time axis of chart, value and lines - void drawChrtValAxis(); // Draw value axis of chart, value and lines - void prntCurrValue(GwApi::BoatValue& currValue); // Add current boat data value to chart - void prntNoValidData(); // print message for no valid data available + void drawChrtTimeAxis(const char chrtDir, const int8_t chrtSz, int8_t& chrtIntv); // Draw time axis of chart, value and lines + void drawChrtValAxis(const char chrtDir, const int8_t chrtSz); // Draw value axis of chart, value and lines + void prntCurrValue(const char chrtDir, GwApi::BoatValue& currValue); // Add current boat data value to chart + void prntNoValidData(const char chrtDir); // print message for no valid data available double getAngleRng(double center, size_t amount); // Calculate range between chart center and edges void prntHorizThreeValueAxisLabel(const GFXfont* font); // print horizontal axis label with only three values: top, mid, and bottom void prntHorizMultiValueAxisLabel(const GFXfont* font); // print horizontal axis label with multiple axis lines @@ -90,17 +90,9 @@ public: // Define default chart range and range step for each boat data type static std::map dfltChrtDta; - Chart(RingBuffer& dataBuf, char chrtDir, int8_t chrtSz, double dfltRng, CommonData& common, bool useSimuData); // Chart object of data chart + // Chart(RingBuffer& dataBuf, char chrtDir, int8_t chrtSz, double dfltRng, CommonData& common, bool useSimuData); // Chart object of data chart + Chart(RingBuffer& dataBuf, double dfltRng, CommonData& common, bool useSimuData); // Chart object of data chart ~Chart(); - void showChrt(GwApi::BoatValue currValue, int8_t& chrtIntv, bool showCurrValue); // Perform all actions to draw chart + // void showChrt(GwApi::BoatValue currValue, int8_t& chrtIntv, bool showCurrValue); // Perform all actions to draw chart + void showChrt(char chrtDir, int8_t chrtSz, int8_t& chrtIntv, bool showCurrValue, GwApi::BoatValue currValue); // Perform all actions to draw chart }; - -template -std::map Chart::dfltChrtDta = { - { "formatWind", { 60.0 * DEG_TO_RAD, 10.0 * DEG_TO_RAD } }, // default course range 60 degrees - { "formatCourse", { 60.0 * DEG_TO_RAD, 10.0 * DEG_TO_RAD } }, // default course range 60 degrees - //{ "formatKnots", { 7.71, 2.57 } }, // default speed range in m/s - { "formatKnots", { 7.71, 2.56 } }, // default speed range in m/s - { "formatDepth", { 15.0, 5.0 } }, // default depth range in m - { "kelvinToC", { 30.0, 5.0 } } // default temp range in °C/K -}; \ No newline at end of file diff --git a/lib/obp60task/PageOneValue.cpp b/lib/obp60task/PageOneValue.cpp index 57175f1..59a02bf 100644 --- a/lib/obp60task/PageOneValue.cpp +++ b/lib/obp60task/PageOneValue.cpp @@ -2,8 +2,8 @@ #include "Pagedata.h" #include "OBP60Extensions.h" -#include "OBPDataOperations.h" #include "BoatDataCalibration.h" +#include "OBPDataOperations.h" #include "OBPcharts.h" class PageOneValue : public Page { @@ -18,7 +18,7 @@ private: int8_t dataIntv = 1; // Update interval for wind history chart: // (1)|(2)|(3)|(4)|(8) x 240 seconds for 4, 8, 12, 16, 32 min. history chart - //String lengthformat; + // String lengthformat; bool useSimuData; bool holdValues; String flashLED; @@ -31,7 +31,7 @@ private: // Data buffer pointer (owned by HstryBuffers) RingBuffer* dataHstryBuf = nullptr; - std::unique_ptr> dataFlChart, dataHfChart; // Chart object, full and half size + std::unique_ptr dataChart; // Chart object, full and half size void showData(GwApi::BoatValue* bValue1, char size) { @@ -124,7 +124,7 @@ public: height = getdisplay().height(); // Screen height // Get config data - //lengthformat = commonData->config->getString(commonData->config->lengthFormat); + // lengthformat = commonData->config->getString(commonData->config->lengthFormat); useSimuData = commonData->config->getBool(commonData->config->useSimuData); holdValues = commonData->config->getBool(commonData->config->holdvalues); flashLED = commonData->config->getString(commonData->config->flashLED); @@ -136,51 +136,57 @@ public: { Page::setupKeys(); +#if defined BOARD_OBP60S3 + constexpr int ZOOM_IDX = 4; +#elif defined BOARD_OBP40S3 + constexpr int ZOOM_IDX = 1; +#endif + if (dataHstryBuf) { // show "Mode" key only if chart supported boat data type is available commonData->keydata[0].label = "MODE"; + commonData->keydata[ZOOM_IDX].label = "ZOOM"; } else { commonData->keydata[0].label = ""; + commonData->keydata[ZOOM_IDX].label = ""; } -#if defined BOARD_OBP60S3 - commonData->keydata[4].label = "ZOOM"; -#elif defined BOARD_OBP40S3 - commonData->keydata[1].label = "ZOOM"; -#endif } // Key functions virtual int handleKey(int key) { - // Set page mode value | full chart | value/half chart - if (key == 1) { - if (pageMode == 'V') { - pageMode = 'C'; - } else if (pageMode == 'C') { - pageMode = 'B'; - } else { - pageMode = 'V'; - } - return 0; // Commit the key - } + if (dataHstryBuf) { // if boat data type supports charts - // Set interval for history chart update time (interval) -#if defined BOARD_OBP60S3 - if (key == 5) { -#elif defined BOARD_OBP40S3 - if (key == 2) { -#endif - if (dataIntv == 1) { - dataIntv = 2; - } else if (dataIntv == 2) { - dataIntv = 3; - } else if (dataIntv == 3) { - dataIntv = 4; - } else if (dataIntv == 4) { - dataIntv = 8; - } else { - dataIntv = 1; + // Set page mode value | full chart | value/half chart + if (key == 1) { + if (pageMode == 'V') { + pageMode = 'C'; + } else if (pageMode == 'C') { + pageMode = 'B'; + } else { + pageMode = 'V'; + } + return 0; // Commit the key + } + + // Set time frame to show for history chart +#if defined BOARD_OBP60S3 + if (key == 5) { +#elif defined BOARD_OBP40S3 + if (key == 2) { +#endif + if (dataIntv == 1) { + dataIntv = 2; + } else if (dataIntv == 2) { + dataIntv = 3; + } else if (dataIntv == 3) { + dataIntv = 4; + } else if (dataIntv == 4) { + dataIntv = 8; + } else { + dataIntv = 1; + } + return 0; // Commit the key } - return 0; // Commit the key } // Keylock function @@ -201,7 +207,7 @@ public: } #endif // buffer initialization will fail, if page is default page, because is not executed at system start for default page - if (!dataFlChart) { // Create chart objects if they don't exist + if (!dataChart) { // Create chart objects if they don't exist GwApi::BoatValue* bValue1 = pageData.values[0]; // Page boat data element String bValName1 = bValue1->getName(); // Value name String bValFormat = bValue1->getFormat(); // Value format @@ -209,8 +215,8 @@ public: dataHstryBuf = pageData.hstryBuffers->getBuffer(bValName1); if (dataHstryBuf) { - dataFlChart.reset(new Chart(*dataHstryBuf, 'H', 0, Chart::dfltChrtDta[bValFormat].range, *commonData, useSimuData)); - dataHfChart.reset(new Chart(*dataHstryBuf, 'H', 2, Chart::dfltChrtDta[bValFormat].range, *commonData, useSimuData)); + dataChart.reset(new Chart(*dataHstryBuf, Chart::dfltChrtDta[bValFormat].range, *commonData, useSimuData)); + //dataHfChart.reset(new Chart(*dataHstryBuf, 'H', 2, Chart::dfltChrtDta[bValFormat].range, *commonData, useSimuData)); LOG_DEBUG(GwLog::DEBUG, "PageOneValue: Created chart objects for %s", bValName1); } else { LOG_DEBUG(GwLog::DEBUG, "PageOneValue: No chart objects available for %s", bValName1); @@ -249,14 +255,14 @@ public: showData(bValue1, 'F'); } else if (pageMode == 'C') { // show only data chart - if (dataFlChart) { - dataFlChart->showChrt(*bValue1, dataIntv, true); + if (dataChart) { + dataChart->showChrt('H', 0, dataIntv, true, *bValue1); } } else if (pageMode == 'B') { // show data value and chart showData(bValue1, 'H'); - if (dataHfChart) { - dataHfChart->showChrt(*bValue1, dataIntv, false); + if (dataChart) { + dataChart->showChrt('H', 2, dataIntv, false, *bValue1); } } diff --git a/lib/obp60task/PageWindPlot.cpp b/lib/obp60task/PageWindPlot.cpp index 49d11d3..d90bab9 100644 --- a/lib/obp60task/PageWindPlot.cpp +++ b/lib/obp60task/PageWindPlot.cpp @@ -11,6 +11,15 @@ class PageWindPlot : public Page { private: GwLog* logger; + static constexpr char SHOW_WIND_DIR = 'D'; + static constexpr char SHOW_WIND_SPEED = 'S'; + static constexpr char SHOW_BOTH = 'B'; + static constexpr char HORIZONTAL = 'H'; + static constexpr char VERTICAL = 'V'; + static constexpr int8_t FULL_SIZE = 0; + static constexpr int8_t HALF_SIZE_TOP = 1; + static constexpr int8_t HALF_SIZE_BOTTOM = 2; + int width; // Screen width int height; // Screen height @@ -37,16 +46,12 @@ private: RingBuffer* awsHstry = nullptr; // Chart objects - std::unique_ptr> twdFlChart, awdFlChart; // Chart object for wind direction, full size - std::unique_ptr> twsFlChart, awsFlChart; // Chart object for wind speed, full size - std::unique_ptr> twdHfChart, awdHfChart; // Chart object for wind direction, half size - std::unique_ptr> twsHfChart, awsHfChart; // Chart object for wind speed, half size + std::unique_ptr twdChart, awdChart; // Chart object for wind direction, full size + std::unique_ptr twsChart, awsChart; // Chart object for wind speed, full size // Active charts and values - Chart* wdFlChart = nullptr; - Chart* wsFlChart = nullptr; - Chart* wdHfChart = nullptr; - Chart* wsHfChart = nullptr; + Chart* wdChart = nullptr; + Chart* wsChart = nullptr; GwApi::BoatValue* wdBVal = nullptr; GwApi::BoatValue* wsBVal = nullptr; @@ -86,12 +91,12 @@ public: { // Set chart mode TWD | TWS if (key == 1) { - if (chrtMode == 'D') { - chrtMode = 'S'; - } else if (chrtMode == 'S') { - chrtMode = 'B'; + if (chrtMode == SHOW_WIND_DIR) { + chrtMode = SHOW_WIND_SPEED; + } else if (chrtMode == SHOW_WIND_SPEED) { + chrtMode = SHOW_BOTH; } else { - chrtMode = 'D'; + chrtMode = SHOW_WIND_DIR; } return 0; // Commit the key } @@ -150,39 +155,36 @@ public: oldShowTruW = !showTruW; // Force chart update in displayPage #endif - // buffer initialization cannot be performed here, because is not executed at system start for default page - /* if (!twdFlChart) { // Create true wind charts if they don't exist + // With chart object initialization being performed here, PageWindPlot won't properly work as default page, + // because is not executed at system start for default page + if (!twdChart) { // Create true wind charts if they don't exist twdHstry = pageData.hstryBuffers->getBuffer("TWD"); twsHstry = pageData.hstryBuffers->getBuffer("TWS"); if (twdHstry) { - twdFlChart.reset(new Chart(*twdHstry, 'V', 0, dfltRngWd, *commonData, useSimuData)); - twdHfChart.reset(new Chart(*twdHstry, 'V', 1, dfltRngWd, *commonData, useSimuData)); + twdChart.reset(new Chart(*twdHstry, Chart::dfltChrtDta["formatCourse"].range, *commonData, useSimuData)); } if (twsHstry) { - twsFlChart.reset(new Chart(*twsHstry, 'H', 0, dfltRngWs, *commonData, useSimuData)); - twsHfChart.reset(new Chart(*twsHstry, 'V', 2, dfltRngWs, *commonData, useSimuData)); + twsChart.reset(new Chart(*twsHstry, Chart::dfltChrtDta["formatKnots"].range, *commonData, useSimuData)); } } - if (!awdFlChart) { // Create apparent wind charts if they don't exist + if (!awdChart) { // Create apparent wind charts if they don't exist awdHstry = pageData.hstryBuffers->getBuffer("AWD"); awsHstry = pageData.hstryBuffers->getBuffer("AWS"); if (awdHstry) { - awdFlChart.reset(new Chart(*awdHstry, 'V', 0, dfltRngWd, *commonData, useSimuData)); - awdHfChart.reset(new Chart(*awdHstry, 'V', 1, dfltRngWd, *commonData, useSimuData)); + awdChart.reset(new Chart(*awdHstry, Chart::dfltChrtDta["formatCourse"].range, *commonData, useSimuData)); } if (awsHstry) { - awsFlChart.reset(new Chart(*awsHstry, 'H', 0, dfltRngWs, *commonData, useSimuData)); - awsHfChart.reset(new Chart(*awsHstry, 'V', 2, dfltRngWs, *commonData, useSimuData)); + awsChart.reset(new Chart(*awsHstry, Chart::dfltChrtDta["formatKnots"].range, *commonData, useSimuData)); } if (twdHstry && twsHstry && awdHstry && awsHstry) { LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: Created wind charts"); } else { LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: Some/all chart objects for wind data missing"); } - } */ + } } int displayPage(PageData& pageData) @@ -190,54 +192,46 @@ public: LOG_DEBUG(GwLog::LOG, "Display PageWindPlot"); ulong pageTime = millis(); - if (!twdFlChart) { // Create true wind charts if they don't exist - twdHstry = pageData.hstryBuffers->getBuffer("TWD"); - twsHstry = pageData.hstryBuffers->getBuffer("TWS"); + /* if (!twdChart) { // Create true wind charts if they don't exist + twdHstry = pageData.hstryBuffers->getBuffer("TWD"); + twsHstry = pageData.hstryBuffers->getBuffer("TWS"); - if (twdHstry) { - twdFlChart.reset(new Chart(*twdHstry, 'V', 0, Chart::dfltChrtDta["formatCourse"].range, *commonData, useSimuData)); - twdHfChart.reset(new Chart(*twdHstry, 'V', 1, Chart::dfltChrtDta["formatCourse"].range, *commonData, useSimuData)); - } - if (twsHstry) { - twsFlChart.reset(new Chart(*twsHstry, 'H', 0, Chart::dfltChrtDta["formatKnots"].range, *commonData, useSimuData)); - twsHfChart.reset(new Chart(*twsHstry, 'V', 2, Chart::dfltChrtDta["formatKnots"].range, *commonData, useSimuData)); - } - } + if (twdHstry) { + twdChart.reset(new Chart(*twdHstry, Chart::dfltChrtDta["formatCourse"].range, *commonData, useSimuData)); + } + if (twsHstry) { + twsChart.reset(new Chart(*twsHstry, Chart::dfltChrtDta["formatKnots"].range, *commonData, useSimuData)); + } + } - if (!awdFlChart) { // Create apparent wind charts if they don't exist - awdHstry = pageData.hstryBuffers->getBuffer("AWD"); - awsHstry = pageData.hstryBuffers->getBuffer("AWS"); + if (!awdChart) { // Create apparent wind charts if they don't exist + awdHstry = pageData.hstryBuffers->getBuffer("AWD"); + awsHstry = pageData.hstryBuffers->getBuffer("AWS"); - if (awdHstry) { - awdFlChart.reset(new Chart(*awdHstry, 'V', 0, Chart::dfltChrtDta["formatCourse"].range, *commonData, useSimuData)); - awdHfChart.reset(new Chart(*awdHstry, 'V', 1, Chart::dfltChrtDta["formatCourse"].range, *commonData, useSimuData)); - } - if (awsHstry) { - awsFlChart.reset(new Chart(*awsHstry, 'H', 0, Chart::dfltChrtDta["formatKnots"].range, *commonData, useSimuData)); - awsHfChart.reset(new Chart(*awsHstry, 'V', 2, Chart::dfltChrtDta["formatKnots"].range, *commonData, useSimuData)); - } - if (twdHstry && twsHstry && awdHstry && awsHstry) { - LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: Created wind charts"); - } else { - LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: Some/all chart objects for wind data missing"); - } - } + if (awdHstry) { + awdChart.reset(new Chart(*awdHstry, Chart::dfltChrtDta["formatCourse"].range, *commonData, useSimuData)); + } + if (awsHstry) { + awsChart.reset(new Chart(*awsHstry, Chart::dfltChrtDta["formatKnots"].range, *commonData, useSimuData)); + } + if (twdHstry && twsHstry && awdHstry && awsHstry) { + LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: Created wind charts"); + } else { + LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: Some/all chart objects for wind data missing"); + } + } */ if (showTruW != oldShowTruW) { // Switch active charts based on showTruW if (showTruW) { - wdFlChart = twdFlChart.get(); - wsFlChart = twsFlChart.get(); - wdHfChart = twdHfChart.get(); - wsHfChart = twsHfChart.get(); + wdChart = twdChart.get(); + wsChart = twsChart.get(); wdBVal = pageData.values[0]; wsBVal = pageData.values[1]; } else { - wdFlChart = awdFlChart.get(); - wsFlChart = awsFlChart.get(); - wdHfChart = awdHfChart.get(); - wsHfChart = awsHfChart.get(); + wdChart = awdChart.get(); + wsChart = awsChart.get(); wdBVal = pageData.values[2]; wsBVal = pageData.values[3]; } @@ -253,22 +247,22 @@ public: getdisplay().setPartialWindow(0, 0, width, height); // Set partial update getdisplay().setTextColor(commonData->fgcolor); - if (chrtMode == 'D') { - if (wdFlChart) { - wdFlChart->showChrt(*wdBVal, dataIntv, true); + if (chrtMode == SHOW_WIND_DIR) { + if (wdChart) { + wdChart->showChrt(VERTICAL, FULL_SIZE, dataIntv, true, *wdBVal); } - } else if (chrtMode == 'S') { - if (wsFlChart) { - wsFlChart->showChrt(*wsBVal, dataIntv, true); + } else if (chrtMode == SHOW_WIND_SPEED) { + if (wsChart) { + wsChart->showChrt(HORIZONTAL, FULL_SIZE, dataIntv, true, *wsBVal); } - } else if (chrtMode == 'B') { - if (wdHfChart) { - wdHfChart->showChrt(*wdBVal, dataIntv, true); + } else if (chrtMode == SHOW_BOTH) { + if (wdChart) { + wdChart->showChrt(VERTICAL, HALF_SIZE_TOP, dataIntv, true, *wdBVal); } - if (wsHfChart) { - wsHfChart->showChrt(*wsBVal, dataIntv, true); + if (wsChart) { + wsChart->showChrt(VERTICAL, HALF_SIZE_BOTTOM, dataIntv, true, *wsBVal); } }