adjust page call to new standard; clean debug code; fix TWS print alignment

This commit is contained in:
Ulrich Meine 2025-07-25 19:50:42 +02:00
parent 938b566bfc
commit 2954a9a58b
3 changed files with 53 additions and 45 deletions

View File

@ -113,7 +113,7 @@ public:
return key; return key;
} }
virtual void displayPage(PageData& pageData) int displayPage(PageData& pageData)
{ {
GwConfigHandler* config = commonData->config; GwConfigHandler* config = commonData->config;
GwLog* logger = commonData->logger; GwLog* logger = commonData->logger;
@ -124,6 +124,16 @@ public:
static int16_t twdLowest, twdHighest; // TWD range static int16_t twdLowest, twdHighest; // TWD range
// static int16_t twdBufMinVal; // lowest possible twd buffer value; used for non-set data // static int16_t twdBufMinVal; // lowest possible twd buffer value; used for non-set data
// current boat data values; TWD only for validation test, TWS for display of current value
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 isInitialized = false; // Flag to indicate that page is initialized
static bool wndDataValid = false; // Flag to indicate if wind data is valid static bool wndDataValid = false; // Flag to indicate if wind data is valid
static int numNoData; // Counter for multiple invalid data values in a row static int numNoData; // Counter for multiple invalid data values in a row
@ -163,7 +173,6 @@ public:
static int chrtPrevVal; // Last wind value in chart area for check if value crosses 180 degree line static int chrtPrevVal; // Last wind value in chart area for check if value crosses 180 degree line
LOG_DEBUG(GwLog::LOG, "Display page WindPlot"); LOG_DEBUG(GwLog::LOG, "Display page WindPlot");
unsigned long WndPlotStart = millis();
// Get config data // Get config data
simulation = config->getBool(config->useSimuData); simulation = config->getBool(config->useSimuData);
@ -194,26 +203,17 @@ public:
isInitialized = true; // Set flag to indicate that page is now initialized isInitialized = true; // Set flag to indicate that page is now initialized
} }
const int numBoatData = 2;
GwApi::BoatValue* bvalue;
String DataName[numBoatData];
double DataValue[numBoatData];
bool DataValid[numBoatData];
String DataText[numBoatData];
String DataUnit[numBoatData];
String DataFormat[numBoatData];
// read boat data values; TWD only for validation test, TWS for display of current value // read boat data values; TWD only for validation test, TWS for display of current value
for (int i = 0; i < numBoatData; i++) { for (int i = 0; i < numBoatData; i++) {
bvalue = pageData.values[i]; bvalue = pageData.values[i];
DataName[i] = xdrDelete(bvalue->getName()); // BDataName[i] = xdrDelete(bvalue->getName());
DataName[i] = DataName[i].substring(0, 6); // String length limit for value name 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 calibrationData.calibrateInstance(bvalue, logger); // Check if boat data value is to be calibrated
DataValue[i] = bvalue->value; // Value as double in SI unit BDataValue[i] = bvalue->value; // Value as double in SI unit
DataValid[i] = bvalue->valid; BDataValid[i] = bvalue->valid;
DataText[i] = formatValue(bvalue, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places BDataText[i] = formatValue(bvalue, *commonData).svalue; // Formatted value as string including unit conversion and switching decimal places
DataUnit[i] = formatValue(bvalue, *commonData).unit; BDataUnit[i] = formatValue(bvalue, *commonData).unit;
DataFormat[i] = bvalue->getFormat(); // Unit of value BDataFormat[i] = bvalue->getFormat(); // Unit of value
} }
// Optical warning by limit violation (unused) // Optical warning by limit violation (unused)
@ -240,8 +240,8 @@ public:
bufStart = max(0, bufStart - numAddedBufVals); bufStart = max(0, bufStart - numAddedBufVals);
} }
} }
LOG_DEBUG(GwLog::ERROR, "PageWindPlot Dataset: count: %d, TWD: %.0f, TWS: %.1f, TWD_valid? %d, intvBufSize: %d, numWndVals: %d, bufStart: %d, numAddedBufVals: %d, lastIdx: %d, old: %d, act: %d", LOG_DEBUG(GwLog::DEBUG, "PageWindPlot Dataset: count: %d, TWD: %.0f, TWS: %.1f, TWD_valid? %d, intvBufSize: %d, numWndVals: %d, bufStart: %d, numAddedBufVals: %d, lastIdx: %d, old: %d, act: %d",
count, pageData.boatHstry.twdHstry->getLast() / 1000.0 * radToDeg, pageData.boatHstry.twsHstry->getLast() / 10.0 * 1.94384, DataValid[0], count, pageData.boatHstry.twdHstry->getLast() / 1000.0 * radToDeg, pageData.boatHstry.twsHstry->getLast() / 10.0 * 1.94384, BDataValid[0],
intvBufSize, numWndVals, bufStart, numAddedBufVals, pageData.boatHstry.twdHstry->getLastIdx(), oldDataIntv, dataIntv); intvBufSize, numWndVals, bufStart, numAddedBufVals, pageData.boatHstry.twdHstry->getLastIdx(), oldDataIntv, dataIntv);
// Set wndCenter from 1st real buffer value // Set wndCenter from 1st real buffer value
@ -307,16 +307,13 @@ public:
if (pageData.boatHstry.twdHstry->getMax() == pageData.boatHstry.twdHstry->getMinVal()) { if (pageData.boatHstry.twdHstry->getMax() == pageData.boatHstry.twdHstry->getMinVal()) {
// only <INT16_MIN> values in buffer -> no valid wind data available // only <INT16_MIN> values in buffer -> no valid wind data available
wndDataValid = false; wndDataValid = false;
} else if (!DataValid[0]) { } else if (!BDataValid[0]) {
// currently no valid TWD data available // currently no valid TWD data available
numNoData++; numNoData++;
wndDataValid = true; wndDataValid = true;
if (numNoData > 3) { if (numNoData > 3) {
// If more than 4 invalid values in a row, send message // If more than 4 invalid values in a row, send message
wndDataValid = false; wndDataValid = false;
getdisplay().setFont(&Ubuntu_Bold10pt8b);
getdisplay().fillRect(xCenter - 66, height / 2 - 20, 146, 24, commonData->bgcolor); // Clear area for TWS value
drawTextCenter(xCenter, height / 2 - 10, "No sensor data");
} }
} else { } else {
numNoData = 0; // reset data error counter numNoData = 0; // reset data error counter
@ -397,8 +394,8 @@ public:
// No valid data available // No valid data available
LOG_DEBUG(GwLog::LOG, "PageWindPlot: No valid data available"); LOG_DEBUG(GwLog::LOG, "PageWindPlot: No valid data available");
getdisplay().setFont(&Ubuntu_Bold10pt8b); getdisplay().setFont(&Ubuntu_Bold10pt8b);
getdisplay().fillRect(xCenter - 66, height / 2 - 20, 146, 24, commonData->bgcolor); // Clear area for TWS value getdisplay().fillRect(xCenter - 33, height / 2 - 20, 66, 24, commonData->bgcolor); // Clear area for message
drawTextCenter(xCenter, height / 2 - 10, "No sensor data"); drawTextCenter(xCenter, height / 2 - 10, "No data");
} }
// Print TWS value // Print TWS value
@ -425,24 +422,25 @@ public:
getdisplay().fillRect(xPosTws - 4, yPosTws - 38, 142, 44, commonData->bgcolor); // Clear area for TWS value getdisplay().fillRect(xPosTws - 4, yPosTws - 38, 142, 44, commonData->bgcolor); // Clear area for TWS value
getdisplay().setFont(&DSEG7Classic_BoldItalic16pt7b); getdisplay().setFont(&DSEG7Classic_BoldItalic16pt7b);
getdisplay().setCursor(xPosTws, yPosTws); getdisplay().setCursor(xPosTws, yPosTws);
if (!DataValid[1]) { if (!BDataValid[1]) {
getdisplay().print("--.-"); getdisplay().print("--.-");
} else { } else {
if (DataValue[1] < 9.95) { double dbl = BDataValue[1] * 3.6 / 1.852;
getdisplay().printf("!%3.1f", DataValue[1] + 0.05); // Value, round to 1 decimal if (dbl < 10.0) {
getdisplay().printf("!%3.1f", dbl); // Value, round to 1 decimal
} else { } else {
getdisplay().printf("%4.1f", DataValue[1] + 0.05); // Value, round to 1 decimal getdisplay().printf("%4.1f", dbl); // Value, round to 1 decimal
} }
} }
getdisplay().setFont(&Ubuntu_Bold12pt8b); getdisplay().setFont(&Ubuntu_Bold12pt8b);
getdisplay().setCursor(xPosTws + 82, yPosTws - 14); getdisplay().setCursor(xPosTws + 82, yPosTws - 14);
// getdisplay().print("TWS"); // Name // getdisplay().print("TWS"); // Name
getdisplay().print(DataName[1]); // Name getdisplay().print(BDataName[1]); // Name
getdisplay().setFont(&Ubuntu_Bold8pt8b); getdisplay().setFont(&Ubuntu_Bold8pt8b);
// getdisplay().setCursor(xPosTws + 78, yPosTws + 1); // getdisplay().setCursor(xPosTws + 78, yPosTws + 1);
getdisplay().setCursor(xPosTws + 82, yPosTws + 1); getdisplay().setCursor(xPosTws + 82, yPosTws + 1);
// getdisplay().printf(" kn"); // Unit // getdisplay().printf(" kn"); // Unit
getdisplay().print(DataUnit[1]); // Unit getdisplay().print(BDataUnit[1]); // Unit
} }
// chart Y axis labels; print at last to overwrite potential chart lines in label area // chart Y axis labels; print at last to overwrite potential chart lines in label area
@ -464,10 +462,7 @@ public:
getdisplay().printf("%3d", chrtLbl); // Wind value label getdisplay().printf("%3d", chrtLbl); // Wind value label
} }
unsigned long finish = millis() - WndPlotStart; return PAGE_UPDATE;
LOG_DEBUG(GwLog::ERROR, "PageWindPlot Time: %lu", finish);
// Update display
getdisplay().nextPage(); // Partial update (fast)
}; };
}; };

View File

@ -381,6 +381,7 @@ bool addTrueWind(GwApi* api, BoatValueList* boatValues) {
// Calculate true wind data and add to obp60task boat data list // Calculate true wind data and add to obp60task boat data list
double awaVal, awsVal, cogVal, stwVal, sogVal, hdtVal, hdmVal, varVal; double awaVal, awsVal, cogVal, stwVal, sogVal, hdtVal, hdmVal, varVal;
double twd, tws, twa;
bool isCalculated = false; bool isCalculated = false;
const double DBL_MIN = std::numeric_limits<double>::lowest(); const double DBL_MIN = std::numeric_limits<double>::lowest();
@ -403,15 +404,27 @@ bool addTrueWind(GwApi* api, BoatValueList* boatValues) {
hdtVal = hdtBVal->valid ? hdtBVal->value : DBL_MIN; hdtVal = hdtBVal->valid ? hdtBVal->value : DBL_MIN;
hdmVal = hdmBVal->valid ? hdmBVal->value : DBL_MIN; hdmVal = hdmBVal->valid ? hdmBVal->value : DBL_MIN;
varVal = varBVal->valid ? varBVal->value : DBL_MIN; varVal = varBVal->valid ? varBVal->value : DBL_MIN;
api->getLogger()->logDebug(GwLog::ERROR,"obp60task addTrueWind: AWA: %.1f, AWS: %.1f, COG: %.1f, STW: %.1f, HDT: %.1f, HDM: %.1f, VAR: %.1f", awaBVal->value * RAD_TO_DEG, awsBVal->value * 3.6 / 1.852, api->getLogger()->logDebug(GwLog::DEBUG,"obp60task addTrueWind: AWA: %.1f, AWS: %.1f, COG: %.1f, STW: %.1f, HDT: %.1f, HDM: %.1f, VAR: %.1f", awaBVal->value * RAD_TO_DEG, awsBVal->value * 3.6 / 1.852,
cogBVal->value * RAD_TO_DEG, stwBVal->value * 3.6 / 1.852, hdtBVal->value * RAD_TO_DEG, hdmBVal->value * RAD_TO_DEG, varBVal->value * RAD_TO_DEG); cogBVal->value * RAD_TO_DEG, stwBVal->value * 3.6 / 1.852, hdtBVal->value * RAD_TO_DEG, hdmBVal->value * RAD_TO_DEG, varBVal->value * RAD_TO_DEG);
isCalculated = WindUtils::calcTrueWind(&awaVal, &awsVal, &cogVal, &stwVal, &sogVal, &hdtVal, &hdmVal, &varVal, &twdBVal->value, &twsBVal->value, &twaBVal->value); // isCalculated = WindUtils::calcTrueWind(&awaVal, &awsVal, &cogVal, &stwVal, &sogVal, &hdtVal, &hdmVal, &varVal, &twdBVal->value, &twsBVal->value, &twaBVal->value);
twdBVal->valid = isCalculated; isCalculated = WindUtils::calcTrueWind(&awaVal, &awsVal, &cogVal, &stwVal, &sogVal, &hdtVal, &hdmVal, &varVal, &twd, &tws, &twa);
twsBVal->valid = isCalculated;
twaBVal->valid = isCalculated;
api->getLogger()->logDebug(GwLog::ERROR,"obp60task calcTrueWind: TWD_Valid? %d, TWD=%.1f, TWS=%.1f, TWA=%.1f, isCalculated? %d", twdBVal->valid, twdBVal->value * RAD_TO_DEG, twsBVal->value * 3.6 / 1.852, if (isCalculated) { // Replace values only, if successfully calculated and not already available
if (!twdBVal->valid) {
twdBVal->value = twd;
twdBVal->valid = true;
}
if (!twsBVal->valid) {
twsBVal->value = tws;
twsBVal->valid = true;
}
if (!twaBVal->valid) {
twaBVal->value = twa;
twaBVal->valid = true;
}
}
api->getLogger()->logDebug(GwLog::DEBUG,"obp60task calcTrueWind: TWD_Valid? %d, TWD=%.1f, TWS=%.1f, TWA=%.1f, isCalculated? %d", twdBVal->valid, twdBVal->value * RAD_TO_DEG, twsBVal->value * 3.6 / 1.852,
twaBVal->value * RAD_TO_DEG, isCalculated); twaBVal->value * RAD_TO_DEG, isCalculated);
return isCalculated; return isCalculated;
@ -451,7 +464,7 @@ void handleHstryBuf(GwApi* api, BoatValueList* boatValues, tBoatHstryData hstryB
GwApi::BoatValue *twsBVal = boatValues->findValueOrCreate(hstryBufList.twsHstry->getName()); GwApi::BoatValue *twsBVal = boatValues->findValueOrCreate(hstryBufList.twsHstry->getName());
GwApi::BoatValue *twaBVal = boatValues->findValueOrCreate("TWA"); GwApi::BoatValue *twaBVal = boatValues->findValueOrCreate("TWA");
api->getLogger()->logDebug(GwLog::ERROR,"obp60task handleHstryBuf: twdBVal: %f, twsBVal: %f, twaBVal: %f, TWD_isValid? %d", twdBVal->value * RAD_TO_DEG, api->getLogger()->logDebug(GwLog::DEBUG,"obp60task handleHstryBuf: twdBVal: %f, twsBVal: %f, twaBVal: %f, TWD_isValid? %d", twdBVal->value * RAD_TO_DEG,
twsBVal->value * 3.6 / 1.852, twaBVal->value * RAD_TO_DEG, twdBVal->valid); twsBVal->value * 3.6 / 1.852, twaBVal->value * RAD_TO_DEG, twdBVal->valid);
calBVal = new GwApi::BoatValue("TWD"); // temporary solution for calibration of history buffer values calBVal = new GwApi::BoatValue("TWD"); // temporary solution for calibration of history buffer values
calBVal->setFormat(twdBVal->getFormat()); calBVal->setFormat(twdBVal->getFormat());
@ -959,7 +972,7 @@ void OBP60Task(GwApi *api){
api->getStatus(commonData.status); api->getStatus(commonData.status);
if (calcTrueWnds) { if (calcTrueWnds) {
addTrueWind(api, &boatValues); // addTrueWind(api, &boatValues);
} }
// Handle history buffers for TWD, TWS for wind plot page and other usage // Handle history buffers for TWD, TWS for wind plot page and other usage
handleHstryBuf(api, &boatValues, hstryBufList); handleHstryBuf(api, &boatValues, hstryBufList);

View File

@ -102,5 +102,5 @@ build_flags=
${env.build_flags} ${env.build_flags}
upload_port = /dev/ttyUSB0 #OBP40 download via external USB/Serail converter 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 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
upload_speed = 230400 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200