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

adjusted simulation calc in OBPFormatter;

WindPlot + PageOneValue: aligned simulation data handling to standard; added "holdValues";
improved data check for chart buffer data; changed handling of tmpBVal -> always unique_ptr
This commit is contained in:
Ulrich Meine
2025-12-24 01:40:37 +01:00
parent 69754b85fd
commit 784cc15b8f
9 changed files with 176 additions and 83 deletions

View File

@@ -192,10 +192,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
rawvalue = value->value; rawvalue = value->value;
} }
else { else {
course = 2.53 + float(random(0, 10) / 100.0); course = M_PI_2 + float(random(-17, 17) / 100.0); // create random course/wind values with 90° +/- 10°
rawvalue = course; rawvalue = course;
} }
course = course * 57.2958; // Unit conversion form rad to deg course = course * RAD_TO_DEG; // Unit conversion form rad to deg
// Format 3 numbers with prefix zero // Format 3 numbers with prefix zero
snprintf(buffer,bsize,"%03.0f",course); snprintf(buffer,bsize,"%03.0f",course);
@@ -210,7 +210,7 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
rawvalue = value->value; rawvalue = value->value;
} }
else{ else{
rawvalue = 4.0 + float(random(0, 40)); rawvalue = 4.0 + float(random(-30, 40) / 10.0); // create random speed values from [1..8] m/s
speed = rawvalue; speed = rawvalue;
} }
if (String(speedFormat) == "km/h"){ if (String(speedFormat) == "km/h"){
@@ -244,7 +244,7 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
rawvalue = value->value; rawvalue = value->value;
} }
else { else {
rawvalue = 4.0 + float(random(0, 40)); rawvalue = 4.0 + float(random(0, 40) / 10.0); // create random wind speed values from [4..8] m/s
speed = rawvalue; speed = rawvalue;
} }
if (String(windspeedFormat) == "km/h"){ if (String(windspeedFormat) == "km/h"){
@@ -429,7 +429,7 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
rawvalue = value->value; rawvalue = value->value;
} }
else { else {
rawvalue = 18.0 + float(random(0, 100)) / 10.0; rawvalue = 18.0 + float(random(0, 100)) / 10.0; // create random depth values from [18..28] metres
depth = rawvalue; depth = rawvalue;
} }
if(String(lengthFormat) == "ft"){ if(String(lengthFormat) == "ft"){

View File

@@ -1,6 +1,5 @@
#include "OBPDataOperations.h" #include "OBPDataOperations.h"
#include "BoatDataCalibration.h" // Functions lib for data instance calibration #include "BoatDataCalibration.h" // Functions lib for data instance calibration
#include <math.h>
// --- Class HstryBuf --------------- // --- Class HstryBuf ---------------
HstryBuf::HstryBuf(const String& name, int size, BoatValueList* boatValues, GwLog* log) HstryBuf::HstryBuf(const String& name, int size, BoatValueList* boatValues, GwLog* log)
@@ -26,34 +25,29 @@ void HstryBuf::add(double value)
{ {
if (value >= hstryMin && value <= hstryMax) { if (value >= hstryMin && value <= hstryMax) {
hstryBuf.add(value); hstryBuf.add(value);
LOG_DEBUG(GwLog::DEBUG, "HstryBuf::add: name: %s, value: %.3f", hstryBuf.getName(), value);
} }
} }
void HstryBuf::handle(bool useSimuData) void HstryBuf::handle(bool useSimuData, CommonData& common)
{ {
GwApi::BoatValue* calBVal; //GwApi::BoatValue* tmpBVal;
std::unique_ptr<GwApi::BoatValue> tmpBVal; // Temp variable to get formatted and converted data value from OBP60Formatter
// create temporary boat value for calibration purposes and retrieval of simulation value
//tmpBVal = new GwApi::BoatValue(boatDataName.c_str());
tmpBVal = std::unique_ptr<GwApi::BoatValue>(new GwApi::BoatValue(boatDataName));
tmpBVal->setFormat(boatValue->getFormat());
tmpBVal->value = boatValue->value;
tmpBVal->valid = boatValue->valid;
if (boatValue->valid) { if (boatValue->valid) {
// Calibrate boat value before adding it to history buffer // Calibrate boat value before adding it to history buffer
calBVal = new GwApi::BoatValue(boatDataName.c_str()); calibrationData.calibrateInstance(tmpBVal.get(), logger);
calBVal->setFormat(boatValue->getFormat()); add(tmpBVal->value);
calBVal->value = boatValue->value;
calBVal->valid = boatValue->valid;
calibrationData.calibrateInstance(calBVal, logger);
add(calBVal->value);
delete calBVal;
calBVal = nullptr;
} else if (useSimuData) { // add simulated value to history buffer } else if (useSimuData) { // add simulated value to history buffer
double simValue = hstryBuf.getLast(); double simValue = formatValue(tmpBVal.get(), common).value; // simulated value is generated at <formatValue>
if (boatDataName == "TWD" || boatDataName == "AWD") {
simValue += static_cast<double>(random(-349, 349) / 1000.0);
simValue = WindUtils::to2PI(simValue);
} else if (boatDataName == "TWS" || boatDataName == "AWS") {
simValue += static_cast<double>(random(-5000, 5000) / 1000.0);
simValue = constrain(simValue, 0, 40);
}
add(simValue); add(simValue);
} }
} }
@@ -96,17 +90,17 @@ void HstryBuffers::addBuffer(const String& name)
double bufferMaxVal = bufferParams[name].bufferMaxVal; // Max value for this history buffer double bufferMaxVal = bufferParams[name].bufferMaxVal; // Max value for this history buffer
hstryBuffers[name]->init(valueFormat, hstryUpdFreq, mltplr, bufferMinVal, bufferMaxVal); hstryBuffers[name]->init(valueFormat, hstryUpdFreq, mltplr, bufferMinVal, bufferMaxVal);
LOG_DEBUG(GwLog::DEBUG, "HstryBuffers-new buffer added: name: %s, format: %s, multiplier: %d, min value: %.2f, max value: %.2f", name, valueFormat, mltplr, bufferMinVal, bufferMaxVal); LOG_DEBUG(GwLog::DEBUG, "HstryBuffers: new buffer added: name: %s, format: %s, multiplier: %d, min value: %.2f, max value: %.2f", name, valueFormat, mltplr, bufferMinVal, bufferMaxVal);
} }
// Handle history buffers // Handle history buffers
void HstryBuffers::handleHstryBufs(bool useSimuData) void HstryBuffers::handleHstryBufs(bool useSimuData, CommonData& common)
{ {
// Handle all registered history buffers // Handle all registered history buffers
for (auto& pair : hstryBuffers) { for (auto& pair : hstryBuffers) {
auto& buf = pair.second; auto& buf = pair.second;
buf->handle(useSimuData); buf->handle(useSimuData, common);
} }
} }

View File

@@ -2,6 +2,7 @@
#pragma once #pragma once
#include "OBPRingBuffer.h" #include "OBPRingBuffer.h"
#include "obp60task.h" #include "obp60task.h"
#include "Pagedata.h"
#include <map> #include <map>
class HstryBuf { class HstryBuf {
@@ -19,7 +20,7 @@ public:
HstryBuf(const String& name, int size, BoatValueList* boatValues, GwLog* log); HstryBuf(const String& name, int size, BoatValueList* boatValues, GwLog* log);
void init(const String& format, int updFreq, int mltplr, double minVal, double maxVal); void init(const String& format, int updFreq, int mltplr, double minVal, double maxVal);
void add(double value); void add(double value);
void handle(bool useSimuData); void handle(bool useSimuData, CommonData& common);
}; };
class HstryBuffers { class HstryBuffers {
@@ -61,7 +62,7 @@ private:
public: public:
HstryBuffers(int size, BoatValueList* boatValues, GwLog* log); HstryBuffers(int size, BoatValueList* boatValues, GwLog* log);
void addBuffer(const String& name); void addBuffer(const String& name);
void handleHstryBufs(bool useSimuData); void handleHstryBufs(bool useSimuData, CommonData& common);
RingBuffer<uint16_t>* getBuffer(const String& name); RingBuffer<uint16_t>* getBuffer(const String& name);
}; };

View File

@@ -1,6 +1,7 @@
// Function lib for display of boat data in various chart formats // Function lib for display of boat data in various chart formats
#include "OBPcharts.h" #include "OBPcharts.h"
#include "OBP60Extensions.h" #include "OBP60Extensions.h"
#include "OBPDataOperations.h"
#include "OBPRingBuffer.h" #include "OBPRingBuffer.h"
// --- Class Chart --------------- // --- Class Chart ---------------
@@ -183,6 +184,8 @@ void Chart<T>::drawChrt(int8_t chrtIntv, GwApi::BoatValue& currValue)
} }
calcChrtBorders(chrtMid, chrtMin, chrtMax, chrtRng); calcChrtBorders(chrtMid, chrtMin, chrtMax, chrtRng);
LOG_DEBUG(GwLog::DEBUG, "calcChrtBorders: min: %.3f, mid: %.3f, max: %.3f, rng: %.3f", chrtMin, chrtMid, chrtMax, chrtRng);
chrtScl = double(valAxis) / chrtRng; // Chart scale: pixels per value step chrtScl = double(valAxis) / chrtRng; // Chart scale: pixels per value step
// Do we have valid buffer data? // Do we have valid buffer data?
@@ -501,6 +504,10 @@ void Chart<T>::drawChrtValAxis()
slots = valAxis / 60.0; // number of axis labels slots = valAxis / 60.0; // number of axis labels
tmpBVal->value = chrtRng; tmpBVal->value = chrtRng;
cChrtRng = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted) cChrtRng = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted)
if (useSimuData) {
// cannot use <formatValue> in this case, because that would change the range value to some random data
cChrtRng = tmpBVal->value; // take SI value in this case -> need to be improved
}
intv = static_cast<int>(round(cChrtRng / slots)); intv = static_cast<int>(round(cChrtRng / slots));
i = intv; i = intv;
@@ -517,10 +524,8 @@ void Chart<T>::drawChrtValAxis()
loopEnd = valAxis - 30; loopEnd = valAxis - 30;
loopStp = 60; loopStp = 60;
} }
LOG_DEBUG(GwLog::DEBUG, "Chart drawValAxis: chrtDataFmt: %c, loopStrt: %d, loopEnd: %d, loopIntv: %d", chrtDataFmt, loopStrt, loopEnd, loopStp);
for (int j = loopStrt; (loopStp > 0) ? (j < loopEnd) : (j > loopEnd); j += loopStp) { for (int j = loopStrt; (loopStp > 0) ? (j < loopEnd) : (j > loopEnd); j += loopStp) {
LOG_DEBUG(GwLog::DEBUG, "Chart drawValAxis2: j: %d, i: %d", j, i);
getdisplay().drawLine(cStart.x, cStart.y + j, cStart.x + timAxis, cStart.y + j, fgColor); 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 getdisplay().fillRect(cStart.x, cStart.y + j - 11, 42, 21, bgColor); // Clear small area to remove potential chart lines
@@ -535,6 +540,9 @@ void Chart<T>::drawChrtValAxis()
tmpBVal->value = (chrtDataFmt == 'D') ? chrtMin : chrtMax; tmpBVal->value = (chrtDataFmt == 'D') ? chrtMin : chrtMax;
cVal = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted) cVal = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted)
if (useSimuData) { // dirty fix for problem that OBP60Formatter can only be used without data simulation -> returns random values in simulation mode
cVal = tmpBVal->value; // no value conversion here
}
sLen = snprintf(sVal, sizeof(sVal), "%.0f", round(cVal)); sLen = snprintf(sVal, sizeof(sVal), "%.0f", round(cVal));
getdisplay().fillRect(cStart.x, cStart.y + 2, 42, 16, bgColor); // Clear small area to remove potential chart lines getdisplay().fillRect(cStart.x, cStart.y + 2, 42, 16, bgColor); // Clear small area to remove potential chart lines
getdisplay().setCursor(cStart.x + ((3 - sLen) * 10), cStart.y + 16); getdisplay().setCursor(cStart.x + ((3 - sLen) * 10), cStart.y + 16);
@@ -542,6 +550,9 @@ void Chart<T>::drawChrtValAxis()
tmpBVal->value = chrtMid; tmpBVal->value = chrtMid;
cVal = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted) cVal = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted)
if (useSimuData) { // dirty fix for problem that OBP60Formatter can only be used without data simulation -> returns random values in simulation mode
cVal = tmpBVal->value; // no value conversion here
}
sLen = snprintf(sVal, sizeof(sVal), "%.0f", round(cVal)); sLen = snprintf(sVal, sizeof(sVal), "%.0f", round(cVal));
getdisplay().fillRect(cStart.x, cStart.y + (valAxis / 2) - 9, 42, 16, bgColor); // Clear small area to remove potential chart lines getdisplay().fillRect(cStart.x, cStart.y + (valAxis / 2) - 9, 42, 16, bgColor); // Clear small area to remove potential chart lines
getdisplay().setCursor(cStart.x + ((3 - sLen) * 10), cStart.y + (valAxis / 2) + 5); getdisplay().setCursor(cStart.x + ((3 - sLen) * 10), cStart.y + (valAxis / 2) + 5);
@@ -550,6 +561,9 @@ void Chart<T>::drawChrtValAxis()
tmpBVal->value = (chrtDataFmt == 'D') ? chrtMax : chrtMin; tmpBVal->value = (chrtDataFmt == 'D') ? chrtMax : chrtMin;
cVal = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted) cVal = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted)
if (useSimuData) { // dirty fix for problem that OBP60Formatter can only be used without data simulation -> returns random values in simulation mode
cVal = tmpBVal->value; // no value conversion here
}
sLen = snprintf(sVal, sizeof(sVal), "%.0f", round(cVal)); sLen = snprintf(sVal, sizeof(sVal), "%.0f", round(cVal));
getdisplay().fillRect(cStart.x, cStart.y + valAxis - 16, 42, 16, bgColor); // Clear small area to remove potential chart lines getdisplay().fillRect(cStart.x, cStart.y + valAxis - 16, 42, 16, bgColor); // Clear small area to remove potential chart lines
getdisplay().setCursor(cStart.x + ((3 - sLen) * 10), cStart.y + valAxis - 1); getdisplay().setCursor(cStart.x + ((3 - sLen) * 10), cStart.y + valAxis - 1);
@@ -571,17 +585,26 @@ void Chart<T>::drawChrtValAxis()
tmpBVal->value = chrtMin; tmpBVal->value = chrtMin;
cVal = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted) cVal = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted)
if (useSimuData) { // dirty fix for problem that OBP60Formatter can only be used without data simulation -> returns random values in simulation mode
cVal = tmpBVal->value; // no value conversion here
}
snprintf(sVal, sizeof(sVal), "%.0f", round(cVal)); snprintf(sVal, sizeof(sVal), "%.0f", round(cVal));
getdisplay().setCursor(cStart.x, cStart.y - 2); getdisplay().setCursor(cStart.x, cStart.y - 2);
getdisplay().printf("%s", sVal); // Range low end getdisplay().printf("%s", sVal); // Range low end
tmpBVal->value = chrtMid; tmpBVal->value = chrtMid;
cVal = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted) cVal = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted)
if (useSimuData) { // dirty fix for problem that OBP60Formatter can only be used without data simulation -> returns random values in simulation mode
cVal = tmpBVal->value; // no value conversion here
}
snprintf(sVal, sizeof(sVal), "%.0f", round(cVal)); snprintf(sVal, sizeof(sVal), "%.0f", round(cVal));
drawTextCenter(cStart.x + (valAxis / 2), cStart.y - 10, sVal); // Range mid end drawTextCenter(cStart.x + (valAxis / 2), cStart.y - 10, sVal); // Range mid end
tmpBVal->value = chrtMax; tmpBVal->value = chrtMax;
cVal = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted) cVal = formatValue(tmpBVal.get(), *commonData).cvalue; // value (converted)
if (useSimuData) { // dirty fix for problem that OBP60Formatter can only be used without data simulation -> returns random values in simulation mode
cVal = tmpBVal->value; // no value conversion here
}
snprintf(sVal, sizeof(sVal), "%.0f", round(cVal)); snprintf(sVal, sizeof(sVal), "%.0f", round(cVal));
drawTextRalign(cStart.x + valAxis - 2, cStart.y - 2, sVal); // Range high end drawTextRalign(cStart.x + valAxis - 2, cStart.y - 2, sVal); // Range high end
@@ -599,21 +622,16 @@ void Chart<T>::prntCurrValue(GwApi::BoatValue& currValue)
const int yPosVal = (chrtDir == 'H') ? cStart.y + valAxis - 7 : cStart.y + timAxis - 7; const int yPosVal = (chrtDir == 'H') ? cStart.y + valAxis - 7 : cStart.y + timAxis - 7;
FormattedData frmtDbData = formatValue(&currValue, *commonData); FormattedData frmtDbData = formatValue(&currValue, *commonData);
double testdbValue = frmtDbData.value; String sdbValue = frmtDbData.svalue; // value as formatted string
String sdbValue = frmtDbData.svalue; // value (string)
String dbUnit = frmtDbData.unit; // Unit of value String dbUnit = frmtDbData.unit; // Unit of value
// 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, // LOG_DEBUG(GwLog::DEBUG, "Chart CurrValue: dbValue: %.2f, sdbValue: %s, dbFormat: %s, dbUnit: %s, Valid: %d, Name: %s, Address: %p", currValue.value, sdbValue,
// testdbValue, currValue.getFormat(), dbUnit, currValue.valid, currValue.getName(), currValue); // currValue.getFormat(), dbUnit, currValue.valid, currValue.getName(), currValue);
getdisplay().fillRect(xPosVal - 1, yPosVal - 35, 125, 41, bgColor); // Clear area for TWS value getdisplay().fillRect(xPosVal - 1, yPosVal - 35, 128, 41, bgColor); // Clear area for TWS value
getdisplay().drawRect(xPosVal, yPosVal - 34, 123, 40, fgColor); // Draw box for TWS value getdisplay().drawRect(xPosVal, yPosVal - 34, 126, 40, fgColor); // Draw box for TWS value
getdisplay().setFont(&DSEG7Classic_BoldItalic16pt7b); getdisplay().setFont(&DSEG7Classic_BoldItalic16pt7b);
getdisplay().setCursor(xPosVal + 1, yPosVal); getdisplay().setCursor(xPosVal + 1, yPosVal);
if (useSimuData) { getdisplay().print(sdbValue); // alue
getdisplay().printf("%2.1f", currValue.value); // Value
} else {
getdisplay().print(sdbValue); // Value
}
getdisplay().setFont(&Ubuntu_Bold10pt8b); getdisplay().setFont(&Ubuntu_Bold10pt8b);
getdisplay().setCursor(xPosVal + 76, yPosVal - 17); getdisplay().setCursor(xPosVal + 76, yPosVal - 17);

View File

@@ -26,7 +26,7 @@ protected:
int top = 44; // chart gap at top of display (25 lines for standard gap + 19 lines for axis labels) 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 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 <gap> int hGap = 11; // gap between 2 horizontal charts; actual gap is 2x <gap>
int vGap = 20; // gap between 2 vertical charts; actual gap is 2x <gap> int vGap = 17; // gap between 2 vertical charts; actual gap is 2x <gap>
int dWidth; // Display width int dWidth; // Display width
int dHeight; // Display height int dHeight; // Display height
int timAxis, valAxis; // size of time and value chart axis int timAxis, valAxis; // size of time and value chart axis

View File

@@ -2,6 +2,7 @@
#include "Pagedata.h" #include "Pagedata.h"
#include "OBP60Extensions.h" #include "OBP60Extensions.h"
#include "OBPDataOperations.h"
#include "BoatDataCalibration.h" #include "BoatDataCalibration.h"
#include "OBPcharts.h" #include "OBPcharts.h"
@@ -30,8 +31,6 @@ private:
// Data buffer pointer (owned by HstryBuffers) // Data buffer pointer (owned by HstryBuffers)
RingBuffer<uint16_t>* dataHstryBuf = nullptr; RingBuffer<uint16_t>* dataHstryBuf = nullptr;
std::unique_ptr<Chart<uint16_t>> dataFlChart, dataHfChart; // Chart object, full and half size std::unique_ptr<Chart<uint16_t>> dataFlChart, dataHfChart; // Chart object, full and half size
// Active chart and value
Chart<uint16_t>* dataChart = nullptr;
void showData(GwApi::BoatValue* bValue1, char size) void showData(GwApi::BoatValue* bValue1, char size)
{ {
@@ -81,16 +80,13 @@ private:
// Show unit // Show unit
getdisplay().setFont(unitFnt); getdisplay().setFont(unitFnt);
getdisplay().setCursor(270 + unitXoff, 100 + unitYoff); getdisplay().setCursor(270 + unitXoff, 100 + unitYoff);
if (holdValues == false) { if (holdValues) {
//getdisplay().print(unit1); // Unit
drawTextRalign(298 + unitXoff, 100 + unitYoff, unit1); // Unit
} else {
// getdisplay().print(unit1Old);
drawTextRalign(298 + unitXoff, 100 + unitYoff, unit1Old); drawTextRalign(298 + unitXoff, 100 + unitYoff, unit1Old);
} else {
drawTextRalign(298 + unitXoff, 100 + unitYoff, unit1); // Unit
} }
// Switch font if format for any values // Switch font depending on value format and adjust position
if (bValue1->getFormat() == "formatLatitude" || bValue1->getFormat() == "formatLongitude") { if (bValue1->getFormat() == "formatLatitude" || bValue1->getFormat() == "formatLongitude") {
getdisplay().setFont(valueFnt1); getdisplay().setFont(valueFnt1);
getdisplay().setCursor(20 + value1Xoff, 180 + value1Yoff); getdisplay().setCursor(20 + value1Xoff, 180 + value1Yoff);
@@ -103,11 +99,12 @@ private:
} }
// Show bus data // Show bus data
if (holdValues == false) { if (!holdValues || useSimuData) {
getdisplay().print(sValue1); // Real value as formated string getdisplay().print(sValue1); // Real value as formated string
} else { } else {
getdisplay().print(sValue1Old); // Old value as formated string getdisplay().print(sValue1Old); // Old value as formated string
} }
if (valid1 == true) { if (valid1 == true) {
sValue1Old = sValue1; // Save the old value sValue1Old = sValue1; // Save the old value
unit1Old = unit1; // Save the old unit unit1Old = unit1; // Save the old unit
@@ -195,17 +192,22 @@ public:
setFlashLED(false); setFlashLED(false);
} }
#endif #endif
if (!dataFlChart) { // Create chart objects if they don't exist // buffer initialization cannot be performed here, because <displayNew> is not executed at system start for default page
/* if (!dataFlChart) { // Create chart objects if they don't exist
GwApi::BoatValue* bValue1 = pageData.values[0]; // Page boat data element GwApi::BoatValue* bValue1 = pageData.values[0]; // Page boat data element
String bValName1 = bValue1->getName(); // Value name String bValName1 = bValue1->getName(); // Value name
String bValFormat = bValue1->getFormat(); // Value format String bValFormat = bValue1->getFormat(); // Value format
dataHstryBuf = pageData.hstryBuffers->getBuffer(bValName1); dataHstryBuf = pageData.hstryBuffers->getBuffer(bValName1);
if (dataHstryBuf) {
dataFlChart.reset(new Chart<uint16_t>(*dataHstryBuf, 'H', 0, Chart<uint16_t>::dfltChartRng[bValFormat], *commonData, useSimuData)); dataFlChart.reset(new Chart<uint16_t>(*dataHstryBuf, 'H', 0, Chart<uint16_t>::dfltChartRng[bValFormat], *commonData, useSimuData));
dataHfChart.reset(new Chart<uint16_t>(*dataHstryBuf, 'H', 2, Chart<uint16_t>::dfltChartRng[bValFormat], *commonData, useSimuData)); dataHfChart.reset(new Chart<uint16_t>(*dataHstryBuf, 'H', 2, Chart<uint16_t>::dfltChartRng[bValFormat], *commonData, useSimuData));
LOG_DEBUG(GwLog::DEBUG, "PageOneValue: Created chart objects for %s", bValName1); LOG_DEBUG(GwLog::DEBUG, "PageOneValue: Created chart objects for %s", bValName1);
} else {
LOG_DEBUG(GwLog::DEBUG, "PageOneValue: No chart objects available for %s", bValName1);
} }
} */
} }
int displayPage(PageData& pageData) int displayPage(PageData& pageData)
@@ -224,10 +226,27 @@ public:
setFlashLED(false); setFlashLED(false);
} }
if (!dataFlChart) { // 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
dataHstryBuf = pageData.hstryBuffers->getBuffer(bValName1);
if (dataHstryBuf) {
dataFlChart.reset(new Chart<uint16_t>(*dataHstryBuf, 'H', 0, Chart<uint16_t>::dfltChartRng[bValFormat], *commonData, useSimuData));
dataHfChart.reset(new Chart<uint16_t>(*dataHstryBuf, 'H', 2, Chart<uint16_t>::dfltChartRng[bValFormat], *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);
}
}
// Logging boat values // Logging boat values
if (bValue1 == NULL) if (bValue1 == NULL)
return PAGE_OK; // WTF why this statement? return PAGE_OK; // WTF why this statement?
LOG_DEBUG(GwLog::LOG, "Drawing at PageOneValue, %s: %f", bValue1->getName().c_str(), bValue1->value);
LOG_DEBUG(GwLog::DEBUG, "Drawing at PageOneValue, %s, %.3f", bValue1->getName().c_str(), bValue1->value);
// Draw page // Draw page
//*********************************************************** //***********************************************************
@@ -238,12 +257,16 @@ public:
showData(bValue1, 'F'); showData(bValue1, 'F');
} else if (pageMode == 'C') { // show only data chart } else if (pageMode == 'C') { // show only data chart
if (dataFlChart) {
dataFlChart->showChrt(dataIntv, *bValue1, true); dataFlChart->showChrt(dataIntv, *bValue1, true);
}
} else if (pageMode == 'B') { // show data value and chart } else if (pageMode == 'B') { // show data value and chart
showData(bValue1, 'H'); showData(bValue1, 'H');
if (dataHfChart) {
dataHfChart->showChrt(dataIntv, *bValue1, false); dataHfChart->showChrt(dataIntv, *bValue1, false);
} }
}
return PAGE_UPDATE; return PAGE_UPDATE;
}; };

View File

@@ -2,6 +2,7 @@
#include "Pagedata.h" #include "Pagedata.h"
#include "OBP60Extensions.h" #include "OBP60Extensions.h"
#include "OBPDataOperations.h"
#include "OBPcharts.h" #include "OBPcharts.h"
// **************************************************************** // ****************************************************************
@@ -21,6 +22,7 @@ private:
int dataIntv = 1; // Update interval for wind history chart: int 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 // (1)|(2)|(3)|(4)|(8) x 240 seconds for 4, 8, 12, 16, 32 min. history chart
bool useSimuData; bool useSimuData;
//bool holdValues;
String flashLED; String flashLED;
String backlightMode; String backlightMode;
@@ -149,28 +151,40 @@ public:
} }
oldShowTruW = !showTruW; // Force chart update in displayPage oldShowTruW = !showTruW; // Force chart update in displayPage
#endif #endif
// buffer initialization cannot be performed here, because <displayNew> is not executed at system start for default page
if (!twdFlChart) { // Create true wind charts if they don't exist /* if (!twdFlChart) { // Create true wind charts if they don't exist
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: Creating true wind charts");
twdHstry = pageData.hstryBuffers->getBuffer("TWD"); twdHstry = pageData.hstryBuffers->getBuffer("TWD");
twsHstry = pageData.hstryBuffers->getBuffer("TWS"); twsHstry = pageData.hstryBuffers->getBuffer("TWS");
if (twdHstry) {
twdFlChart.reset(new Chart<uint16_t>(*twdHstry, 'V', 0, dfltRngWd, *commonData, useSimuData)); twdFlChart.reset(new Chart<uint16_t>(*twdHstry, 'V', 0, dfltRngWd, *commonData, useSimuData));
twsFlChart.reset(new Chart<uint16_t>(*twsHstry, 'H', 0, dfltRngWs, *commonData, useSimuData));
twdHfChart.reset(new Chart<uint16_t>(*twdHstry, 'V', 1, dfltRngWd, *commonData, useSimuData)); twdHfChart.reset(new Chart<uint16_t>(*twdHstry, 'V', 1, dfltRngWd, *commonData, useSimuData));
}
if (twsHstry) {
twsFlChart.reset(new Chart<uint16_t>(*twsHstry, 'H', 0, dfltRngWs, *commonData, useSimuData));
twsHfChart.reset(new Chart<uint16_t>(*twsHstry, 'V', 2, dfltRngWs, *commonData, useSimuData)); twsHfChart.reset(new Chart<uint16_t>(*twsHstry, 'V', 2, dfltRngWs, *commonData, useSimuData));
} }
}
if (!awdFlChart) { // Create apparent wind charts if they don't exist if (!awdFlChart) { // Create apparent wind charts if they don't exist
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: Creating apparent wind charts");
awdHstry = pageData.hstryBuffers->getBuffer("AWD"); awdHstry = pageData.hstryBuffers->getBuffer("AWD");
awsHstry = pageData.hstryBuffers->getBuffer("AWS"); awsHstry = pageData.hstryBuffers->getBuffer("AWS");
if (awdHstry) {
awdFlChart.reset(new Chart<uint16_t>(*awdHstry, 'V', 0, dfltRngWd, *commonData, useSimuData)); awdFlChart.reset(new Chart<uint16_t>(*awdHstry, 'V', 0, dfltRngWd, *commonData, useSimuData));
awsFlChart.reset(new Chart<uint16_t>(*awsHstry, 'H', 0, dfltRngWs, *commonData, useSimuData));
awdHfChart.reset(new Chart<uint16_t>(*awdHstry, 'V', 1, dfltRngWd, *commonData, useSimuData)); awdHfChart.reset(new Chart<uint16_t>(*awdHstry, 'V', 1, dfltRngWd, *commonData, useSimuData));
}
if (awsHstry) {
awsFlChart.reset(new Chart<uint16_t>(*awsHstry, 'H', 0, dfltRngWs, *commonData, useSimuData));
awsHfChart.reset(new Chart<uint16_t>(*awsHstry, 'V', 2, dfltRngWs, *commonData, useSimuData)); awsHfChart.reset(new Chart<uint16_t>(*awsHstry, 'V', 2, dfltRngWs, *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) int displayPage(PageData& pageData)
@@ -178,6 +192,39 @@ public:
LOG_DEBUG(GwLog::LOG, "Display PageWindPlot"); LOG_DEBUG(GwLog::LOG, "Display PageWindPlot");
ulong pageTime = millis(); 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 (twdHstry) {
twdFlChart.reset(new Chart<uint16_t>(*twdHstry, 'V', 0, dfltRngWd, *commonData, useSimuData));
twdHfChart.reset(new Chart<uint16_t>(*twdHstry, 'V', 1, dfltRngWd, *commonData, useSimuData));
}
if (twsHstry) {
twsFlChart.reset(new Chart<uint16_t>(*twsHstry, 'H', 0, dfltRngWs, *commonData, useSimuData));
twsHfChart.reset(new Chart<uint16_t>(*twsHstry, 'V', 2, dfltRngWs, *commonData, useSimuData));
}
}
if (!awdFlChart) { // 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<uint16_t>(*awdHstry, 'V', 0, dfltRngWd, *commonData, useSimuData));
awdHfChart.reset(new Chart<uint16_t>(*awdHstry, 'V', 1, dfltRngWd, *commonData, useSimuData));
}
if (awsHstry) {
awsFlChart.reset(new Chart<uint16_t>(*awsHstry, 'H', 0, dfltRngWs, *commonData, useSimuData));
awsHfChart.reset(new Chart<uint16_t>(*awsHstry, 'V', 2, dfltRngWs, *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) { if (showTruW != oldShowTruW) {
// Switch active charts based on showTruW // Switch active charts based on showTruW
@@ -199,6 +246,7 @@ public:
oldShowTruW = showTruW; oldShowTruW = showTruW;
} }
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: draw with data %s: %.2f, %s: %.2f", wdBVal->getName().c_str(), wdBVal->value, wsBVal->getName().c_str(), wsBVal->value);
// Draw page // Draw page
//*********************************************************** //***********************************************************
@@ -208,15 +256,23 @@ public:
getdisplay().setTextColor(commonData->fgcolor); getdisplay().setTextColor(commonData->fgcolor);
if (chrtMode == 'D') { if (chrtMode == 'D') {
if (wdFlChart) {
wdFlChart->showChrt(dataIntv, *wdBVal, true); wdFlChart->showChrt(dataIntv, *wdBVal, true);
}
} else if (chrtMode == 'S') { } else if (chrtMode == 'S') {
if (wsFlChart) {
wsFlChart->showChrt(dataIntv, *wsBVal, true); wsFlChart->showChrt(dataIntv, *wsBVal, true);
}
} else if (chrtMode == 'B') { } else if (chrtMode == 'B') {
if (wdHfChart) {
wdHfChart->showChrt(dataIntv, *wdBVal, true); wdHfChart->showChrt(dataIntv, *wdBVal, true);
}
if (wsHfChart) {
wsHfChart->showChrt(dataIntv, *wsBVal, true); wsHfChart->showChrt(dataIntv, *wsBVal, true);
} }
}
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: page time %ldms", millis() - pageTime); LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: page time %ldms", millis() - pageTime);
return PAGE_UPDATE; return PAGE_UPDATE;

View File

@@ -4,12 +4,13 @@
#include <functional> #include <functional>
#include <vector> #include <vector>
#include "LedSpiTask.h" #include "LedSpiTask.h"
#include "OBPDataOperations.h"
#define MAX_PAGE_NUMBER 10 // Max number of pages for show data #define MAX_PAGE_NUMBER 10 // Max number of pages for show data
typedef std::vector<GwApi::BoatValue *> ValueList; typedef std::vector<GwApi::BoatValue *> ValueList;
class HstryBuffers;
typedef struct{ typedef struct{
GwApi *api; GwApi *api;
String pageName; String pageName;

View File

@@ -815,7 +815,7 @@ void OBP60Task(GwApi *api){
trueWind.addWinds(); trueWind.addWinds();
} }
// Handle history buffers for certain boat data for windplot page and other usage // Handle history buffers for certain boat data for windplot page and other usage
hstryBufList.handleHstryBufs(useSimuData); hstryBufList.handleHstryBufs(useSimuData, commonData);
// Clear display // Clear display
// getdisplay().fillRect(0, 0, getdisplay().width(), getdisplay().height(), commonData.bgcolor); // getdisplay().fillRect(0, 0, getdisplay().width(), getdisplay().height(), commonData.bgcolor);