mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-29 13:33:06 +01:00
Code part for more chart plots
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
// Function lib for history buffer handling, true wind calculation, and other operations on boat data
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <N2kMessages.h>
|
#include <N2kMessages.h>
|
||||||
#include "OBPRingBuffer.h"
|
#include "OBPRingBuffer.h"
|
||||||
|
|||||||
75
lib/obp60task/OBPcharts.cpp
Normal file
75
lib/obp60task/OBPcharts.cpp
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
// Function lib for display of boat data in various chart formats
|
||||||
|
#include "OBPcharts.h"
|
||||||
|
|
||||||
|
// --- Class Chart ---------------
|
||||||
|
void Chart::drawChrtHdr() {
|
||||||
|
// chart header label + lines
|
||||||
|
int i;
|
||||||
|
getdisplay().fillRect(0, top, cWidth, 2, commonData->fgcolor);
|
||||||
|
|
||||||
|
// horizontal chart labels
|
||||||
|
getdisplay().drawLine(cStart.x, cStart.y, cWidth, cStart.y);
|
||||||
|
getdisplay().fillRect(cStart.x, cStart.y, cWidth, 2, commonData->fgcolor);
|
||||||
|
|
||||||
|
getdisplay().setFont(&Ubuntu_Bold10pt8b);
|
||||||
|
getdisplay().setCursor(cStart.x, cStart.y + 12);
|
||||||
|
getdisplay().print(dbName); // Wind data name
|
||||||
|
|
||||||
|
getdisplay().setFont(&Ubuntu_Bold12pt8b);
|
||||||
|
if (chrtSze == 0) {
|
||||||
|
i = -1 * (chrtIntv / 8 - 2);
|
||||||
|
} else {
|
||||||
|
i = -1 * (chrtIntv / 4 - 2);
|
||||||
|
}
|
||||||
|
for (int j = 50; j <= (cWidth - 50); j += 50 ) {
|
||||||
|
getdisplay().setCursor(cStart.x + j - 16, cStart.y + 12);
|
||||||
|
getdisplay().print(i++); // time interval
|
||||||
|
// i++;
|
||||||
|
getdisplay().drawLine(cStart.x + j - 30, cStart.y, cStart.x - 30, cHeight + top);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Chart::drawChrtGrd(const int chrtRng) {
|
||||||
|
// chart Y axis labels + lines
|
||||||
|
int i;
|
||||||
|
|
||||||
|
getdisplay().setFont(&Ubuntu_Bold8pt8b);
|
||||||
|
if (chrtDir == 0) {
|
||||||
|
i = -1 * (chrtRng / 4 - 2);
|
||||||
|
for (int j = cStart.x; j <= (cHeight - (cHeight / 4)); j += cHeight / 4 ) {
|
||||||
|
getdisplay().drawLine(0, cStart.y, cWidth, cStart.y);
|
||||||
|
getdisplay().setCursor(0, cStart.y + 12);
|
||||||
|
if (i < 10)
|
||||||
|
getdisplay().printf("!!%1d", i); // Range value
|
||||||
|
else if (i < 100)
|
||||||
|
getdisplay().printf("!%2d", i); // Range value
|
||||||
|
else
|
||||||
|
getdisplay().printf("%3d", i); // Range value
|
||||||
|
i += (chrtRng / 4);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
i = -1 * (chrtRng / 8 - 2);
|
||||||
|
for (int j = cStart.x; j <= (cHeight - (cHeight / 8)); j += cHeight / 8 ) {
|
||||||
|
getdisplay().drawLine(cStart.x + j - 30, cStart.y, cStart.x - 30, cHeight + top);
|
||||||
|
getdisplay().setCursor(0, cStart.y + 12);
|
||||||
|
if (i < 10)
|
||||||
|
getdisplay().printf("!!%1d", i); // Range value
|
||||||
|
else if (i < 100)
|
||||||
|
getdisplay().printf("!%2d", i); // Range value
|
||||||
|
else
|
||||||
|
getdisplay().printf("%3d", i); // Range value
|
||||||
|
i += (chrtRng / 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Chart::drawChrt(int8_t chrtIntv, int dfltRng) {
|
||||||
|
// hstryBuf = buffer to display
|
||||||
|
// bValue = present value to display additionally to chart
|
||||||
|
// chrtDir = chart direction: [0] = vertical, [1] = horizontal
|
||||||
|
// chrtSze = chart size: [0] = full size, [1] = half size left half/top, [2] half size right half/bottom
|
||||||
|
// chrtIntv = chart time interval: [1] 4 min., [2] 8 min., [3] 12 min., [4] 16 min., [5] 32 min.
|
||||||
|
// dfltRng = default range of chart, e.g. 30 = [0..30]
|
||||||
|
|
||||||
|
}
|
||||||
|
// --- Class Chart ---------------
|
||||||
103
lib/obp60task/OBPcharts.h
Normal file
103
lib/obp60task/OBPcharts.h
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
// Function lib for display of boat data in various chart formats
|
||||||
|
#pragma once
|
||||||
|
#include "OBP60Extensions.h"
|
||||||
|
#include "Pagedata.h"
|
||||||
|
// #include "OBPDataOperations.h"
|
||||||
|
// #include "OBPRingBuffer.h"
|
||||||
|
|
||||||
|
struct Point {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Chart {
|
||||||
|
protected:
|
||||||
|
RingBuffer<uint16_t>* dataBuf; // Buffer to display
|
||||||
|
GwApi::BoatValue* bValue; // Present value to display additionally to chart
|
||||||
|
int8_t chrtDir; // Chart direction: [0] = vertical, [1] = horizontal
|
||||||
|
int8_t chrtSze; // Chart size: [0] = full size, [1] = half size left/top, [2] half size right/bottom
|
||||||
|
int8_t chrtIntv; // Chart time interval: [4] 4 min., [8] 8 min., [12] 12 min., [16] 16 min., [32] 32 min.
|
||||||
|
int dfltRng; // Default range of chart, e.g. 30 = [0..30]
|
||||||
|
|
||||||
|
int top = 48; // display top header lines
|
||||||
|
int bottom = 22; // display bottom lines
|
||||||
|
int gap = 4; // gap between 2 charts; actual gap is 2x <gap>
|
||||||
|
int cWidth;
|
||||||
|
int cHeight;
|
||||||
|
Point cStart; // start point for chart area
|
||||||
|
int cLines; // number of chart lines
|
||||||
|
int xCenter; // x center point of chart
|
||||||
|
|
||||||
|
String dbName, dbFormat;
|
||||||
|
int16_t dbMAX_VAL;
|
||||||
|
size_t bufSize;
|
||||||
|
GwApi::BoatValue* bValue;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Chart(RingBuffer<uint16_t>* dataBuf, GwApi::BoatValue* bValue, int8_t chrtDir, int8_t chrtSz, int8_t chrtIntv, int dfltRng, GwLog* logger)
|
||||||
|
: dataBuf(dataBuf)
|
||||||
|
, bValue(bValue)
|
||||||
|
, chrtDir(chrtDir)
|
||||||
|
, chrtSze(chrtSze)
|
||||||
|
, chrtIntv(chrtIntv)
|
||||||
|
, dfltRng(dfltRng)
|
||||||
|
{
|
||||||
|
cWidth = getdisplay().width();
|
||||||
|
cHeight = getdisplay().height();
|
||||||
|
cHeight = cHeight - top - bottom;
|
||||||
|
if (chrtDir == 0) {
|
||||||
|
// vertical chart
|
||||||
|
switch (chrtSze) {
|
||||||
|
case 0:
|
||||||
|
// default is already set
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
cWidth = cWidth;
|
||||||
|
cHeight = cHeight / 2 - gap;
|
||||||
|
cStart = { 30, cHeight + top };
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
cWidth = cWidth;
|
||||||
|
cHeight = cHeight / 2 - gap;
|
||||||
|
cStart = { cWidth + gap, top };
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
LOG_DEBUG(GwLog::DEBUG, "displayChart: wrong parameter");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (chrtDir == 1) {
|
||||||
|
// horizontal chart
|
||||||
|
switch (chrtSze) {
|
||||||
|
case 0:
|
||||||
|
cStart = { 0, cHeight - bottom };
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
cWidth = cWidth / 2 - gap;
|
||||||
|
cHeight = cHeight;
|
||||||
|
cStart = { 0, cHeight - bottom };
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
cWidth = cWidth / 2 - gap;
|
||||||
|
cHeight = cHeight;
|
||||||
|
cStart = { cWidth + gap, cHeight - bottom };
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
LOG_DEBUG(GwLog::DEBUG, "displayChart: wrong parameter");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG_DEBUG(GwLog::DEBUG, "displayChart: wrong parameter");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xCenter = cWidth / 2;
|
||||||
|
cLines = cHeight - 22;
|
||||||
|
|
||||||
|
dataBuf->getMetaData(dbName, dbFormat);
|
||||||
|
dbMAX_VAL = dataBuf->getMaxVal();
|
||||||
|
bufSize = dataBuf->getCapacity();
|
||||||
|
bValue->setFormat(dataBuf->getFormat());
|
||||||
|
};
|
||||||
|
void drawChrtHdr();
|
||||||
|
void drawChrtGrd(const int chrtRng);
|
||||||
|
bool drawChrt(int8_t chrtIntv, int dfltRng);
|
||||||
|
};
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
#if defined BOARD_OBP60S3 || defined BOARD_OBP40S3
|
#if defined BOARD_OBP60S3 || defined BOARD_OBP40S3
|
||||||
|
|
||||||
#include "Pagedata.h"
|
|
||||||
#include "OBP60Extensions.h"
|
|
||||||
#include "OBPRingBuffer.h"
|
|
||||||
#include "OBPDataOperations.h"
|
|
||||||
#include "BoatDataCalibration.h"
|
#include "BoatDataCalibration.h"
|
||||||
|
#include "OBP60Extensions.h"
|
||||||
|
#include "OBPDataOperations.h"
|
||||||
|
#include "OBPRingBuffer.h"
|
||||||
|
#include "OBPcharts.h"
|
||||||
|
#include "Pagedata.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
static const double radToDeg = 180.0 / M_PI; // Conversion factor from radians to degrees
|
static const double radToDeg = 180.0 / M_PI; // Conversion factor from radians to degrees
|
||||||
@@ -99,13 +100,12 @@ public:
|
|||||||
// holdValues = common.config->getBool(common.config->holdvalues);
|
// holdValues = common.config->getBool(common.config->holdvalues);
|
||||||
flashLED = common.config->getString(common.config->flashLED);
|
flashLED = common.config->getString(common.config->flashLED);
|
||||||
backlightMode = common.config->getString(common.config->backlight);
|
backlightMode = common.config->getString(common.config->backlight);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void setupKeys()
|
virtual void setupKeys()
|
||||||
{
|
{
|
||||||
Page::setupKeys();
|
Page::setupKeys();
|
||||||
// commonData->keydata[0].label = "MODE";
|
commonData->keydata[0].label = "MODE";
|
||||||
#if defined BOARD_OBP60S3
|
#if defined BOARD_OBP60S3
|
||||||
commonData->keydata[1].label = "SRC";
|
commonData->keydata[1].label = "SRC";
|
||||||
commonData->keydata[4].label = "INTV";
|
commonData->keydata[4].label = "INTV";
|
||||||
@@ -161,17 +161,18 @@ public:
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void displayNew(PageData &pageData){
|
virtual void displayNew(PageData& pageData)
|
||||||
|
{
|
||||||
#ifdef BOARD_OBP40S3
|
#ifdef BOARD_OBP40S3
|
||||||
String wndSrc; // Wind source true/apparant wind - preselection for OBP40
|
String wndSrc; // Wind source true/apparant wind - preselection for OBP40
|
||||||
|
|
||||||
wndSrc = commonData->config->getString("page" + String(pageData.pageNumber) + "wndsrc");
|
wndSrc = commonData->config->getString("page" + String(pageData.pageNumber) + "wndsrc");
|
||||||
if (wndSrc =="True wind") {
|
if (wndSrc == "True wind") {
|
||||||
showTruW = true;
|
showTruW = true;
|
||||||
} else {
|
} else {
|
||||||
showTruW = false; // Wind source is apparant wind
|
showTruW = false; // Wind source is apparant wind
|
||||||
}
|
}
|
||||||
commonData->logger->logDebug(GwLog::LOG,"New PageWindPlot: wind source=%s", wndSrc);
|
commonData->logger->logDebug(GwLog::LOG, "New PageWindPlot: wind source=%s", wndSrc);
|
||||||
#endif
|
#endif
|
||||||
oldShowTruW = !showTruW; // makes wind source being initialized at initial page call
|
oldShowTruW = !showTruW; // makes wind source being initialized at initial page call
|
||||||
}
|
}
|
||||||
@@ -280,6 +281,7 @@ public:
|
|||||||
oldShowTruW = showTruW;
|
oldShowTruW = showTruW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chrtMode == 'D') {
|
||||||
// Identify buffer size and buffer start position for chart
|
// Identify buffer size and buffer start position for chart
|
||||||
count = wdHstry->getCurrentSize();
|
count = wdHstry->getCurrentSize();
|
||||||
currIdx = wdHstry->getLastIdx();
|
currIdx = wdHstry->getLastIdx();
|
||||||
@@ -457,7 +459,7 @@ public:
|
|||||||
getdisplay().setFont(&DSEG7Classic_BoldItalic16pt7b);
|
getdisplay().setFont(&DSEG7Classic_BoldItalic16pt7b);
|
||||||
getdisplay().setCursor(xPosTws, yPosTws);
|
getdisplay().setCursor(xPosTws, yPosTws);
|
||||||
getdisplay().print(swsValue); // Value
|
getdisplay().print(swsValue); // Value
|
||||||
/* if (!wsBVal->valid) {
|
/* if (!wsBVal->valid) {
|
||||||
getdisplay().print("--.-");
|
getdisplay().print("--.-");
|
||||||
} else {
|
} else {
|
||||||
wsValue = wsValue / 1000.0 * 1.94384; // Wind speed value in knots
|
wsValue = wsValue / 1000.0 * 1.94384; // Wind speed value in knots
|
||||||
@@ -500,6 +502,14 @@ public:
|
|||||||
}
|
}
|
||||||
getdisplay().printf("%3d", chrtLbl); // Wind value label
|
getdisplay().printf("%3d", chrtLbl); // Wind value label
|
||||||
}
|
}
|
||||||
|
} else if (chrtMode == 'S') {
|
||||||
|
wsValue = wsHstry->getLast();
|
||||||
|
Chart twsChart(wsHstry, wsBVal, 0, 0, dataIntv, dfltRng, logger);
|
||||||
|
twsChart.drawChrtHdr();
|
||||||
|
twsChart.drawChrtGrd(40);
|
||||||
|
|
||||||
|
} else if (chrtMode == 'B') {
|
||||||
|
}
|
||||||
|
|
||||||
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot time: %ld", millis() - timer);
|
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot time: %ld", millis() - timer);
|
||||||
return PAGE_UPDATE;
|
return PAGE_UPDATE;
|
||||||
|
|||||||
Reference in New Issue
Block a user