diff --git a/lib/obp60task/OBPcharts.cpp b/lib/obp60task/OBPcharts.cpp index 17caf75..b78bc6e 100644 --- a/lib/obp60task/OBPcharts.cpp +++ b/lib/obp60task/OBPcharts.cpp @@ -5,7 +5,7 @@ // --- Class Chart --------------- template -Chart::Chart(RingBuffer& dataBuf, int8_t 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) : dataBuf(dataBuf) , chrtDir(chrtDir) , chrtSz(chrtSz) @@ -21,41 +21,43 @@ Chart::Chart(RingBuffer& dataBuf, int8_t chrtDir, int8_t chrtSz, double df dWidth = getdisplay().width(); dHeight = getdisplay().height(); - if (chrtDir == 0) { + if (chrtDir == 'H') { // horizontal chart timeline direction timAxis = dWidth; switch (chrtSz) { case 0: valAxis = dHeight - top - bottom; - cStart = { 0, top }; + cStart = { 0, top - 1 }; break; case 1: valAxis = (dHeight - top - bottom) / 2 - hGap; - cStart = { 0, top }; + cStart = { 0, top - 1 }; break; case 2: valAxis = (dHeight - top - bottom) / 2 - hGap; - cStart = { 0, top + (valAxis + hGap) + hGap }; + cStart = { 0, top + (valAxis + hGap) + hGap - 1 }; break; default: LOG_DEBUG(GwLog::ERROR, "displayChart: wrong init parameter"); return; } - } else if (chrtDir == 1) { + } else if (chrtDir == 'V') { // vertical chart timeline direction timAxis = dHeight - top - bottom; switch (chrtSz) { case 0: valAxis = dWidth; - cStart = { 0, top }; + cStart = { 0, top - 1 }; break; case 1: - valAxis = dWidth / 2 - vGap - 1; - cStart = { 0, top }; + // valAxis = dWidth / 2 - vGap - 1; + valAxis = dWidth / 2 - vGap; + cStart = { 0, top - 1 }; break; case 2: - valAxis = dWidth / 2 - vGap - 1; - cStart = { dWidth / 2 + vGap, top }; + // valAxis = dWidth / 2 - vGap - 1; + valAxis = dWidth / 2 - vGap; + cStart = { dWidth / 2 + vGap - 1, top - 1 }; break; default: LOG_DEBUG(GwLog::ERROR, "displayChart: wrong init parameter"); @@ -71,17 +73,21 @@ Chart::Chart(RingBuffer& dataBuf, int8_t chrtDir, int8_t chrtSz, double df dbMAX_VAL = dataBuf.getMaxVal(); bufSize = dataBuf.getCapacity(); - if (dbFormat == "formatCourse" || dbFormat == "FormatWind" || dbFormat == "FormatRot") { + if (dbFormat == "formatCourse" || dbFormat == "formatWind" || dbFormat == "formatRot") { - if (dbFormat == "FormatRot") { - chrtDataFmt = 2; // Chart is showing data of rotational format + if (dbFormat == "formatRot") { + chrtDataFmt = 'R'; // Chart is showing data of rotational format } else { - chrtDataFmt = 1; // Chart is showing data of course / wind format + chrtDataFmt = 'W'; // Chart is showing data of course / wind format } rngStep = M_TWOPI / 360.0 * 10.0; // +/-10 degrees on each end of chrtMid; we are calculating with SI values } else { - chrtDataFmt = 0; // Chart is showing any other data format than + if (dbFormat == "formatDepth") { + chrtDataFmt = 'D'; // Chart ist showing data of format + } else { + chrtDataFmt = 'S'; // Chart is showing any other data format than + } rngStep = 5.0; // +/- 10 for all other values (eg. m/s, m, K, mBar) } @@ -178,16 +184,19 @@ void Chart::drawChrt(int8_t chrtIntv, GwApi::BoatValue& currValue) chrtPrevVal = dbMAX_VAL; } else { - if (chrtDir == 0) { // horizontal chart + if (chrtDir == 'H') { // horizontal chart x = cStart.x + i; // Position in chart area - if (chrtDataFmt == 0) { + if (chrtDataFmt == 'S') { + // y = cStart.y + static_cast(((chrtVal - chrtMin) * chrtScl) + 0.5); // calculate chart point and round + y = cStart.y + valAxis - static_cast(((chrtVal - chrtMin) * chrtScl) + 0.5); // calculate chart point and round + } else if (chrtDataFmt == 'D') { y = cStart.y + static_cast(((chrtVal - chrtMin) * chrtScl) + 0.5); // calculate chart point and round } else { // degree type value y = cStart.y + static_cast((WindUtils::to2PI(chrtVal - chrtMin) * chrtScl) + 0.5); // calculate chart point and round } } else { // vertical chart y = cStart.y + timAxis - i; // Position in chart area - if (chrtDataFmt == 0) { + if (chrtDataFmt == 'S' || chrtDataFmt == 'D') { x = cStart.x + static_cast(((chrtVal - chrtMin) * chrtScl) + 0.5); // calculate chart point and round } else { // degree type value x = cStart.x + static_cast((WindUtils::to2PI(chrtVal - chrtMin) * chrtScl) + 0.5); // calculate chart point and round @@ -202,7 +211,7 @@ void Chart::drawChrt(int8_t chrtIntv, GwApi::BoatValue& currValue) prevX = x; prevY = y; - } else if (chrtDataFmt != 0) { + } else if (chrtDataFmt == 'W' || chrtDataFmt == 'R') { // cross borders check for degree values; shift values to [-PI..0..PI]; when crossing borders, range is 2x PI degrees double normCurr = WindUtils::to2PI(chrtVal - chrtMin); double normPrev = WindUtils::to2PI(chrtPrevVal - chrtMin); @@ -212,7 +221,7 @@ void Chart::drawChrt(int8_t chrtIntv, GwApi::BoatValue& currValue) if (crossedBorders) { // If current value crosses chart borders compared to previous value, split line // LOG_DEBUG(GwLog::DEBUG, "PageWindPlot Chart: crossedBorders: %d, chrtVal: %.2f, chrtPrevVal: %.2f", crossedBorders, chrtVal, chrtPrevVal); bool wrappingFromHighToLow = normCurr < normPrev; // Determine which edge we're crossing - if (chrtDir == 0) { + if (chrtDir == 'H') { int ySplit = wrappingFromHighToLow ? (cStart.y + valAxis) : cStart.y; getdisplay().drawLine(prevX, prevY, x, ySplit, fgColor); if (x != prevX) { // line with some horizontal trend @@ -231,12 +240,18 @@ void Chart::drawChrt(int8_t chrtIntv, GwApi::BoatValue& currValue) } // Draw line with 2 pixels width + make sure vertical lines are drawn correctly - if (chrtDir == 0 || x == prevX) { // horizontal chart & vertical line -// if (x == prevX) { // vertical line + if (chrtDir == 'H' || x == prevX) { // horizontal chart & vertical line + if (chrtDataFmt == 'D') { + getdisplay().drawLine(x, y, x, cStart.y + valAxis, fgColor); + getdisplay().drawLine(x - 1, y, x - 1, cStart.y + valAxis, fgColor); + } getdisplay().drawLine(prevX, prevY, x, y, fgColor); getdisplay().drawLine(prevX - 1, prevY, x - 1, y, fgColor); - } else if (chrtDir == 1 || x != prevX) { // vertical chart & line with some horizontal trend -> normal state -// } else { // line with some horizontal trend -> normal state + } else if (chrtDir == 'V' || x != prevX) { // vertical chart & line with some horizontal trend -> normal state + if (chrtDataFmt == 'D') { + getdisplay().drawLine(x, y, cStart.x + valAxis, y, fgColor); + getdisplay().drawLine(x, y - 1, cStart.x + valAxis, y - 1, fgColor); + } getdisplay().drawLine(prevX, prevY, x, y, fgColor); getdisplay().drawLine(prevX, prevY - 1, x, y - 1, fgColor); } @@ -249,23 +264,22 @@ void Chart::drawChrt(int8_t chrtIntv, GwApi::BoatValue& currValue) if (i >= timAxis - 1) { oldChrtIntv = 0; // force reset of buffer start and number of values to show in next display loop - if (chrtDataFmt == 1) { // degree of course or wind + if (chrtDataFmt == 'W') { // degree of course or wind recalcRngCntr = true; LOG_DEBUG(GwLog::DEBUG, "PageWindPlot FreeTop: timAxis: %d, i: %d, bufStart: %d, numBufVals: %d, recalcRngCntr: %d", timAxis, i, bufStart, numBufVals, recalcRngCntr); } break; } } - } else { // No valid data available getdisplay().setFont(&Ubuntu_Bold10pt8b); int pX, pY; - if (chrtDir == 0) { // horizontal chart + if (chrtDir == 'H') { pX = cStart.x + (timAxis / 2); pY = cStart.y + (valAxis / 2) - 10; - } else { // vertical chart + } else { pX = cStart.x + (valAxis / 2); pY = cStart.y + (timAxis / 2) - 10; } @@ -316,7 +330,7 @@ double Chart::getRng(double center, size_t amount) template void Chart::calcChrtBorders(double& rngMid, double& rngMin, double& rngMax, double& rng) { - if (chrtDataFmt == 0) { + if (chrtDataFmt == 'S' || chrtDataFmt == 'D') { // Chart data is of any type but 'degree' double oldRngMin = rngMin; @@ -349,7 +363,7 @@ void Chart::calcChrtBorders(double& rngMid, double& rngMin, double& rngMax, d currMinVal, currMaxVal, rngMin, rngMid, rngMax, rng, rngStep, oldRngMin, oldRngMax, dfltRng, numBufVals); } else { - if (chrtDataFmt == 1) { + if (chrtDataFmt == 'W') { // Chart data is of type 'course' or 'wind' if ((count == 1 && rngMid == 0) || rngMid == dbMAX_VAL) { @@ -378,7 +392,7 @@ void Chart::calcChrtBorders(double& rngMid, double& rngMin, double& rngMax, d rng * RAD_TO_DEG, rngStep * RAD_TO_DEG); } - } else if (chrtDataFmt == 2) { + } else if (chrtDataFmt == 'R') { // Chart data is of type 'rotation'; then we want to have always to be '0' rngMid = 0; } @@ -417,7 +431,7 @@ void Chart::drawChrtTimeAxis(int8_t chrtIntv) getdisplay().setFont(&Ubuntu_Bold8pt8b); getdisplay().setTextColor(fgColor); - if (chrtDir == 0) { // horizontal chart + if (chrtDir == 'H') { // horizontal chart getdisplay().fillRect(0, cStart.y, dWidth, 2, fgColor); timeRng = chrtIntv * 4; // Chart time interval: [1] 4 min., [2] 8 min., [3] 12 min., [4] 16 min., [8] 32 min. @@ -478,7 +492,7 @@ void Chart::drawChrtValAxis() { double slots; int i, intv; - double cVal, cchrtRng, crngMin; + double cVal, cChrtRng, crngMin; char sVal[6]; int sLen; std::unique_ptr tmpBVal; // Temp variable to get formatted and converted data value from OBP60Formatter @@ -486,16 +500,17 @@ void Chart::drawChrtValAxis() tmpBVal->setFormat(dataBuf.getFormat()); tmpBVal->valid = true; - if (chrtDir == 0) { // horizontal chart + if (chrtDir == 'H') { slots = valAxis / 60.0; // number of axis labels tmpBVal->value = chrtRng; - cchrtRng = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted) - intv = static_cast(round(cchrtRng / slots)); + cChrtRng = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted) + intv = static_cast(round(cChrtRng / slots)); i = intv; if (chrtSz == 0) { // full size chart -> print multiple value lines getdisplay().setFont(&Ubuntu_Bold12pt8b); - for (int j = 60; j < valAxis - 30; j += 60) { +// for (int j = 60; j < valAxis - 30; j += 60) { + for (int j = valAxis - 60; j > 30; j -= 60) { getdisplay().drawLine(cStart.x, cStart.y + j, cStart.x + timAxis, cStart.y + j, fgColor); getdisplay().fillRect(cStart.x, cStart.y + j - 11, 42, 21, bgColor); // Clear small area to remove potential chart lines @@ -542,7 +557,7 @@ void Chart::drawChrtValAxis() } else { getdisplay().setFont(&Ubuntu_Bold10pt8b); } - getdisplay().fillRect(cStart.x, top, valAxis, 2, fgColor); // top chart line + getdisplay().fillRect(cStart.x, cStart.y, valAxis, 2, fgColor); // top chart line tmpBVal->value = chrtMin; cVal = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted) @@ -560,14 +575,9 @@ void Chart::drawChrtValAxis() snprintf(sVal, sizeof(sVal), "%.0f", round(cVal)); drawTextRalign(cStart.x + valAxis - 2, cStart.y - 2, sVal); // Range high end - for (int j = 0; j <= valAxis + 2; j += ((valAxis + 2) / 2)) { + for (int j = 0; j <= valAxis; j += (valAxis / 2)) { getdisplay().drawLine(cStart.x + j, cStart.y, cStart.x + j, cStart.y + timAxis, fgColor); } - - // if (chrtSz == 0) { - // getdisplay().setFont(&Ubuntu_Bold12pt8b); - // drawTextCenter(cStart.x + (valAxis / 4) + 15, cStart.y - 11, dbName); // buffer data name - // } } } @@ -575,8 +585,8 @@ void Chart::drawChrtValAxis() template void Chart::prntCurrValue(GwApi::BoatValue& currValue) { - const int xPosVal = (chrtDir == 0) ? cStart.x + (timAxis / 2) - 56 : cStart.x + 32; - const int yPosVal = (chrtDir == 0) ? cStart.y + valAxis - 7 : cStart.y + timAxis - 7; + const int xPosVal = (chrtDir == 'H') ? cStart.x + (timAxis / 2) - 56 : cStart.x + 32; + const int yPosVal = (chrtDir == 'H') ? cStart.y + valAxis - 5 : cStart.y + timAxis - 5; FormattedData frmtDbData = formatValue(&currValue, *commonData); double testdbValue = frmtDbData.value; @@ -585,7 +595,7 @@ void Chart::prntCurrValue(GwApi::BoatValue& currValue) // LOG_DEBUG(GwLog::DEBUG, "Chart CurrValue: dbValue: %.2f, sdbValue: %s, fmrtDbValue: %.2f, dbFormat: %s, dbUnit: %s, Valid: %d, Name: %s, Address: %p", currValue.value, sdbValue, // testdbValue, currValue.getFormat(), dbUnit, currValue.valid, currValue.getName(), currValue); - getdisplay().fillRect(xPosVal - 1, yPosVal - 34, 125, 41, bgColor); // Clear area for TWS value + getdisplay().fillRect(xPosVal - 1, yPosVal - 34, 125, 40, bgColor); // Clear area for TWS value getdisplay().drawRect(xPosVal, yPosVal - 33, 123, 39, fgColor); // Draw box for TWS value getdisplay().setFont(&DSEG7Classic_BoldItalic16pt7b); getdisplay().setCursor(xPosVal + 1, yPosVal); diff --git a/lib/obp60task/OBPcharts.h b/lib/obp60task/OBPcharts.h index db298a5..f160dd4 100644 --- a/lib/obp60task/OBPcharts.h +++ b/lib/obp60task/OBPcharts.h @@ -16,19 +16,18 @@ protected: GwLog *logger; RingBuffer &dataBuf; // Buffer to display - int8_t chrtDir; // Chart timeline direction: [0] = horizontal, [1] = vertical + 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 bool useSimuData; // flag to indicate if simulation data is active - int top = 48; // display top header lines - int bottom = 22; // display bottom lines + // int top = 48; // display top header lines + int top = 44; // chart gap at top of display (25 lines for standard gap + 19 lines for axis labels) + int bottom = 25; // chart gap at bottom of display to keep space for status line int hGap = 11; // gap between 2 horizontal charts; actual gap is 2x int vGap = 20; // gap between 2 vertical charts; actual gap is 2x - int xOffset = 33; // offset for horizontal axis (time/value), because of space for left vertical axis labeling - int yOffset = 10; // offset for vertical axis (time/value), because of space for top horizontal axis labeling int dWidth; // Display width int dHeight; // Display height int timAxis, valAxis; // size of time and value chart axis @@ -41,7 +40,7 @@ protected: bool recalcRngCntr = false; // Flag for re-calculation of mid value of chart for wind data types String dbName, dbFormat; // Name and format of data buffer - int chrtDataFmt; // Data format of chart: [0] size values; [1] degree of course or wind; [2] rotational degrees + char chrtDataFmt; // Data format of chart: 'S' = size values; 'D' = depth value, 'W' = degree of course or wind; 'R' rotational degrees double dbMIN_VAL; // Lowest possible value of buffer of type double dbMAX_VAL; // Highest possible value of buffer of type ; indicates invalid value in buffer size_t bufSize; // History buffer size: 1.920 values for 32 min. history chart @@ -63,7 +62,7 @@ protected: void prntCurrValue(GwApi::BoatValue& currValue); // Add current boat data value to chart public: - Chart(RingBuffer& dataBuf, int8_t 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(); void showChrt(int8_t chrtIntv, GwApi::BoatValue currValue); // Perform all actions to draw chart diff --git a/lib/obp60task/PageWindPlot.cpp b/lib/obp60task/PageWindPlot.cpp index a30c0c8..1ce55b9 100644 --- a/lib/obp60task/PageWindPlot.cpp +++ b/lib/obp60task/PageWindPlot.cpp @@ -167,12 +167,13 @@ public: LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: Creating true wind charts"); auto* twdHstry = pageData.hstryManager->getBuffer("TWD"); auto* twsHstry = pageData.hstryManager->getBuffer("TWS"); - twdFlChart = std::unique_ptr>(new Chart(*twdHstry, 1, 0, dfltRngWd, *commonData, useSimuData)); - twsFlChart = std::unique_ptr>(new Chart(*twsHstry, 0, 0, dfltRngWs, *commonData, useSimuData)); - twdHfChart = std::unique_ptr>(new Chart(*twdHstry, 1, 1, dfltRngWd, *commonData, useSimuData)); - twsHfChart = std::unique_ptr>(new Chart(*twsHstry, 1, 2, dfltRngWs, *commonData, useSimuData)); - // twdHfChart = std::unique_ptr>(new Chart(*twdHstry, 0, 1, dfltRngWd, *commonData, useSimuData)); - // twsHfChart = std::unique_ptr>(new Chart(*twsHstry, 0, 2, dfltRngWs, *commonData, useSimuData)); + + twdFlChart = std::unique_ptr>(new Chart(*twdHstry, 'V', 0, dfltRngWd, *commonData, useSimuData)); + twsFlChart = std::unique_ptr>(new Chart(*twsHstry, 'H', 0, dfltRngWs, *commonData, useSimuData)); + twdHfChart = std::unique_ptr>(new Chart(*twdHstry, 'V', 1, dfltRngWd, *commonData, useSimuData)); + twsHfChart = std::unique_ptr>(new Chart(*twsHstry, 'V', 2, dfltRngWs, *commonData, useSimuData)); + // twdHfChart = std::unique_ptr>(new Chart(*twdHstry, 'H', 1, dfltRngWd, *commonData, useSimuData)); + // twsHfChart = std::unique_ptr>(new Chart(*twsHstry, 'H', 2, dfltRngWs, *commonData, useSimuData)); // LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: twdHstry: %p, twsHstry: %p", (void*)twdHstry, (void*)twsHstry); } @@ -181,10 +182,10 @@ public: auto* awdHstry = pageData.hstryManager->getBuffer("AWD"); auto* awsHstry = pageData.hstryManager->getBuffer("AWS"); - awdFlChart = std::unique_ptr>(new Chart(*awdHstry, 1, 0, dfltRngWd, *commonData, useSimuData)); - awsFlChart = std::unique_ptr>(new Chart(*awsHstry, 0, 0, dfltRngWs, *commonData, useSimuData)); - awdHfChart = std::unique_ptr>(new Chart(*awdHstry, 1, 1, dfltRngWd, *commonData, useSimuData)); - awsHfChart = std::unique_ptr>(new Chart(*awsHstry, 1, 2, dfltRngWs, *commonData, useSimuData)); + awdFlChart = std::unique_ptr>(new Chart(*awdHstry, 'V', 0, dfltRngWd, *commonData, useSimuData)); + awsFlChart = std::unique_ptr>(new Chart(*awsHstry, 'H', 0, dfltRngWs, *commonData, useSimuData)); + awdHfChart = std::unique_ptr>(new Chart(*awdHstry, 'V', 1, dfltRngWd, *commonData, useSimuData)); + awsHfChart = std::unique_ptr>(new Chart(*awsHstry, 'V', 2, dfltRngWs, *commonData, useSimuData)); } // Switch active charts based on showTruW