mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-15 15:03:07 +01:00
Code cleanup: moved buffer + wind calc to OBPDataOperations; <BoatValueList> header to obp60task.h; tws 3 decimals
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
#if defined BOARD_OBP60S3 || defined BOARD_OBP40S3
|
||||
|
||||
#include "BoatDataCalibration.h"
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60Extensions.h"
|
||||
#include "OBPRingBuffer.h"
|
||||
#include "Pagedata.h"
|
||||
#include "OBPDataOperations.h"
|
||||
#include "BoatDataCalibration.h"
|
||||
#include <vector>
|
||||
|
||||
static const double radToDeg = 180.0 / M_PI; // Conversion factor from radians to degrees
|
||||
@@ -20,7 +21,7 @@ int getCntr(const RingBuffer<int16_t>& windDirHstry, size_t amount)
|
||||
if (amount > count)
|
||||
amount = count;
|
||||
|
||||
int16_t midWndDir, minWndDir, maxWndDir = 0;
|
||||
uint16_t midWndDir, minWndDir, maxWndDir = 0;
|
||||
int wndCenter = 0;
|
||||
|
||||
midWndDir = windDirHstry.getMid(amount);
|
||||
@@ -78,6 +79,8 @@ class PageWindPlot : public Page {
|
||||
bool keylock = false; // Keylock
|
||||
char chrtMode = 'D'; // Chart mode: 'D' for TWD, 'S' for TWS, 'B' for both
|
||||
bool showTruW = true; // Show true wind or apparant wind in chart area
|
||||
bool oldShowTruW = false; // remember recent user selection of wind data type
|
||||
|
||||
int dataIntv = 1; // Update interval for wind history chart:
|
||||
// (1)|(2)|(3)|(4) seconds for approx. 4, 8, 12, 16 min. history chart
|
||||
bool useSimuData;
|
||||
@@ -169,34 +172,26 @@ public:
|
||||
}
|
||||
commonData->logger->logDebug(GwLog::LOG,"New PageWindPlot: wind source=%s", wndSrc);
|
||||
#endif
|
||||
oldShowTruW = !showTruW; // makes wind source being initialized at initial page call
|
||||
}
|
||||
|
||||
|
||||
|
||||
int displayPage(PageData& pageData)
|
||||
{
|
||||
GwConfigHandler* config = commonData->config;
|
||||
GwLog* logger = commonData->logger;
|
||||
|
||||
static RingBuffer<int16_t>* wdHstry; // Wind direction data buffer
|
||||
static RingBuffer<int16_t>* wsHstry; // Wind speed data buffer
|
||||
static RingBuffer<uint16_t>* wsHstry; // Wind speed data buffer
|
||||
static String wdName, wdFormat; // Wind direction name and format
|
||||
static String wsName, wsFormat; // Wind speed name and format
|
||||
static int updFreq; // Update frequency for wind direction
|
||||
static int16_t wdLowest, wdHighest; // Wind direction range
|
||||
float wsValue; // Wind speed value in chart area
|
||||
String wsUnit; // Wind speed unit in chart area
|
||||
static GwApi::BoatValue* wsBVal = new GwApi::BoatValue("TWS"); // temp BoatValue for wind speed unit identification; required by OBP60Formater
|
||||
|
||||
// current boat data values; TWD/AWD only for validation test, TWS/AWS for display of current value
|
||||
const int numBoatData = 4;
|
||||
// current boat data values; TWD/AWD only for validation test
|
||||
const int numBoatData = 2;
|
||||
GwApi::BoatValue* bvalue;
|
||||
String BDataName[numBoatData];
|
||||
double BDataValue[numBoatData];
|
||||
bool BDataValid[numBoatData];
|
||||
String BDataText[numBoatData];
|
||||
String BDataUnit[numBoatData];
|
||||
String BDataFormat[numBoatData];
|
||||
|
||||
static bool isInitialized = false; // Flag to indicate that page is initialized
|
||||
static bool wndDataValid = false; // Flag to indicate if wind data is valid
|
||||
@@ -217,7 +212,6 @@ public:
|
||||
static size_t lastIdx; // Last index of TWD history buffer
|
||||
static size_t lastAddedIdx = 0; // Last index of TWD history buffer when new data was added
|
||||
static int oldDataIntv; // remember recent user selection of data interval
|
||||
static bool oldShowTruW; // remember recent user selection of wind data type
|
||||
|
||||
static int wndCenter; // chart wind center value position
|
||||
static int wndLeft; // chart wind left value position
|
||||
@@ -234,13 +228,8 @@ public:
|
||||
static int chrtPrevVal; // Last wind value in chart area for check if value crosses 180 degree line
|
||||
|
||||
LOG_DEBUG(GwLog::LOG, "Display PageWindPlot");
|
||||
ulong timer = millis();
|
||||
|
||||
/* // Get config data
|
||||
bool useSimuData = config->getBool(config->useSimuData);
|
||||
// holdValues = config->getBool(config->holdvalues);
|
||||
String flashLED = config->getString(config->flashLED);
|
||||
String backlightMode = config->getString(config->backlight);
|
||||
*/
|
||||
if (!isInitialized) {
|
||||
width = getdisplay().width();
|
||||
height = getdisplay().height();
|
||||
@@ -249,17 +238,8 @@ public:
|
||||
numNoData = 0;
|
||||
bufStart = 0;
|
||||
oldDataIntv = 0;
|
||||
oldShowTruW = false; // we want to initialize wind buffers at 1st time routine runs
|
||||
wdHstry = pageData.boatHstry.twdHstry;
|
||||
bufSize = wdHstry->getCapacity();
|
||||
wsHstry = pageData.boatHstry.twsHstry;
|
||||
bufSize = wsHstry->getCapacity();
|
||||
wdHstry->getMetaData(wdName, wdFormat, updFreq, wdLowest, wdHighest);
|
||||
wsHstry->getMetaData(wsName, wsFormat, updFreq, wdLowest, wdHighest);
|
||||
wsValue = 0;
|
||||
wsBVal->setFormat(wsHstry->getFormat());
|
||||
numAddedBufVals, currIdx, lastIdx = 0;
|
||||
lastAddedIdx = wdHstry->getLastIdx();
|
||||
wndCenter = INT_MIN;
|
||||
midWndDir = 0;
|
||||
diffRng = dfltRng;
|
||||
@@ -271,14 +251,7 @@ public:
|
||||
// read boat data values; TWD only for validation test, TWS for display of current value
|
||||
for (int i = 0; i < numBoatData; i++) {
|
||||
bvalue = pageData.values[i];
|
||||
BDataName[i] = xdrDelete(bvalue->getName());
|
||||
BDataName[i] = BDataName[i].substring(0, 6); // String length limit for value name
|
||||
calibrationData.calibrateInstance(bvalue, logger); // Check if boat data value is to be calibrated
|
||||
BDataValue[i] = bvalue->value; // Value as double in SI unit
|
||||
BDataValid[i] = bvalue->valid;
|
||||
BDataText[i] = formatValue(bvalue, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places
|
||||
BDataUnit[i] = formatValue(bvalue, *commonData).unit;
|
||||
BDataFormat[i] = bvalue->getFormat(); // Unit of value
|
||||
}
|
||||
|
||||
// Optical warning by limit violation (unused)
|
||||
@@ -289,16 +262,17 @@ public:
|
||||
|
||||
if (showTruW != oldShowTruW) {
|
||||
if (showTruW) {
|
||||
wdHstry = pageData.boatHstry.twdHstry;
|
||||
wsHstry = pageData.boatHstry.twsHstry;
|
||||
wdHstry = pageData.boatHstry->hstryBufList.twdHstry;
|
||||
wsHstry = pageData.boatHstry->hstryBufList.twsHstry;
|
||||
} else {
|
||||
wdHstry = pageData.boatHstry.awdHstry;
|
||||
wsHstry = pageData.boatHstry.awsHstry;
|
||||
wdHstry = pageData.boatHstry->hstryBufList.awdHstry;
|
||||
wsHstry = pageData.boatHstry->hstryBufList.awsHstry;
|
||||
}
|
||||
wdHstry->getMetaData(wdName, wdFormat, updFreq, wdLowest, wdHighest);
|
||||
wsHstry->getMetaData(wsName, wsFormat, updFreq, wdLowest, wdHighest);
|
||||
wdHstry->getMetaData(wdName, wdFormat);
|
||||
wsHstry->getMetaData(wsName, wsFormat);
|
||||
bufSize = wdHstry->getCapacity();
|
||||
wsBVal->setFormat(wsHstry->getFormat());
|
||||
lastAddedIdx = wdHstry->getLastIdx();
|
||||
|
||||
oldShowTruW = showTruW;
|
||||
}
|
||||
@@ -321,15 +295,15 @@ public:
|
||||
bufStart = max(0, bufStart - numAddedBufVals);
|
||||
}
|
||||
}
|
||||
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot Dataset: count: %d, xWD: %.0f, xWS: %.1f, xWD_valid? %d, intvBufSize: %d, numWndVals: %d, bufStart: %d, numAddedBufVals: %d, lastIdx: %d, wind source: %s",
|
||||
count, wdHstry->getLast() / 1000.0 * radToDeg, wsHstry->getLast() / 10.0 * 1.94384, BDataValid[0], intvBufSize, numWndVals, bufStart, numAddedBufVals, wdHstry->getLastIdx(),
|
||||
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot Dataset: count: %d, xWD: %.1f, xWS: %.2f, xWD_valid? %d, intvBufSize: %d, numWndVals: %d, bufStart: %d, numAddedBufVals: %d, lastIdx: %d, wind source: %s",
|
||||
count, wdHstry->getLast() / 1000.0 * radToDeg, wsHstry->getLast() / 1000.0 * 1.94384, BDataValid[0], intvBufSize, numWndVals, bufStart, numAddedBufVals, wdHstry->getLastIdx(),
|
||||
showTruW ? "True" : "App");
|
||||
|
||||
// Set wndCenter from 1st real buffer value
|
||||
if (wndCenter == INT_MIN || (wndCenter == 0 && count == 1)) {
|
||||
wndCenter = getCntr(*wdHstry, numWndVals);
|
||||
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot Range Init: count: %d, xWD: %.0f, wndCenter: %d, diffRng: %d, chrtRng: %d, Min: %.0f, Max: %.0f", count, wdHstry->getLast() / 1000.0 * radToDeg,
|
||||
wndCenter, diffRng, chrtRng, wdHstry->getMin(numWndVals) / 1000.0 * radToDeg, wdHstry->getMax(numWndVals) / 1000.0 * radToDeg);
|
||||
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot Range Init: count: %d, xWD: %.1f, wndCenter: %d, diffRng: %d, chrtRng: %d, Min: %.0f, Max: %.0f", count, wdHstry->getLast() / 10000.0 * radToDeg,
|
||||
wndCenter, diffRng, chrtRng, wdHstry->getMin(numWndVals) / 10000.0 * radToDeg, wdHstry->getMax(numWndVals) / 10000.0 * radToDeg);
|
||||
} else {
|
||||
// check and adjust range between left, center, and right chart limit
|
||||
diffRng = getRng(*wdHstry, wndCenter, numWndVals);
|
||||
@@ -365,7 +339,6 @@ public:
|
||||
char sWndLbl[4]; // char buffer for Wind angle label
|
||||
getdisplay().setFont(&Ubuntu_Bold12pt8b);
|
||||
getdisplay().setCursor(xCenter - 88, yOffset - 3);
|
||||
// getdisplay().print("TWD"); // Wind data name
|
||||
getdisplay().print(wdName); // Wind data name
|
||||
snprintf(sWndLbl, 4, "%03d", (wndCenter < 0) ? (wndCenter + 360) : wndCenter);
|
||||
drawTextCenter(xCenter, yOffset - 11, sWndLbl);
|
||||
@@ -473,22 +446,24 @@ public:
|
||||
lastZone = currentZone;
|
||||
|
||||
wsValue = wsHstry->getLast();
|
||||
wsBVal->value = wsValue; // temp variable to retreive data unit from OBP60Formater
|
||||
wsBVal->valid = (static_cast<int16_t>(wsValue) != wsHstry->getMinVal());
|
||||
wsBVal->value = wsValue / 1000.0; // temp variable to retreive data unit from OBP60Formater
|
||||
wsBVal->valid = (static_cast<uint16_t>(wsValue) != wsHstry->getMinVal());
|
||||
String swsValue = formatValue(wsBVal, *commonData).svalue; // value (string)
|
||||
wsUnit = formatValue(wsBVal, *commonData).unit; // Unit of value
|
||||
getdisplay().fillRect(xPosTws - 4, yPosTws - 38, 142, 44, commonData->bgcolor); // Clear area for TWS value
|
||||
getdisplay().setFont(&DSEG7Classic_BoldItalic16pt7b);
|
||||
getdisplay().setCursor(xPosTws, yPosTws);
|
||||
if (!wsBVal->valid) {
|
||||
getdisplay().print(swsValue); // Value
|
||||
/* if (!wsBVal->valid) {
|
||||
getdisplay().print("--.-");
|
||||
} else {
|
||||
wsValue = wsValue / 10.0 * 1.94384; // Wind speed value in knots
|
||||
wsValue = wsValue / 1000.0 * 1.94384; // Wind speed value in knots
|
||||
if (wsValue < 10.0) {
|
||||
getdisplay().printf("!%3.1f", wsValue); // Value, round to 1 decimal
|
||||
} else {
|
||||
getdisplay().printf("%4.1f", wsValue); // Value, round to 1 decimal
|
||||
}
|
||||
}
|
||||
} */
|
||||
getdisplay().setFont(&Ubuntu_Bold12pt8b);
|
||||
getdisplay().setCursor(xPosTws + 82, yPosTws - 14);
|
||||
getdisplay().print(wsName); // Name
|
||||
@@ -523,6 +498,7 @@ public:
|
||||
getdisplay().printf("%3d", chrtLbl); // Wind value label
|
||||
}
|
||||
|
||||
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot time: %ld", millis() - timer);
|
||||
return PAGE_UPDATE;
|
||||
};
|
||||
};
|
||||
@@ -541,7 +517,8 @@ PageDescription registerPageWindPlot(
|
||||
"WindPlot", // Page name
|
||||
createPage, // Action
|
||||
0, // Number of bus values depends on selection in Web configuration
|
||||
{ "TWD", "TWS", "AWD", "AWS" }, // Bus values we need in the page
|
||||
// { "TWD", "TWS", "AWD", "AWS" }, // Bus values we need in the page
|
||||
{ "TWD", "AWD" }, // Bus values we need in the page
|
||||
true // Show display header on/off
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user