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

Code rework for OBPcharts, part 3

This commit is contained in:
Ulrich Meine
2026-01-10 12:31:37 +01:00
parent 84736e6769
commit 4747336a69
5 changed files with 413 additions and 426 deletions

View File

@@ -10,11 +10,32 @@ class PageOneValue : public Page {
private:
GwLog* logger;
enum PageMode {
VALUE,
CHART,
BOTH
};
enum DisplayMode {
FULL,
HALF
};
static constexpr char HORIZONTAL = 'H';
static constexpr char VERTICAL = 'V';
static constexpr int8_t FULL_SIZE = 0;
static constexpr int8_t HALF_SIZE_TOP = 1;
static constexpr int8_t HALF_SIZE_BOTTOM = 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 pageMode = 'V'; // Page mode: 'V' for value, 'C' for chart, 'B' for both
PageMode pageMode = VALUE; // Page display mode
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
@@ -31,14 +52,14 @@ private:
// Data buffer pointer (owned by HstryBuffers)
RingBuffer<uint16_t>* dataHstryBuf = nullptr;
std::unique_ptr<Chart> dataChart; // Chart object, full and half size
std::unique_ptr<Chart> dataChart; // Chart object
void showData(GwApi::BoatValue* bValue1, char size)
void showData(GwApi::BoatValue* bValue1, DisplayMode mode)
{
int nameXoff, nameYoff, unitXoff, unitYoff, value1Xoff, value1Yoff;
const GFXfont *nameFnt, *unitFnt, *valueFnt1, *valueFnt2, *valueFnt3;
if (size == 'F') { // full size data display
if (mode == FULL) { // full size data display
nameXoff = 0;
nameYoff = 0;
nameFnt = &Ubuntu_Bold32pt8b;
@@ -51,17 +72,17 @@ private:
valueFnt2 = &Ubuntu_Bold32pt8b;
valueFnt3 = &DSEG7Classic_BoldItalic60pt7b;
} else { // half size data and chart display
nameXoff = 105;
nameYoff = -35;
nameXoff = -10;
nameYoff = -34;
nameFnt = &Ubuntu_Bold20pt8b;
unitXoff = -35;
unitYoff = -102;
unitXoff = 63;
unitYoff = -119;
unitFnt = &Ubuntu_Bold12pt8b;
valueFnt1 = &Ubuntu_Bold12pt8b;
value1Xoff = 105;
value1Yoff = -102;
value1Xoff = 153;
value1Yoff = -119;
valueFnt2 = &Ubuntu_Bold20pt8b;
valueFnt3 = &DSEG7Classic_BoldItalic30pt7b;
valueFnt3 = &DSEG7Classic_BoldItalic42pt7b;
}
String name1 = xdrDelete(bValue1->getName()); // Value name
@@ -156,14 +177,18 @@ public:
{
if (dataHstryBuf) { // if boat data type supports charts
// Set page mode value | full chart | value/half chart
// Set page mode value | value/half chart | full chart
if (key == 1) {
if (pageMode == 'V') {
pageMode = 'C';
} else if (pageMode == 'C') {
pageMode = 'B';
} else {
pageMode = 'V';
switch (pageMode) {
case VALUE:
pageMode = BOTH;
break;
case BOTH:
pageMode = CHART;
break;
case CHART:
pageMode = VALUE;
break;
}
return 0; // Commit the key
}
@@ -208,6 +233,7 @@ public:
#endif
// buffer initialization will fail, if page is default page, because <displayNew> is not executed at system start for default page
if (!dataChart) { // 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
@@ -216,7 +242,6 @@ public:
if (dataHstryBuf) {
dataChart.reset(new Chart(*dataHstryBuf, Chart::dfltChrtDta[bValFormat].range, *commonData, useSimuData));
//dataHfChart.reset(new Chart(*dataHstryBuf, 'H', 2, Chart::dfltChrtDta[bValFormat].range, *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);
@@ -228,7 +253,6 @@ public:
int displayPage(PageData& pageData)
{
LOG_DEBUG(GwLog::LOG, "Display PageOneValue");
// Get boat value for page
@@ -250,19 +274,19 @@ public:
getdisplay().setPartialWindow(0, 0, width, height); // Set partial update
if (pageMode == 'V' || dataHstryBuf == nullptr) {
if (pageMode == VALUE || dataHstryBuf == nullptr) {
// show only data value; ignore other pageMode options if no chart supported boat data history buffer is available
showData(bValue1, 'F');
showData(bValue1, FULL);
} else if (pageMode == 'C') { // show only data chart
} else if (pageMode == CHART) { // show only data chart
if (dataChart) {
dataChart->showChrt('H', 0, dataIntv, true, *bValue1);
dataChart->showChrt(HORIZONTAL, FULL_SIZE, dataIntv, PRNT_NAME, PRNT_VALUE, *bValue1);
}
} else if (pageMode == 'B') { // show data value and chart
showData(bValue1, 'H');
} else if (pageMode == BOTH) { // show data value and chart
showData(bValue1, HALF);
if (dataChart) {
dataChart->showChrt('H', 2, dataIntv, false, *bValue1);
dataChart->showChrt(HORIZONTAL, HALF_SIZE_BOTTOM, dataIntv, NO_PRNT_NAME, NO_PRNT_VALUE, *bValue1);
}
}