From e43199b05d74ab80aa9dcfa5ae24cdf22f49200c Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Wed, 23 Jul 2025 14:00:06 +0200 Subject: [PATCH] Preparation for upcoming alarm functionality --- lib/obp60task/OBP60Extensions.cpp | 84 ++++++++++++++++++++++++++++ lib/obp60task/OBP60Extensions.h | 10 +++- lib/obp60task/PageBME280.cpp | 6 +- lib/obp60task/PageBattery.cpp | 6 +- lib/obp60task/PageBattery2.cpp | 5 +- lib/obp60task/PageClock.cpp | 8 +-- lib/obp60task/PageCompass.cpp | 13 ++--- lib/obp60task/PageDST810.cpp | 8 +-- lib/obp60task/PageFluid.cpp | 6 +- lib/obp60task/PageFourValues.cpp | 8 +-- lib/obp60task/PageFourValues2.cpp | 8 +-- lib/obp60task/PageGenerator.cpp | 5 +- lib/obp60task/PageKeelPosition.cpp | 6 +- lib/obp60task/PageOneValue.cpp | 8 +-- lib/obp60task/PageRollPitch.cpp | 8 +-- lib/obp60task/PageRudderPosition.cpp | 7 +-- lib/obp60task/PageSixValues.cpp | 8 +-- lib/obp60task/PageSolar.cpp | 5 +- lib/obp60task/PageSystem.cpp | 4 +- lib/obp60task/PageThreeValues.cpp | 7 +-- lib/obp60task/PageTwoValues.cpp | 7 +-- lib/obp60task/PageVoltage.cpp | 5 +- lib/obp60task/PageWhite.cpp | 9 ++- lib/obp60task/PageWind.cpp | 8 +-- lib/obp60task/PageWindRose.cpp | 7 +-- lib/obp60task/PageWindRoseFlex.cpp | 7 +-- lib/obp60task/PageXTETrack.cpp | 6 +- lib/obp60task/Pagedata.h | 19 ++++++- lib/obp60task/obp60task.cpp | 11 +++- 29 files changed, 191 insertions(+), 108 deletions(-) diff --git a/lib/obp60task/OBP60Extensions.cpp b/lib/obp60task/OBP60Extensions.cpp index 018702f..09ac7b7 100644 --- a/lib/obp60task/OBP60Extensions.cpp +++ b/lib/obp60task/OBP60Extensions.cpp @@ -350,6 +350,49 @@ void fillPoly4(const std::vector& p4, uint16_t color) { getdisplay().fillTriangle(p4[0].x, p4[0].y, p4[2].x, p4[2].y, p4[3].x, p4[3].y, color); } +// Split string into words, whitespace separated +std::vector split(const String &s) { + std::vector words; + String word = ""; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == ' ' || s[i] == '\t' || s[i] == '\r' || s[i] == '\n') { + if (word.length() > 0) { + words.push_back(word); + word = ""; + } + } else { + word += s[i]; + } + } + if (word.length() > 0) { + words.push_back(word); + } + return words; +} + +// Wordwrap single line, monospaced font +std::vector wordwrap(String &line, uint16_t maxwidth) { + std::vector lines; + std::vector words = split(line); + String currentLine = ""; + for (const auto& word : words) { + if (currentLine.length() + word.length() + 1 > maxwidth) { + if (currentLine.length() > 0) { + lines.push_back(currentLine); + currentLine = ""; + } + } + if (currentLine.length() > 0) { + currentLine += " "; + } + currentLine += word; + } + if (currentLine.length() > 0) { + lines.push_back(currentLine); + } + return lines; +} + // Draw centered text void drawTextCenter(int16_t cx, int16_t cy, String text) { int16_t x1, y1; @@ -595,6 +638,47 @@ void displayFooter(CommonData &commonData) { #endif } +// Alarm overlay, to be drawn as very last draw operation +void displayAlarm(CommonData &commonData) { + + const uint16_t x = 50; // overlay area + const uint16_t y = 100; + const uint16_t w = 300; + const uint16_t h = 150; + + getdisplay().setFont(&Atari16px); + getdisplay().setTextColor(commonData.fgcolor); + + // overlay + getdisplay().drawRect(x, y, w, h, commonData.fgcolor); + getdisplay().fillRect(x + 1, y + 1, w - 1, h - 1, commonData.bgcolor); + getdisplay().drawRect(x + 3, y + 3, w - 5, h - 5, commonData.fgcolor); + + // exclamation icon in left top corner + getdisplay().drawXBitmap(x + 16, y + 16, exclamation_bits, exclamation_width, exclamation_height, commonData.fgcolor); + + // title + getdisplay().setCursor(x + 64, y + 30); + getdisplay().print("A L A R M"); + getdisplay().setCursor(x + 64, y + 48); + getdisplay().print("#" + commonData.alarm.id); + getdisplay().print(" from "); + getdisplay().print(commonData.alarm.source); + + // message, but maximum 4 lines + std::vector lines = wordwrap (commonData.alarm.message, w - 16 - 8 / 8); + int n = 0; + for (const auto& l : lines) { + getdisplay().setCursor(x + 16, y + 80 + n); + getdisplay().print(l); + n += 16; + if (n > 64) { + break; + } + } + drawTextCenter(x + w / 2, y + h - 16, "Press button 1 to dismiss alarm"); +} + // Sunset und sunrise calculation SunData calcSunsetSunrise(double time, double date, double latitude, double longitude, float timezone){ SunData returnset; diff --git a/lib/obp60task/OBP60Extensions.h b/lib/obp60task/OBP60Extensions.h index 3b4702a..84ad7d9 100644 --- a/lib/obp60task/OBP60Extensions.h +++ b/lib/obp60task/OBP60Extensions.h @@ -67,6 +67,11 @@ GxEPD2_BW & getdisplay(); GxEPD2_BW & getdisplay(); #endif +// Page display return values +#define PAGE_OK 0 // all ok, do nothing +#define PAGE_UPDATE 1 // page wants display to update +#define PAGE_HIBERNATE 2 // page wants displey to hibernate + struct Point { double x; double y; @@ -107,6 +112,7 @@ void displayTrendLow(int16_t x, int16_t y, uint16_t size, uint16_t color); void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatValue *time, GwApi::BoatValue *hdop); // Draw display header void displayFooter(CommonData &commonData); +void displayAlarm(CommonData &commonData); SunData calcSunsetSunrise(double time, double date, double latitude, double longitude, float timezone); // Calulate sunset and sunrise SunData calcSunsetSunriseRTC(struct tm *rtctime, double latitude, double longitude, float timezone); @@ -152,12 +158,12 @@ static unsigned char fram_bits[] PROGMEM = { 0xff, 0xff, 0xf8, 0x1f, 0xf8, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x1f, 0xf8, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x1f }; -static unsigned char ap_bits[] = { +static unsigned char ap_bits[] PROGMEM = { 0xe0, 0x03, 0x18, 0x0c, 0x04, 0x10, 0xc2, 0x21, 0x30, 0x06, 0x08, 0x08, 0xc0, 0x01, 0x20, 0x02, 0x00, 0x00, 0x80, 0x00, 0xc0, 0x01, 0xc0, 0x01, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00 }; -static unsigned char dish_bits[] PROGMEM= { +static unsigned char dish_bits[] PROGMEM = { 0x3c, 0x00, 0x42, 0x18, 0xfa, 0x1b, 0x02, 0x04, 0x02, 0x0a, 0x02, 0x09, 0x82, 0x08, 0x06, 0x0a, 0x0e, 0x1b, 0x9c, 0x2b, 0x38, 0x2b, 0x74, 0x20, 0xec, 0x1f, 0x1c, 0x00, 0xf4, 0x00, 0xfe, 0x03 }; diff --git a/lib/obp60task/PageBME280.cpp b/lib/obp60task/PageBME280.cpp index 84fa030..540d5c5 100644 --- a/lib/obp60task/PageBME280.cpp +++ b/lib/obp60task/PageBME280.cpp @@ -20,7 +20,7 @@ class PageBME280 : public Page return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -176,9 +176,7 @@ class PageBME280 : public Page // Show bus data getdisplay().print(svalue3); // Real value as formated string - // Update display - getdisplay().nextPage(); // Partial update (fast) - + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageBattery.cpp b/lib/obp60task/PageBattery.cpp index e3304b5..0938b13 100644 --- a/lib/obp60task/PageBattery.cpp +++ b/lib/obp60task/PageBattery.cpp @@ -34,7 +34,7 @@ class PageBattery : public Page return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -288,9 +288,7 @@ class PageBattery : public Page getdisplay().print("---"); // No sensor data (sensor is off) } - // Update display - getdisplay().nextPage(); // Partial update (fast) - + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageBattery2.cpp b/lib/obp60task/PageBattery2.cpp index c4497ef..b0b712b 100644 --- a/lib/obp60task/PageBattery2.cpp +++ b/lib/obp60task/PageBattery2.cpp @@ -44,7 +44,7 @@ public: return key; } - virtual void displayPage(PageData &pageData) + int displayPage(PageData &pageData) { GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -334,8 +334,7 @@ public: getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("W"); - // Update display - getdisplay().nextPage(); // Partial update (fast) + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageClock.cpp b/lib/obp60task/PageClock.cpp index 7a293b2..b567d1d 100644 --- a/lib/obp60task/PageClock.cpp +++ b/lib/obp60task/PageClock.cpp @@ -85,7 +85,7 @@ bool homevalid = false; // homelat and homelon are valid return key; } - virtual void displayPage(PageData &pageData) + int displayPage(PageData &pageData) { GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -162,7 +162,7 @@ bool homevalid = false; // homelat and homelon are valid } // Logging boat values - if (bvalue1 == NULL) return; + if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? LOG_DEBUG(GwLog::LOG,"Drawing at PageClock, %s:%f, %s:%f", name1.c_str(), value1, name2.c_str(), value2); // Draw page @@ -438,9 +438,7 @@ bool homevalid = false; // homelat and homelon are valid getdisplay().fillCircle(200, 150, startwidth + 6, commonData->bgcolor); getdisplay().fillCircle(200, 150, startwidth + 4, commonData->fgcolor); - // Update display - getdisplay().nextPage(); // Partial update (fast) - + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageCompass.cpp b/lib/obp60task/PageCompass.cpp index 202d8d9..783e8cd 100644 --- a/lib/obp60task/PageCompass.cpp +++ b/lib/obp60task/PageCompass.cpp @@ -61,7 +61,7 @@ class PageCompass : public Page return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -104,7 +104,7 @@ class PageCompass : public Page setFlashLED(false); } - if (bvalue == NULL) return; + if (bvalue == NULL) return PAGE_OK; // WTF why this statement? //*********************************************************** @@ -235,12 +235,11 @@ class PageCompass : public Page // if ( x_test > 390) // x_test = 320; - // Update display - getdisplay().nextPage(); // Partial update (fast) - - }; - + return PAGE_UPDATE; }; + +}; + static Page *createPage(CommonData &common){ return new PageCompass(common); }/** diff --git a/lib/obp60task/PageDST810.cpp b/lib/obp60task/PageDST810.cpp index 5eb1452..2ac7494 100644 --- a/lib/obp60task/PageDST810.cpp +++ b/lib/obp60task/PageDST810.cpp @@ -20,7 +20,7 @@ public: return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -84,7 +84,7 @@ public: } // Logging boat values - if (bvalue1 == NULL) return; + if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? LOG_DEBUG(GwLog::LOG,"Drawing at PageDST810, %s: %f, %s: %f, %s: %f, %s: %f", name1.c_str(), value1, name2.c_str(), value2, name3.c_str(), value3, name4.c_str(), value4); // Draw page @@ -242,9 +242,7 @@ public: unit4old = unit4; // Save the old unit } - // Update display - getdisplay().nextPage(); // Partial update (fast) - + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageFluid.cpp b/lib/obp60task/PageFluid.cpp index 51ce120..f844d87 100644 --- a/lib/obp60task/PageFluid.cpp +++ b/lib/obp60task/PageFluid.cpp @@ -98,7 +98,7 @@ class PageFluid : public Page commonData->logger->logDebug(GwLog::LOG,"New PageFluid: fluidtype=%d", fluidtype); } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -252,9 +252,7 @@ class PageFluid : public Page getdisplay().fillCircle(c.x, c.y, 6, commonData->bgcolor); } - // Update display - getdisplay().nextPage(); // Partial update (fast) - + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageFourValues.cpp b/lib/obp60task/PageFourValues.cpp index d931f20..53120cc 100644 --- a/lib/obp60task/PageFourValues.cpp +++ b/lib/obp60task/PageFourValues.cpp @@ -21,7 +21,7 @@ class PageFourValues : public Page return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -89,7 +89,7 @@ class PageFourValues : public Page } // Logging boat values - if (bvalue1 == NULL) return; + if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? LOG_DEBUG(GwLog::LOG,"Drawing at PageFourValues, %s: %f, %s: %f, %s: %f, %s: %f", name1.c_str(), value1, name2.c_str(), value2, name3.c_str(), value3, name4.c_str(), value4); // Draw page @@ -287,9 +287,7 @@ class PageFourValues : public Page unit4old = unit4; // Save the old unit } - // Update display - getdisplay().nextPage(); // Partial update (fast) - + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageFourValues2.cpp b/lib/obp60task/PageFourValues2.cpp index db1fba0..e608409 100644 --- a/lib/obp60task/PageFourValues2.cpp +++ b/lib/obp60task/PageFourValues2.cpp @@ -21,7 +21,7 @@ class PageFourValues2 : public Page return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -89,7 +89,7 @@ class PageFourValues2 : public Page } // Logging boat values - if (bvalue1 == NULL) return; + if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? LOG_DEBUG(GwLog::LOG,"Drawing at PageFourValues2, %s: %f, %s: %f, %s: %f, %s: %f", name1.c_str(), value1, name2.c_str(), value2, name3.c_str(), value3, name4.c_str(), value4); // Draw page @@ -287,9 +287,7 @@ class PageFourValues2 : public Page unit4old = unit4; // Save the old unit } - // Update display - getdisplay().nextPage(); // Partial update (fast) - + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageGenerator.cpp b/lib/obp60task/PageGenerator.cpp index 276e4b0..201b647 100644 --- a/lib/obp60task/PageGenerator.cpp +++ b/lib/obp60task/PageGenerator.cpp @@ -20,7 +20,7 @@ public: return key; } - virtual void displayPage(PageData &pageData) + int displayPage(PageData &pageData) { GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -203,8 +203,7 @@ public: getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("W"); - // Update display - getdisplay().nextPage(); // Partial update (fast) + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageKeelPosition.cpp b/lib/obp60task/PageKeelPosition.cpp index 5a25866..48e5018 100644 --- a/lib/obp60task/PageKeelPosition.cpp +++ b/lib/obp60task/PageKeelPosition.cpp @@ -21,7 +21,7 @@ public: return key; } - virtual void displayPage(PageData &pageData) + int displayPage(PageData &pageData) { GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -206,9 +206,7 @@ public: getdisplay().print("No sensor data"); // Info missing sensor } - // Update display - getdisplay().nextPage(); // Partial update (fast) - + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageOneValue.cpp b/lib/obp60task/PageOneValue.cpp index ebdb96e..6f33597 100644 --- a/lib/obp60task/PageOneValue.cpp +++ b/lib/obp60task/PageOneValue.cpp @@ -21,7 +21,7 @@ class PageOneValue : public Page return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -53,7 +53,7 @@ class PageOneValue : public Page } // Logging boat values - if (bvalue1 == NULL) return; + if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? LOG_DEBUG(GwLog::LOG,"Drawing at PageOneValue, %s: %f", name1.c_str(), value1); // Draw page @@ -104,9 +104,7 @@ class PageOneValue : public Page unit1old = unit1; // Save the old unit } - // Update display - getdisplay().nextPage(); // Partial update (fast) - + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageRollPitch.cpp b/lib/obp60task/PageRollPitch.cpp index 488056d..db3d27f 100644 --- a/lib/obp60task/PageRollPitch.cpp +++ b/lib/obp60task/PageRollPitch.cpp @@ -21,7 +21,7 @@ public: return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -109,7 +109,7 @@ public: } // Logging boat values - if (bvalue1 == NULL) return; + if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? LOG_DEBUG(GwLog::LOG,"Drawing at PageRollPitch, %s:%f, %s:%f", name1.c_str(), value1, name2.c_str(), value2); // Draw page @@ -305,9 +305,7 @@ public: getdisplay().print("No sensor data"); // Info missing sensor } - // Update display - getdisplay().nextPage(); // Partial update (fast) - + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageRudderPosition.cpp b/lib/obp60task/PageRudderPosition.cpp index a11f917..22b5f91 100644 --- a/lib/obp60task/PageRudderPosition.cpp +++ b/lib/obp60task/PageRudderPosition.cpp @@ -22,7 +22,7 @@ public: return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -67,7 +67,7 @@ public: } // Logging boat values - if (bvalue1 == NULL) return; + if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? LOG_DEBUG(GwLog::LOG,"Drawing at PageRudderPosition, %s:%f", name1.c_str(), value1); // Draw page @@ -207,8 +207,7 @@ public: getdisplay().fillCircle(200, 150, startwidth + 6, commonData->bgcolor); getdisplay().fillCircle(200, 150, startwidth + 4, commonData->fgcolor); - // Update display - getdisplay().nextPage(); // Partial update (fast) + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageSixValues.cpp b/lib/obp60task/PageSixValues.cpp index fc42ad9..af735f2 100644 --- a/lib/obp60task/PageSixValues.cpp +++ b/lib/obp60task/PageSixValues.cpp @@ -29,7 +29,7 @@ class PageSixValues : public Page return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -71,7 +71,7 @@ class PageSixValues : public Page setFlashLED(false); } - if (bvalue == NULL) return; + if (bvalue == NULL) return PAGE_OK; // WTF why this statement? // Draw page //*********************************************************** @@ -149,9 +149,7 @@ class PageSixValues : public Page getdisplay().fillRect(SixValues_x1+SixValues_DeltaX-8, SixValues_y1+i*SixValues_DeltaY, 3, SixValues_DeltaY, commonData->fgcolor); } - // Update display - getdisplay().nextPage(); // Partial update (fast) - + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageSolar.cpp b/lib/obp60task/PageSolar.cpp index 1962b66..2a19bb9 100644 --- a/lib/obp60task/PageSolar.cpp +++ b/lib/obp60task/PageSolar.cpp @@ -20,7 +20,7 @@ public: return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -199,8 +199,7 @@ public: getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("W"); - // Update display - getdisplay().nextPage(); // Partial update (fast) + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageSystem.cpp b/lib/obp60task/PageSystem.cpp index 7cb41f5..dd93aec 100644 --- a/lib/obp60task/PageSystem.cpp +++ b/lib/obp60task/PageSystem.cpp @@ -159,7 +159,7 @@ public: } } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -380,7 +380,7 @@ public: // Update display getdisplay().nextPage(); // Partial update (fast) - + return PAGE_OK; }; }; diff --git a/lib/obp60task/PageThreeValues.cpp b/lib/obp60task/PageThreeValues.cpp index d2131b7..3bd2d0b 100644 --- a/lib/obp60task/PageThreeValues.cpp +++ b/lib/obp60task/PageThreeValues.cpp @@ -21,7 +21,7 @@ class PageThreeValues : public Page return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -77,7 +77,7 @@ class PageThreeValues : public Page } // Logging boat values - if (bvalue1 == NULL) return; + if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? LOG_DEBUG(GwLog::LOG,"Drawing at PageThreeValues, %s: %f, %s: %f, %s: %f", name1.c_str(), value1, name2.c_str(), value2, name3.c_str(), value3); // Draw page @@ -226,8 +226,7 @@ class PageThreeValues : public Page unit3old = unit3; // Save the old unit } - // Update display - getdisplay().nextPage(); // Partial update (fast) + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageTwoValues.cpp b/lib/obp60task/PageTwoValues.cpp index 2859fd2..8b27e7b 100644 --- a/lib/obp60task/PageTwoValues.cpp +++ b/lib/obp60task/PageTwoValues.cpp @@ -21,7 +21,7 @@ class PageTwoValues : public Page return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -65,7 +65,7 @@ class PageTwoValues : public Page } // Logging boat values - if (bvalue1 == NULL) return; + if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? LOG_DEBUG(GwLog::LOG,"Drawing at PageTwoValues, %s: %f, %s: %f", name1.c_str(), value1, name2.c_str(), value2); // Draw page @@ -166,8 +166,7 @@ class PageTwoValues : public Page unit2old = unit2; // Save the old unit } - // Update display - getdisplay().nextPage(); // Partial update (fast) + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageVoltage.cpp b/lib/obp60task/PageVoltage.cpp index cfd784e..3c2693b 100644 --- a/lib/obp60task/PageVoltage.cpp +++ b/lib/obp60task/PageVoltage.cpp @@ -100,7 +100,7 @@ public: getdisplay().fillRect(x + 16, y + 11, 6, 3, color); } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -383,8 +383,7 @@ public: } - // Update display - getdisplay().nextPage(); // Partial update (fast) + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageWhite.cpp b/lib/obp60task/PageWhite.cpp index e40a3ac..ada2616 100644 --- a/lib/obp60task/PageWhite.cpp +++ b/lib/obp60task/PageWhite.cpp @@ -31,7 +31,7 @@ public: return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -67,10 +67,13 @@ public: } // Update display - getdisplay().nextPage(); + // getdisplay().nextPage(); + int ret = PAGE_UPDATE; if (mode == 'W') { - getdisplay().hibernate(); + //getdisplay().hibernate(); + ret |= PAGE_HIBERNATE; } + return ret; }; }; diff --git a/lib/obp60task/PageWind.cpp b/lib/obp60task/PageWind.cpp index 0a94857..0b11461 100644 --- a/lib/obp60task/PageWind.cpp +++ b/lib/obp60task/PageWind.cpp @@ -296,7 +296,7 @@ public: return key; } - virtual void displayPage(PageData &pageData) + int displayPage(PageData &pageData) { GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -354,7 +354,7 @@ public: } // Logging boat values - if (bvalue1 == NULL) return; + if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? LOG_DEBUG(GwLog::LOG,"Drawing at PageWind, %s:%f, %s:%f", name1.c_str(), value1, name2.c_str(), value2); // Draw page @@ -618,9 +618,7 @@ public: } - // Update display - getdisplay().nextPage(); // Partial update (fast) - + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageWindRose.cpp b/lib/obp60task/PageWindRose.cpp index 9b1c203..45c62ce 100644 --- a/lib/obp60task/PageWindRose.cpp +++ b/lib/obp60task/PageWindRose.cpp @@ -24,7 +24,7 @@ public: return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -140,7 +140,7 @@ public: } // Logging boat values - if (bvalue1 == NULL) return; + if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? LOG_DEBUG(GwLog::LOG,"Drawing at PageWindRose, %s:%f, %s:%f, %s:%f, %s:%f, %s:%f, %s:%f", name1.c_str(), value1, name2.c_str(), value2, name3.c_str(), value3, name4.c_str(), value4, name5.c_str(), value5, name6.c_str(), value6); // Draw page @@ -357,8 +357,7 @@ public: getdisplay().print(unit6old); // Unit } - // Update display - getdisplay().nextPage(); // Partial update (fast) + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageWindRoseFlex.cpp b/lib/obp60task/PageWindRoseFlex.cpp index bee86fe..f0e21ab 100644 --- a/lib/obp60task/PageWindRoseFlex.cpp +++ b/lib/obp60task/PageWindRoseFlex.cpp @@ -24,7 +24,7 @@ public: return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -140,7 +140,7 @@ public: } // Logging boat values - if (bvalue1 == NULL) return; + if (bvalue1 == NULL) return PAGE_OK; // WTF why this statement? LOG_DEBUG(GwLog::LOG,"Drawing at PageWindRoseFlex, %s:%f, %s:%f, %s:%f, %s:%f, %s:%f, %s:%f", name1.c_str(), value1, name2.c_str(), value2, name3.c_str(), value3, name4.c_str(), value4, name5.c_str(), value5, name6.c_str(), value6); // Draw page @@ -362,8 +362,7 @@ if ( cos(value1) > 0){ } - // Update display - getdisplay().nextPage(); // Partial update (fast) + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/PageXTETrack.cpp b/lib/obp60task/PageXTETrack.cpp index 5b0bdbb..cbb0af5 100644 --- a/lib/obp60task/PageXTETrack.cpp +++ b/lib/obp60task/PageXTETrack.cpp @@ -65,7 +65,7 @@ class PageXTETrack : public Page return key; } - virtual void displayPage(PageData &pageData){ + int displayPage(PageData &pageData){ GwConfigHandler *config = commonData->config; GwLog *logger = commonData->logger; @@ -207,9 +207,7 @@ class PageXTETrack : public Page drawSegment(399, 100, 318, 24, 289, 24, 350, 100, commonData->fgcolor, seg[4]); drawSegment(399, 54, 354, 24, 325, 24, 399, 90, commonData->fgcolor, seg[5]); - // Update display - getdisplay().nextPage(); // Partial update (fast) - + return PAGE_UPDATE; }; }; diff --git a/lib/obp60task/Pagedata.h b/lib/obp60task/Pagedata.h index 7387b28..9177fff 100644 --- a/lib/obp60task/Pagedata.h +++ b/lib/obp60task/Pagedata.h @@ -78,6 +78,22 @@ typedef struct{ bool on; // fast on/off detector } BacklightData; +enum AlarmSource { + Alarm_Generic, + Alarm_Local, + Alarm_NMEA0183, + Alarm_NMEA2000 +}; + +typedef struct{ + uint8_t id; // alarm-id e.g. 01..99 from NMEA0183 + AlarmSource source; + String message; // single line of plain text + bool active = false; + uint8_t signal; // how to signal MESSAGE | LED | BUZZER + uint8_t length_sec; // seconds until alarm disappeares without user interaction +} AlarmData; + typedef struct{ GwApi::Status status; GwLog *logger=NULL; @@ -86,6 +102,7 @@ typedef struct{ SunData sundata; TouchKeyData keydata[6]; BacklightData backlight; + AlarmData alarm; GwApi::BoatValue *time=NULL; GwApi::BoatValue *date=NULL; uint16_t fgcolor; @@ -100,7 +117,7 @@ class Page{ CommonData *commonData; public: int refreshtime = 1000; - virtual void displayPage(PageData &pageData)=0; + virtual int displayPage(PageData &pageData)=0; virtual void displayNew(PageData &pageData){} virtual void setupKeys() { #ifdef HARDWARE_V21 diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index 9301e1a..4055fcf 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -845,7 +845,16 @@ void OBP60Task(GwApi *api){ if (pages[pageNumber].description && pages[pageNumber].description->header){ displayFooter(commonData); } - currentPage->displayPage(pages[pageNumber].parameters); + int ret = currentPage->displayPage(pages[pageNumber].parameters); + if (commonData.alarm.active) { + displayAlarm(commonData); + } + if (ret & PAGE_UPDATE) { + getdisplay().nextPage(); // Partial update (fast) + } + if (ret & PAGE_HIBERNATE) { + getdisplay().hibernate(); + } } }