1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2026-01-26 08:13:05 +01:00

Revert wind speed chart for horizontal charts; changed chart format parameters to <char>; adjusted chart size to OBP standard

Revert wind speed chart for horizontal charts; changed chart format parameters to <char>; adjusted chart size to OBP standard - commit from PageWindPlot-v2
This commit is contained in:
Ulrich Meine
2025-12-14 20:17:36 +01:00
parent 3ce1e31e64
commit d655674529
3 changed files with 75 additions and 65 deletions

View File

@@ -5,7 +5,7 @@
// --- Class Chart ---------------
template <typename T>
Chart<T>::Chart(RingBuffer<T>& dataBuf, int8_t chrtDir, int8_t chrtSz, double dfltRng, CommonData& common, bool useSimuData)
Chart<T>::Chart(RingBuffer<T>& dataBuf, char chrtDir, int8_t chrtSz, double dfltRng, CommonData& common, bool useSimuData)
: dataBuf(dataBuf)
, chrtDir(chrtDir)
, chrtSz(chrtSz)
@@ -21,41 +21,43 @@ Chart<T>::Chart(RingBuffer<T>& 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<T>::Chart(RingBuffer<T>& 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 <degree> format
if (dbFormat == "formatRot") {
chrtDataFmt = 'R'; // Chart is showing data of rotational <degree> format
} else {
chrtDataFmt = 1; // Chart is showing data of course / wind <degree> format
chrtDataFmt = 'W'; // Chart is showing data of course / wind <degree> 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 <degree>
if (dbFormat == "formatDepth") {
chrtDataFmt = 'D'; // Chart ist showing data of <depth> format
} else {
chrtDataFmt = 'S'; // Chart is showing any other data format than <degree>
}
rngStep = 5.0; // +/- 10 for all other values (eg. m/s, m, K, mBar)
}
@@ -178,16 +184,19 @@ void Chart<T>::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<int>(((chrtVal - chrtMin) * chrtScl) + 0.5); // calculate chart point and round
y = cStart.y + valAxis - static_cast<int>(((chrtVal - chrtMin) * chrtScl) + 0.5); // calculate chart point and round
} else if (chrtDataFmt == 'D') {
y = cStart.y + static_cast<int>(((chrtVal - chrtMin) * chrtScl) + 0.5); // calculate chart point and round
} else { // degree type value
y = cStart.y + static_cast<int>((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<int>(((chrtVal - chrtMin) * chrtScl) + 0.5); // calculate chart point and round
} else { // degree type value
x = cStart.x + static_cast<int>((WindUtils::to2PI(chrtVal - chrtMin) * chrtScl) + 0.5); // calculate chart point and round
@@ -202,7 +211,7 @@ void Chart<T>::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<T>::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<T>::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<T>::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<T>::getRng(double center, size_t amount)
template <typename T>
void Chart<T>::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<T>::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<T>::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 <rndMid> always to be '0'
rngMid = 0;
}
@@ -417,7 +431,7 @@ void Chart<T>::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<T>::drawChrtValAxis()
{
double slots;
int i, intv;
double cVal, cchrtRng, crngMin;
double cVal, cChrtRng, crngMin;
char sVal[6];
int sLen;
std::unique_ptr<GwApi::BoatValue> tmpBVal; // Temp variable to get formatted and converted data value from OBP60Formatter
@@ -486,16 +500,17 @@ void Chart<T>::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<int>(round(cchrtRng / slots));
cChrtRng = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted)
intv = static_cast<int>(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<T>::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<T>::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<T>::drawChrtValAxis()
template <typename T>
void Chart<T>::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<T>::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);