mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2026-03-28 18:06:37 +01:00
Integrate many changes from master
This commit is contained in:
@@ -1,127 +1,113 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#if defined BOARD_OBP60S3 || defined BOARD_OBP40S3
|
||||
|
||||
#include "Pagedata.h"
|
||||
#include "OBP60Extensions.h"
|
||||
#include "OBPRingBuffer.h"
|
||||
#include "OBPDataOperations.h"
|
||||
#include "BoatDataCalibration.h"
|
||||
#include <vector>
|
||||
|
||||
static const double radToDeg = 180.0 / M_PI; // Conversion factor from radians to degrees
|
||||
|
||||
// Get maximum difference of last <amount> of TWD ringbuffer values to center chart; returns "0" if data is not valid
|
||||
int getCntr(const RingBuffer<int16_t>& windDirHstry, size_t amount)
|
||||
{
|
||||
const int MAX_VAL = windDirHstry.getMaxVal();
|
||||
size_t count = windDirHstry.getCurrentSize();
|
||||
|
||||
if (windDirHstry.isEmpty() || amount <= 0) {
|
||||
return 0;
|
||||
}
|
||||
if (amount > count)
|
||||
amount = count;
|
||||
|
||||
uint16_t midWndDir, minWndDir, maxWndDir = 0;
|
||||
int wndCenter = 0;
|
||||
|
||||
midWndDir = windDirHstry.getMid(amount);
|
||||
if (midWndDir != MAX_VAL) {
|
||||
midWndDir = midWndDir / 1000.0 * radToDeg;
|
||||
wndCenter = int((midWndDir + (midWndDir >= 0 ? 5 : -5)) / 10) * 10; // Set new center value; round to nearest 10 degree value
|
||||
minWndDir = windDirHstry.getMin(amount) / 1000.0 * radToDeg;
|
||||
maxWndDir = windDirHstry.getMax(amount) / 1000.0 * radToDeg;
|
||||
if ((maxWndDir - minWndDir) > 180 && !(minWndDir > maxWndDir)) { // if wind range is > 180 and no 0° crossover, adjust wndCenter to smaller wind range end
|
||||
wndCenter = WindUtils::to360(wndCenter + 180);
|
||||
}
|
||||
}
|
||||
|
||||
return wndCenter;
|
||||
}
|
||||
|
||||
// Get maximum difference of last <amount> of TWD ringbuffer values to center chart
|
||||
int getRng(const RingBuffer<int16_t>& windDirHstry, int center, size_t amount)
|
||||
{
|
||||
int minVal = windDirHstry.getMinVal();
|
||||
const int MAX_VAL = windDirHstry.getMaxVal();
|
||||
size_t count = windDirHstry.getCurrentSize();
|
||||
|
||||
if (windDirHstry.isEmpty() || amount <= 0) {
|
||||
return MAX_VAL;
|
||||
}
|
||||
if (amount > count)
|
||||
amount = count;
|
||||
|
||||
int value = 0;
|
||||
int rng = 0;
|
||||
int maxRng = minVal;
|
||||
// Start from the newest value (last) and go backwards x times
|
||||
for (size_t i = 0; i < amount; i++) {
|
||||
value = windDirHstry.get(count - 1 - i);
|
||||
|
||||
if (value == MAX_VAL) {
|
||||
continue; // ignore invalid values
|
||||
}
|
||||
|
||||
value = value / 1000.0 * radToDeg;
|
||||
rng = abs(((value - center + 540) % 360) - 180);
|
||||
if (rng > maxRng)
|
||||
maxRng = rng;
|
||||
}
|
||||
if (maxRng > 180) {
|
||||
maxRng = 180;
|
||||
}
|
||||
|
||||
return (maxRng != minVal ? maxRng : MAX_VAL);
|
||||
}
|
||||
#include "OBPcharts.h"
|
||||
|
||||
// ****************************************************************
|
||||
class PageWindPlot : public Page {
|
||||
class PageWindPlot : public Page
|
||||
{
|
||||
|
||||
private:
|
||||
GwLog* logger;
|
||||
|
||||
enum ChartMode {
|
||||
DIRECTION,
|
||||
SPEED,
|
||||
BOTH
|
||||
};
|
||||
|
||||
static constexpr char HORIZONTAL = 'H';
|
||||
static constexpr char VERTICAL = 'V';
|
||||
static constexpr int8_t FULL_SIZE = 0;
|
||||
static constexpr int8_t HALF_SIZE_LEFT = 1;
|
||||
static constexpr int8_t HALF_SIZE_RIGHT = 2;
|
||||
|
||||
static constexpr bool PRNT_NAME = true;
|
||||
static constexpr bool NO_PRNT_NAME = false;
|
||||
static constexpr bool PRNT_VALUE = true;
|
||||
static constexpr bool NO_PRNT_VALUE = false;
|
||||
|
||||
// int width; // Screen width
|
||||
// int height; // Screen height
|
||||
|
||||
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
|
||||
ChartMode chrtMode = DIRECTION;
|
||||
bool showTruW = true; // Show true wind or apparent 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
|
||||
int8_t 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
|
||||
bool useSimuData;
|
||||
// bool holdValues;
|
||||
String flashLED;
|
||||
String backlightMode;
|
||||
|
||||
#ifdef BOARD_OBP40S3
|
||||
String wndSrc; // Wind source true/apparent wind - preselection for OBP40
|
||||
#endif
|
||||
|
||||
// Data buffers pointers (owned by HstryBuffers)
|
||||
RingBuffer<uint16_t>* twdHstry = nullptr;
|
||||
RingBuffer<uint16_t>* twsHstry = nullptr;
|
||||
RingBuffer<uint16_t>* awdHstry = nullptr;
|
||||
RingBuffer<uint16_t>* awsHstry = nullptr;
|
||||
|
||||
// Chart objects
|
||||
std::unique_ptr<Chart> twdChart, awdChart; // Chart object for wind direction
|
||||
std::unique_ptr<Chart> twsChart, awsChart; // Chart object for wind speed
|
||||
|
||||
// Active charts and values
|
||||
Chart* wdChart = nullptr;
|
||||
Chart* wsChart = nullptr;
|
||||
GwApi::BoatValue* wdBVal = nullptr;
|
||||
GwApi::BoatValue* wsBVal = nullptr;
|
||||
|
||||
public:
|
||||
PageWindPlot(CommonData& common) : Page(common)
|
||||
{
|
||||
logger->logDebug(GwLog::LOG, "Instantiate PageWindPlot");
|
||||
|
||||
//width = epd->width(); // Screen width
|
||||
//height = epd->height(); // Screen height
|
||||
|
||||
// Get config data
|
||||
oldShowTruW = !showTruW; // makes wind source being initialized at initial page call
|
||||
}
|
||||
|
||||
void setupKeys() {
|
||||
void setupKeys()
|
||||
{
|
||||
Page::setupKeys();
|
||||
// commonData->keydata[0].label = "MODE";
|
||||
commonData->keydata[0].label = "MODE";
|
||||
#if defined BOARD_OBP60S3
|
||||
commonData->keydata[1].label = "SRC";
|
||||
commonData->keydata[4].label = "INTV";
|
||||
commonData->keydata[4].label = "ZOOM";
|
||||
#elif defined BOARD_OBP40S3
|
||||
commonData->keydata[1].label = "INTV";
|
||||
commonData->keydata[1].label = "ZOOM";
|
||||
#endif
|
||||
}
|
||||
|
||||
// Key functions
|
||||
int handleKey(int key) {
|
||||
// Set chart mode TWD | TWS -> to be implemented
|
||||
int handleKey(int key)
|
||||
{
|
||||
// Set chart mode
|
||||
if (key == 1) {
|
||||
if (chrtMode == 'D') {
|
||||
chrtMode = 'S';
|
||||
} else if (chrtMode == 'S') {
|
||||
chrtMode = 'B';
|
||||
if (chrtMode == DIRECTION) {
|
||||
chrtMode = SPEED;
|
||||
} else if (chrtMode == SPEED) {
|
||||
chrtMode = BOTH;
|
||||
} else {
|
||||
chrtMode = 'D';
|
||||
chrtMode = DIRECTION;
|
||||
}
|
||||
return 0; // Commit the key
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined BOARD_OBP60S3
|
||||
// Set data source TRUE | APP
|
||||
if (key == 2) {
|
||||
showTruW = !showTruW;
|
||||
return 0; // Commit the key
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Set interval for wind history chart update time (interval)
|
||||
@@ -135,10 +121,12 @@ public:
|
||||
dataIntv = 3;
|
||||
} else if (dataIntv == 3) {
|
||||
dataIntv = 4;
|
||||
} else if (dataIntv == 4) {
|
||||
dataIntv = 8;
|
||||
} else {
|
||||
dataIntv = 1;
|
||||
}
|
||||
return 0; // Commit the key
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Keylock function
|
||||
@@ -149,7 +137,8 @@ public:
|
||||
return key;
|
||||
}
|
||||
|
||||
void displayNew(PageData &pageData) {
|
||||
virtual void displayNew(PageData& pageData)
|
||||
{
|
||||
#ifdef BOARD_OBP60S3
|
||||
// Clear optical warning
|
||||
if (flashLED == "Limit Violation") {
|
||||
@@ -158,344 +147,99 @@ public:
|
||||
}
|
||||
#endif
|
||||
#ifdef BOARD_OBP40S3
|
||||
String wndSrc; // Wind source true/apparant wind - preselection for OBP40
|
||||
|
||||
// we can only initialize user defined wind source here, because "pageData" is not available at object instantiation
|
||||
wndSrc = commonData->config->getString("page" + String(pageData.pageNumber) + "wndsrc");
|
||||
if (wndSrc =="True wind") {
|
||||
if (wndSrc == "True wind") {
|
||||
showTruW = true;
|
||||
} else {
|
||||
showTruW = false; // Wind source is apparant wind
|
||||
showTruW = false; // Wind source is apparent wind
|
||||
}
|
||||
commonData->logger->logDebug(GwLog::LOG,"New PageWindPlot: wind source=%s", wndSrc);
|
||||
oldShowTruW = !showTruW; // Force chart update in displayPage
|
||||
#endif
|
||||
oldShowTruW = !showTruW; // makes wind source being initialized at initial page call
|
||||
|
||||
if (!twdChart) { // Create true wind charts if they don't exist
|
||||
twdHstry = pageData.hstryBuffers->getBuffer("TWD");
|
||||
twsHstry = pageData.hstryBuffers->getBuffer("TWS");
|
||||
|
||||
if (twdHstry) {
|
||||
twdChart.reset(new Chart(*twdHstry, Chart::dfltChrtDta["formatCourse"].range, *commonData, useSimuData));
|
||||
}
|
||||
if (twsHstry) {
|
||||
twsChart.reset(new Chart(*twsHstry, Chart::dfltChrtDta["formatKnots"].range, *commonData, useSimuData));
|
||||
}
|
||||
}
|
||||
|
||||
if (!awdChart) { // Create apparent wind charts if they don't exist
|
||||
awdHstry = pageData.hstryBuffers->getBuffer("AWD");
|
||||
awsHstry = pageData.hstryBuffers->getBuffer("AWS");
|
||||
|
||||
if (awdHstry) {
|
||||
awdChart.reset(new Chart(*awdHstry, Chart::dfltChrtDta["formatCourse"].range, *commonData, useSimuData));
|
||||
}
|
||||
if (awsHstry) {
|
||||
awsChart.reset(new Chart(*awsHstry, Chart::dfltChrtDta["formatKnots"].range, *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) {
|
||||
|
||||
static RingBuffer<int16_t>* wdHstry; // Wind direction 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 int16_t wdMAX_VAL; // Max. value of wd history buffer, indicating invalid values
|
||||
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
|
||||
const int numBoatData = 2;
|
||||
GwApi::BoatValue* bvalue;
|
||||
bool BDataValid[numBoatData];
|
||||
|
||||
static bool isInitialized = false; // Flag to indicate that page is initialized
|
||||
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 width; // Screen width
|
||||
static int height; // Screen height
|
||||
static int xCenter; // Center of screen in x direction
|
||||
static const int yOffset = 48; // Offset for y coordinates of chart area
|
||||
static int cHeight; // height of chart area
|
||||
static int bufSize; // History buffer size: 960 values for appox. 16 min. history chart
|
||||
static int intvBufSize; // Buffer size used for currently selected time interval
|
||||
int count; // current size of buffer
|
||||
static int numWndVals; // number of wind values available for current interval selection
|
||||
static int bufStart; // 1st data value in buffer to show
|
||||
int numAddedBufVals; // Number of values added to buffer since last display
|
||||
size_t currIdx; // Current index in TWD history buffer
|
||||
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 int wndCenter; // chart wind center value position
|
||||
static int wndLeft; // chart wind left value position
|
||||
static int wndRight; // chart wind right value position
|
||||
static int chrtRng; // Range of wind values from mid wind value to min/max wind value in degrees
|
||||
int diffRng; // Difference between mid and current wind value
|
||||
static const int dfltRng = 60; // Default range for chart
|
||||
int midWndDir; // New value for wndCenter after chart start / shift
|
||||
|
||||
int x, y; // x and y coordinates for drawing
|
||||
static int prevX, prevY; // Last x and y coordinates for drawing
|
||||
static float chrtScl; // Scale for wind values in pixels per degree
|
||||
int chrtVal; // Current wind value
|
||||
static int chrtPrevVal; // Last wind value in chart area for check if value crosses 180 degree line
|
||||
|
||||
int displayPage(PageData& pageData)
|
||||
{
|
||||
logger->logDebug(GwLog::LOG, "Display PageWindPlot");
|
||||
ulong timer = millis();
|
||||
|
||||
if (!isInitialized) {
|
||||
width = epd->width();
|
||||
height = epd->height();
|
||||
xCenter = width / 2;
|
||||
cHeight = height - yOffset - 22;
|
||||
numNoData = 0;
|
||||
bufStart = 0;
|
||||
oldDataIntv = 0;
|
||||
wsValue = 0;
|
||||
numAddedBufVals, currIdx, lastIdx = 0;
|
||||
wndCenter = INT_MAX;
|
||||
midWndDir = 0;
|
||||
diffRng = dfltRng;
|
||||
chrtRng = dfltRng;
|
||||
|
||||
isInitialized = true; // Set flag to indicate that page is now initialized
|
||||
}
|
||||
|
||||
// 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];
|
||||
BDataValid[i] = bvalue->valid;
|
||||
}
|
||||
|
||||
// Optical warning by limit violation (unused)
|
||||
if (String(flashLED) == "Limit Violation") {
|
||||
setBlinkingLED(false);
|
||||
setFlashLED(false);
|
||||
}
|
||||
// ulong pageTime = millis();
|
||||
|
||||
if (showTruW != oldShowTruW) {
|
||||
|
||||
// Switch active charts based on showTruW
|
||||
if (showTruW) {
|
||||
wdHstry = pageData.boatHstry->hstryBufList.twdHstry;
|
||||
wsHstry = pageData.boatHstry->hstryBufList.twsHstry;
|
||||
wdChart = twdChart.get();
|
||||
wsChart = twsChart.get();
|
||||
wdBVal = pageData.values[0];
|
||||
wsBVal = pageData.values[1];
|
||||
} else {
|
||||
wdHstry = pageData.boatHstry->hstryBufList.awdHstry;
|
||||
wsHstry = pageData.boatHstry->hstryBufList.awsHstry;
|
||||
wdChart = awdChart.get();
|
||||
wsChart = awsChart.get();
|
||||
wdBVal = pageData.values[2];
|
||||
wsBVal = pageData.values[3];
|
||||
}
|
||||
wdHstry->getMetaData(wdName, wdFormat);
|
||||
wsHstry->getMetaData(wsName, wsFormat);
|
||||
wdMAX_VAL = wdHstry->getMaxVal();
|
||||
bufSize = wdHstry->getCapacity();
|
||||
wsBVal->setFormat(wsHstry->getFormat());
|
||||
lastAddedIdx = wdHstry->getLastIdx();
|
||||
|
||||
oldShowTruW = showTruW;
|
||||
}
|
||||
|
||||
// Identify buffer size and buffer start position for chart
|
||||
count = wdHstry->getCurrentSize();
|
||||
currIdx = wdHstry->getLastIdx();
|
||||
numAddedBufVals = (currIdx - lastAddedIdx + bufSize) % bufSize; // Number of values added to buffer since last display
|
||||
if (dataIntv != oldDataIntv || count == 1) {
|
||||
// new data interval selected by user
|
||||
intvBufSize = cHeight * dataIntv;
|
||||
numWndVals = min(count, (cHeight - 60) * dataIntv);
|
||||
bufStart = max(0, count - numWndVals);
|
||||
lastAddedIdx = currIdx;
|
||||
oldDataIntv = dataIntv;
|
||||
} else {
|
||||
numWndVals = numWndVals + numAddedBufVals;
|
||||
lastAddedIdx = currIdx;
|
||||
if (count == bufSize) {
|
||||
bufStart = max(0, bufStart - numAddedBufVals);
|
||||
}
|
||||
}
|
||||
logger->logDebug(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_MAX || (wndCenter == 0 && count == 1)) {
|
||||
wndCenter = getCntr(*wdHstry, numWndVals);
|
||||
logger->logDebug(GwLog::DEBUG, "PageWindPlot Range Init: count: %d, xWD: %.1f, 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);
|
||||
} else {
|
||||
// check and adjust range between left, center, and right chart limit
|
||||
diffRng = getRng(*wdHstry, wndCenter, numWndVals);
|
||||
diffRng = (diffRng == wdMAX_VAL ? 0 : diffRng);
|
||||
if (diffRng > chrtRng) {
|
||||
chrtRng = int((diffRng + (diffRng >= 0 ? 9 : -1)) / 10) * 10; // Round up to next 10 degree value
|
||||
} else if (diffRng + 10 < chrtRng) { // Reduce chart range for higher resolution if possible
|
||||
chrtRng = max(dfltRng, int((diffRng + (diffRng >= 0 ? 9 : -1)) / 10) * 10);
|
||||
logger->logDebug(GwLog::DEBUG, "PageWindPlot Range adjust: wndCenter: %d, diffRng: %d, chrtRng: %d, Min: %.0f, Max: %.0f", wndCenter, diffRng, chrtRng,
|
||||
wdHstry->getMin(numWndVals) / 1000.0 * radToDeg, wdHstry->getMax(numWndVals) / 1000.0 * radToDeg);
|
||||
}
|
||||
}
|
||||
chrtScl = float(width) / float(chrtRng) / 2.0; // Chart scale: pixels per degree
|
||||
wndLeft = wndCenter - chrtRng;
|
||||
if (wndLeft < 0)
|
||||
wndLeft += 360;
|
||||
wndRight = (chrtRng < 180 ? wndCenter + chrtRng : wndCenter + chrtRng - 1);
|
||||
if (wndRight >= 360)
|
||||
wndRight -= 360;
|
||||
logger->logDebug(GwLog::DEBUG, "PageWindPlot: draw with data %s: %.2f, %s: %.2f", wdBVal->getName().c_str(), wdBVal->value, wsBVal->getName().c_str(), wsBVal->value);
|
||||
|
||||
// Draw page
|
||||
//***********************************************************************
|
||||
//***********************************************************
|
||||
|
||||
// Set display in partial refresh mode
|
||||
epd->setPartialWindow(0, 0, width, height); // Set partial update
|
||||
epd->setPartialWindow(0, 0, epd->width(), epd->height());
|
||||
epd->setTextColor(commonData->fgcolor);
|
||||
|
||||
// chart lines
|
||||
epd->fillRect(0, yOffset, width, 2, commonData->fgcolor);
|
||||
epd->fillRect(xCenter, yOffset, 1, cHeight, commonData->fgcolor);
|
||||
|
||||
// chart labels
|
||||
char sWndLbl[4]; // char buffer for Wind angle label
|
||||
epd->setFont(&Ubuntu_Bold12pt8b);
|
||||
epd->setCursor(xCenter - 88, yOffset - 3);
|
||||
epd->print(wdName); // Wind data name
|
||||
snprintf(sWndLbl, 4, "%03d", (wndCenter < 0) ? (wndCenter + 360) : wndCenter);
|
||||
drawTextCenter(xCenter, yOffset - 11, sWndLbl);
|
||||
epd->drawCircle(xCenter + 25, yOffset - 17, 2, commonData->fgcolor); // <degree> symbol
|
||||
epd->drawCircle(xCenter + 25, yOffset - 17, 3, commonData->fgcolor); // <degree> symbol
|
||||
epd->setCursor(1, yOffset - 3);
|
||||
snprintf(sWndLbl, 4, "%03d", (wndLeft < 0) ? (wndLeft + 360) : wndLeft);
|
||||
epd->print(sWndLbl); // Wind left value
|
||||
epd->drawCircle(46, yOffset - 17, 2, commonData->fgcolor); // <degree> symbol
|
||||
epd->drawCircle(46, yOffset - 17, 3, commonData->fgcolor); // <degree> symbol
|
||||
epd->setCursor(width - 50, yOffset - 3);
|
||||
snprintf(sWndLbl, 4, "%03d", (wndRight < 0) ? (wndRight + 360) : wndRight);
|
||||
epd->print(sWndLbl); // Wind right value
|
||||
epd->drawCircle(width - 5, yOffset - 17, 2, commonData->fgcolor); // <degree> symbol
|
||||
epd->drawCircle(width - 5, yOffset - 17, 3, commonData->fgcolor); // <degree> symbol
|
||||
|
||||
if (wdHstry->getMax() == wdMAX_VAL) {
|
||||
// only <MAX_VAL> values in buffer -> no valid wind data available
|
||||
wndDataValid = false;
|
||||
} else if (!BDataValid[0] && !simulation) {
|
||||
// currently no valid xWD data available and no simulation mode
|
||||
numNoData++;
|
||||
wndDataValid = true;
|
||||
if (numNoData > 3) {
|
||||
// If more than 4 invalid values in a row, send message
|
||||
wndDataValid = false;
|
||||
}
|
||||
} else {
|
||||
numNoData = 0; // reset data error counter
|
||||
wndDataValid = true; // At least some wind data available
|
||||
}
|
||||
// Draw wind values in chart
|
||||
//***********************************************************************
|
||||
if (wndDataValid) {
|
||||
for (int i = 0; i < (numWndVals / dataIntv); i++) {
|
||||
chrtVal = static_cast<int>(wdHstry->get(bufStart + (i * dataIntv))); // show the latest wind values in buffer; keep 1st value constant in a rolling buffer
|
||||
if (chrtVal == wdMAX_VAL) {
|
||||
chrtPrevVal = wdMAX_VAL;
|
||||
} else {
|
||||
chrtVal = static_cast<int>((chrtVal / 1000.0 * radToDeg) + 0.5); // Convert to degrees and round
|
||||
x = ((chrtVal - wndLeft + 360) % 360) * chrtScl;
|
||||
y = yOffset + cHeight - i; // Position in chart area
|
||||
|
||||
if (i >= (numWndVals / dataIntv) - 1) // log chart data of 1 line (adjust for test purposes)
|
||||
logger->logDebug(GwLog::DEBUG, "PageWindPlot Chart: i: %d, chrtVal: %d, bufStart: %d, count: %d, linesToShow: %d", i, chrtVal, bufStart, count, (numWndVals / dataIntv));
|
||||
|
||||
if ((i == 0) || (chrtPrevVal == wdMAX_VAL)) {
|
||||
// just a dot for 1st chart point or after some invalid values
|
||||
prevX = x;
|
||||
prevY = y;
|
||||
} else {
|
||||
// cross borders check; shift values to [-180..0..180]; when crossing borders, range is 2x 180 degrees
|
||||
int wndLeftDlt = -180 - ((wndLeft >= 180) ? (wndLeft - 360) : wndLeft);
|
||||
int chrtVal180 = ((chrtVal + wndLeftDlt + 180) % 360 + 360) % 360 - 180;
|
||||
int chrtPrevVal180 = ((chrtPrevVal + wndLeftDlt + 180) % 360 + 360) % 360 - 180;
|
||||
if (((chrtPrevVal180 >= -180) && (chrtPrevVal180 < -90) && (chrtVal180 > 90)) || ((chrtPrevVal180 <= 179) && (chrtPrevVal180 > 90) && chrtVal180 <= -90)) {
|
||||
// If current value crosses chart borders compared to previous value, split line
|
||||
int xSplit = (((chrtPrevVal180 > 0 ? wndRight : wndLeft) - wndLeft + 360) % 360) * chrtScl;
|
||||
epd->drawLine(prevX, prevY, xSplit, y, commonData->fgcolor);
|
||||
epd->drawLine(prevX, prevY - 1, ((xSplit != prevX) ? xSplit : xSplit - 1), ((xSplit != prevX) ? y - 1 : y), commonData->fgcolor);
|
||||
prevX = (((chrtVal180 > 0 ? wndRight : wndLeft) - wndLeft + 360) % 360) * chrtScl;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw line with 2 pixels width + make sure vertical line are drawn correctly
|
||||
epd->drawLine(prevX, prevY, x, y, commonData->fgcolor);
|
||||
epd->drawLine(prevX, prevY - 1, ((x != prevX) ? x : x - 1), ((x != prevX) ? y - 1 : y), commonData->fgcolor);
|
||||
chrtPrevVal = chrtVal;
|
||||
prevX = x;
|
||||
prevY = y;
|
||||
}
|
||||
// Reaching chart area top end
|
||||
if (i >= (cHeight - 1)) {
|
||||
oldDataIntv = 0; // force reset of buffer start and number of values to show in next display loop
|
||||
|
||||
int minWndDir = wdHstry->getMin(numWndVals) / 1000.0 * radToDeg;
|
||||
int maxWndDir = wdHstry->getMax(numWndVals) / 1000.0 * radToDeg;
|
||||
logger->logDebug(GwLog::DEBUG, "PageWindPlot FreeTop: Minimum: %d, Maximum: %d, OldwndCenter: %d", minWndDir, maxWndDir, wndCenter);
|
||||
// if (((minWndDir - wndCenter >= 0) && (minWndDir - wndCenter < 180)) || ((maxWndDir - wndCenter <= 0) && (maxWndDir - wndCenter >=180))) {
|
||||
if ((wndRight > wndCenter && (minWndDir >= wndCenter && minWndDir <= wndRight)) || (wndRight <= wndCenter && (minWndDir >= wndCenter || minWndDir <= wndRight)) || (wndLeft < wndCenter && (maxWndDir <= wndCenter && maxWndDir >= wndLeft)) || (wndLeft >= wndCenter && (maxWndDir <= wndCenter || maxWndDir >= wndLeft))) {
|
||||
// Check if all wind value are left or right of center value -> optimize chart center
|
||||
wndCenter = getCntr(*wdHstry, numWndVals);
|
||||
}
|
||||
logger->logDebug(GwLog::DEBUG, "PageWindPlot FreeTop: cHeight: %d, bufStart: %d, numWndVals: %d, wndCenter: %d", cHeight, bufStart, numWndVals, wndCenter);
|
||||
break;
|
||||
}
|
||||
if (chrtMode == DIRECTION) {
|
||||
if (wdChart) {
|
||||
wdChart->showChrt(VERTICAL, FULL_SIZE, dataIntv, PRNT_NAME, PRNT_VALUE, *wdBVal);
|
||||
}
|
||||
|
||||
// Print wind speed value
|
||||
int currentZone;
|
||||
static int lastZone = 0;
|
||||
static bool flipTws = false;
|
||||
int xPosTws;
|
||||
static const int yPosTws = yOffset + 40;
|
||||
|
||||
xPosTws = flipTws ? 20 : width - 145;
|
||||
currentZone = (y >= yPosTws - 38) && (y <= yPosTws + 6) && (x >= xPosTws - 4) && (x <= xPosTws + 146) ? 1 : 0; // Define current zone for TWS value
|
||||
if (currentZone != lastZone) {
|
||||
// Only flip when x moves to a different zone
|
||||
if ((y >= yPosTws - 38) && (y <= yPosTws + 6) && (x >= xPosTws - 4) && (x <= xPosTws + 146)) {
|
||||
flipTws = !flipTws;
|
||||
xPosTws = flipTws ? 20 : width - 145;
|
||||
}
|
||||
} else if (chrtMode == SPEED) {
|
||||
if (wsChart) {
|
||||
wsChart->showChrt(HORIZONTAL, FULL_SIZE, dataIntv, PRNT_NAME, PRNT_VALUE, *wsBVal);
|
||||
}
|
||||
lastZone = currentZone;
|
||||
|
||||
wsValue = wsHstry->getLast();
|
||||
wsBVal->value = wsValue / 1000.0; // temp variable to retreive data unit from OBP60Formater
|
||||
wsBVal->valid = (static_cast<uint16_t>(wsValue) != wsHstry->getMinVal());
|
||||
String swsValue = commonData->fmt->formatValue(wsBVal, *commonData).svalue; // value (string)
|
||||
wsUnit = commonData->fmt->formatValue(wsBVal, *commonData).unit; // Unit of value
|
||||
epd->fillRect(xPosTws - 4, yPosTws - 38, 142, 44, commonData->bgcolor); // Clear area for TWS value
|
||||
epd->setFont(&DSEG7Classic_BoldItalic16pt7b);
|
||||
epd->setCursor(xPosTws, yPosTws);
|
||||
epd->print(swsValue); // Value
|
||||
/* if (!wsBVal->valid) {
|
||||
epd->print("--.-");
|
||||
} else {
|
||||
wsValue = wsValue / 10.0 * 1.94384; // Wind speed value in knots
|
||||
if (wsValue < 10.0) {
|
||||
epd->printf("!%3.1f", wsValue); // Value, round to 1 decimal
|
||||
} else {
|
||||
epd->printf("%4.1f", wsValue); // Value, round to 1 decimal
|
||||
}
|
||||
} */
|
||||
epd->setFont(&Ubuntu_Bold12pt8b);
|
||||
epd->setCursor(xPosTws + 82, yPosTws - 14);
|
||||
epd->print(wsName); // Name
|
||||
epd->setFont(&Ubuntu_Bold8pt8b);
|
||||
epd->setCursor(xPosTws + 82, yPosTws + 1);
|
||||
epd->print(wsUnit); // Unit
|
||||
|
||||
} else {
|
||||
// No valid data available
|
||||
LOG_DEBUG(GwLog::LOG, "PageWindPlot: No valid data available");
|
||||
epd->setFont(&Ubuntu_Bold10pt8b);
|
||||
epd->fillRect(xCenter - 33, height / 2 - 20, 66, 24, commonData->bgcolor); // Clear area for message
|
||||
drawTextCenter(xCenter, height / 2 - 10, "No data");
|
||||
} else if (chrtMode == BOTH) {
|
||||
if (wdChart) {
|
||||
wdChart->showChrt(VERTICAL, HALF_SIZE_LEFT, dataIntv, PRNT_NAME, PRNT_VALUE, *wdBVal);
|
||||
}
|
||||
if (wsChart) {
|
||||
wsChart->showChrt(VERTICAL, HALF_SIZE_RIGHT, dataIntv, PRNT_NAME, PRNT_VALUE, *wsBVal);
|
||||
}
|
||||
}
|
||||
|
||||
// chart Y axis labels; print at last to overwrite potential chart lines in label area
|
||||
int yPos;
|
||||
int chrtLbl;
|
||||
epd->setFont(&Ubuntu_Bold8pt8b);
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
yPos = yOffset + (i * 60);
|
||||
epd->fillRect(0, yPos, width, 1, commonData->fgcolor);
|
||||
epd->fillRect(0, yPos - 8, 24, 16, commonData->bgcolor); // Clear small area to remove potential chart lines
|
||||
epd->setCursor(1, yPos + 4);
|
||||
if (count >= intvBufSize) {
|
||||
// Calculate minute value for label
|
||||
chrtLbl = ((i - 1 + (prevY < yOffset + 30)) * dataIntv) * -1; // change label if last data point is more than 30 lines (= seconds) from chart line
|
||||
} else {
|
||||
int j = 3 - i;
|
||||
chrtLbl = (int((((numWndVals / dataIntv) - 50) * dataIntv / 60) + 1) - (j * dataIntv)) * -1; // 50 lines left below last chart line
|
||||
}
|
||||
epd->printf("%3d", chrtLbl); // Wind value label
|
||||
}
|
||||
|
||||
logger->logDebug(GwLog::DEBUG, "PageWindPlot time: %ld", millis() - timer);
|
||||
// logger->logDebug(GwLog::DEBUG, "PageWindPlot: page time %ldms", millis() - pageTime);
|
||||
return PAGE_UPDATE;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
static Page* createPage(CommonData& common)
|
||||
@@ -512,7 +256,7 @@ PageDescription registerPageWindPlot(
|
||||
"WindPlot", // Page name
|
||||
createPage, // Action
|
||||
0, // Number of bus values depends on selection in Web configuration
|
||||
{ "TWD", "AWD"}, // Bus values we need in the page
|
||||
{ "TWD", "TWS", "AWD", "AWS" }, // Bus values we need in the page
|
||||
true // Show display header on/off
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user