From d3e7aae21a923899a2bcb3942640656b0ef8cb68 Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Sun, 27 Feb 2022 17:20:53 +0100 Subject: [PATCH] Sample page apparent wind --- lib/obp60task/OBP60Formater.cpp | 4 +- lib/obp60task/OBP60Keypad.h | 8 +- lib/obp60task/PageApparentWind.cpp | 195 ++++++++++++++++++++++++----- lib/obp60task/PageOneValue.cpp | 32 +++-- lib/obp60task/PageVoltage.cpp | 22 ++-- lib/obp60task/Pagedata.h | 1 - lib/obp60task/obp60task.cpp | 16 +-- 7 files changed, 211 insertions(+), 67 deletions(-) diff --git a/lib/obp60task/OBP60Formater.cpp b/lib/obp60task/OBP60Formater.cpp index 70de333..02449a2 100644 --- a/lib/obp60task/OBP60Formater.cpp +++ b/lib/obp60task/OBP60Formater.cpp @@ -97,7 +97,7 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){ result.unit = ""; } //######################################################## - else if (value->getFormat() == "formatCourse"){ + else if (value->getFormat() == "formatCourse" || value->getFormat() == "formatWind"){ double course = 0; if(usesimudata == false) { course = value->value; @@ -118,7 +118,7 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){ result.unit = "Deg"; } //######################################################## - else if (value->getFormat() == "formatKnots" || value->getFormat() == "formatWind"){ + else if (value->getFormat() == "formatKnots"){ double speed = 0; if(usesimudata == false) { speed = value->value; diff --git a/lib/obp60task/OBP60Keypad.h b/lib/obp60task/OBP60Keypad.h index a64bc9c..2079dc5 100644 --- a/lib/obp60task/OBP60Keypad.h +++ b/lib/obp60task/OBP60Keypad.h @@ -101,14 +101,8 @@ int readKeypad() { buzzer(TONE4, 1000); keylock = false; delay(keydelay); - keyoff = !keyoff; - if(keyoff == true){ - keystatus = 11; - } - else{ - keystatus = 0; - } + keystatus = 11; } // Detect swipe right diff --git a/lib/obp60task/PageApparentWind.cpp b/lib/obp60task/PageApparentWind.cpp index cc465d8..27f6394 100644 --- a/lib/obp60task/PageApparentWind.cpp +++ b/lib/obp60task/PageApparentWind.cpp @@ -3,42 +3,181 @@ class PageApparentWind : public Page { - int dummy=0; //an example on how you would maintain some status - //for a page +bool keylock = false; // Keylock +int16_t lp = 80; // Pointer length + public: PageApparentWind(CommonData &common){ - common.logger->logDebug(GwLog::LOG,"created PageApparentWind"); - dummy=1; + common.logger->logDebug(GwLog::LOG,"Show PageApparentWind"); } + + // Key functions virtual int handleKey(int key){ - if(key == 3){ - dummy++; - return 0; // Commit the key + // Reduce instrument size + if(key == 2){ // Code for reduce + lp = lp - 10; + if(lp < 10){ + lp = 10; + } + return 0; // Commit the key + } + + // Enlarge instrument size + if(key == 5){ // Code for enlarge + lp = lp + 10; + if(lp > 80){ + lp = 80; + } + return 0; // Commit the key + } + + // Keylock function + if(key == 11){ // Code for keylock + keylock = !keylock; // Toggle keylock + return 0; // Commit the key } return key; } virtual void displayPage(CommonData &commonData, PageData &pageData) { - GwLog *logger = commonData.logger; - GwConfigHandler *config = commonData.config; - String test = config->getString(config->lengthFormat); - - display.setFont(&Ubuntu_Bold8pt7b); + GwLog *logger=commonData.logger; - dummy++; - for (int i = 0; i < 2; i++) - { - GwApi::BoatValue *value = pageData.values[i]; - if (value == NULL) - continue; - LOG_DEBUG(GwLog::LOG, "drawing at PageApparentWind(%d),dummy=%d, p=%s,v=%f", - i, - dummy, - value->getName().c_str(), - value->valid ? value->value : -1.0); + static String svalue1old = ""; + static String unit1old = ""; + static String svalue2old = ""; + static String unit2old = ""; + + // Get config data + String lengthformat = config->getString(config->lengthFormat); + bool simulation = config->getBool(config->useSimuData); + String displaycolor = config->getString(config->displaycolor); + bool holdvalues = config->getBool(config->holdvalues); + String flashLED = config->getString(config->flashLED); + String backlightMode = config->getString(config->backlight); + + // Get boat values for AWS + GwApi::BoatValue *bvalue1 = pageData.values[0]; // First element in list (only one value by PageOneValue) + String name1 = bvalue1->getName().c_str(); // Value name + name1 = name1.substring(0, 6); // String length limit for value name + double value1 = bvalue1->value; // Value as double in SI unit + bool valid1 = bvalue1->valid; // Valid information + String svalue1 = formatValue(bvalue1, commonData).svalue; // Formatted value as string including unit conversion and switching decimal places + String unit1 = formatValue(bvalue1, commonData).unit; // Unit of value + + // Get boat values for AWD + GwApi::BoatValue *bvalue2 = pageData.values[1]; // First element in list (only one value by PageOneValue) + String name2 = bvalue2->getName().c_str(); // Value name + name2 = name2.substring(0, 6); // String length limit for value name + double value2 = bvalue2->value; // Value as double in SI unit + bool valid2 = bvalue2->valid; // Valid information + String svalue2 = formatValue(bvalue2, commonData).svalue; // Formatted value as string including unit conversion and switching decimal places + String unit2 = formatValue(bvalue2, commonData).unit; // Unit of value + + // Optical warning by limit violation (unused) + if(String(flashLED) == "Limit Violation"){ + setBlinkingLED(false); + setPortPin(OBP_FLASH_LED, false); } + + // Logging boat values + if (bvalue1 == NULL) return; + LOG_DEBUG(GwLog::LOG,"Drawing at PageApparentWind, %s:%f, %s:%f", name1, value1, name2, value2); + + // Draw page + //*********************************************************** + + // Set background color and text color + int textcolor = GxEPD_BLACK; + int pixelcolor = GxEPD_BLACK; + int bgcolor = GxEPD_WHITE; + if(displaycolor == "Normal"){ + textcolor = GxEPD_BLACK; + pixelcolor = GxEPD_BLACK; + bgcolor = GxEPD_WHITE; + } + else{ + textcolor = GxEPD_WHITE; + pixelcolor = GxEPD_WHITE; + bgcolor = GxEPD_BLACK; + } + // Clear display by call in obp60task.cpp in main loop + + // Show values AWS + display.setFont(&Ubuntu_Bold20pt7b); + display.setCursor(20, 50); + if(holdvalues == false){ + display.print(name1); // Value name + display.print(": "); + display.print(svalue1); // Value + display.print(" "); + display.print(unit1); // Unit + } + else{ + display.print(name1); // Value name + display.print(": "); + display.print(svalue1old); // Value old + display.print(" "); + display.print(unit1old); // Unit old + } + + // Show values AWD + display.setFont(&Ubuntu_Bold20pt7b); + display.setCursor(20, 260); + if(holdvalues == false){ + display.print(name2); // Value name + display.print(": "); + display.print(svalue2); // Value + display.print(" "); + display.print(unit2); // Unit + } + else{ + display.print(name2); // Value name + display.print(": "); + display.print(svalue2old); // Value old + display.print(" "); + display.print(unit2old); // Unit old + } + + // Draw wind pointer + static int16_t x0 = 200; // Center point + static int16_t y0 = 145; + static int16_t x1 = x0; // Start point for pointer + static int16_t y1 = y0; + static int16_t x2 = x0; // End point for pointer + static int16_t y2 = y0; + + //Draw instrument + display.fillCircle(x0, y0, lp + 5, pixelcolor); // Black circle + display.fillCircle(x0, y0, lp + 1, bgcolor); // White circle + + // Calculation end point of pointer + value2 = value2 - 3.14 / 2; + x1 = x0 + cos(value2) * lp * 0.6; + y1 = y0 + sin(value2) * lp * 0.6; + x2 = x0 + cos(value2) * lp; + y2 = y0 + sin(value2) * lp; + + display.drawLine(x1, y1, x2, y2, pixelcolor); + + // Key Layout + display.setFont(&Ubuntu_Bold8pt7b); + display.setCursor(115, 290); + if(keylock == false){ + display.print(" [ <<<<<< >>>>>> ]"); + if(String(backlightMode) == "Control by Key"){ // Key for illumination + display.setCursor(343, 290); + display.print("[ILUM]"); + } + } + else{ + display.print(" [ Keylock active ]"); + } + + // Update display + display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Partial update (fast) + }; }; @@ -53,9 +192,9 @@ static Page *createPage(CommonData &common){ * and will will provide the names of the fixed values we need */ PageDescription registerPageApparentWind( - "apparentWind", - createPage, - 0, - {"AWS","AWD"}, - false + "apparentWind", // Page name + createPage, // Action + 0, // Number of bus values depends on selection in Web configuration + {"AWS","AWA"}, // Bus values we need in the page + true // Show display header on/off ); \ No newline at end of file diff --git a/lib/obp60task/PageOneValue.cpp b/lib/obp60task/PageOneValue.cpp index 064b2b3..8d0c061 100644 --- a/lib/obp60task/PageOneValue.cpp +++ b/lib/obp60task/PageOneValue.cpp @@ -2,7 +2,21 @@ #include "OBP60ExtensionPort.h" class PageOneValue : public Page{ + bool keylock = false; // Keylock + public: + PageOneValue(CommonData &common){ + common.logger->logDebug(GwLog::LOG,"Show PageOneValue"); + } + + virtual int handleKey(int key){ + if(key == 11){ // Code for keylock + keylock = !keylock; // Toggle keylock + return 0; // Commit the key + } + return key; + } + virtual void displayPage(CommonData &commonData, PageData &pageData){ GwConfigHandler *config = commonData.config; GwLog *logger=commonData.logger; @@ -85,7 +99,7 @@ class PageOneValue : public Page{ display.setCursor(20, 240); } - // Show bus data or using simulation data + // Show bus data if(holdvalues == false){ display.print(svalue1); // Real value as formated string } @@ -100,16 +114,16 @@ class PageOneValue : public Page{ // Key Layout display.setFont(&Ubuntu_Bold8pt7b); display.setCursor(115, 290); - if(commonData.keylock == false){ + if(keylock == false){ display.print(" [ <<<<<< >>>>>> ]"); + if(String(backlightMode) == "Control by Key"){ // Key for illumination + display.setCursor(343, 290); + display.print("[ILUM]"); + } } else{ display.print(" [ Keylock active ]"); } - if(String(backlightMode) == "Control by Key"){ - display.setCursor(343, 290); - display.print("[ILUM]"); - } // Update display display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Partial update (fast) @@ -117,7 +131,9 @@ class PageOneValue : public Page{ }; }; -static Page* createPage(CommonData &common){return new PageOneValue();} +static Page* createPage(CommonData &common){ + return new PageOneValue(common); +} /** * with the code below we make this page known to the PageTask @@ -127,7 +143,7 @@ static Page* createPage(CommonData &common){return new PageOneValue();} * this will be number of BoatValue pointers in pageData.values */ PageDescription registerPageOneValue( - "oneValue", // Name of page + "oneValue", // Page name createPage, // Action 1, // Number of bus values depends on selection in Web configuration true // Show display header on/off diff --git a/lib/obp60task/PageVoltage.cpp b/lib/obp60task/PageVoltage.cpp index 3fbca1b..c2eec32 100644 --- a/lib/obp60task/PageVoltage.cpp +++ b/lib/obp60task/PageVoltage.cpp @@ -3,17 +3,16 @@ class PageVoltage : public Page { - int dummy=0; //an example on how you would maintain some status - //for a page +bool keylock = false; // Keylock + public: PageVoltage(CommonData &common){ - common.logger->logDebug(GwLog::LOG,"created PageApparentWind"); - dummy=1; + common.logger->logDebug(GwLog::LOG,"Show PageVoltage"); } virtual int handleKey(int key){ - if(key == 3){ - dummy++; - return 0; // Commit the key + if(key == 11){ // Code for keylock + keylock = !keylock; // Toggle keylock + return 0; // Commit the key } return key; } @@ -117,8 +116,13 @@ public: // Key Layout display.setFont(&Ubuntu_Bold8pt7b); display.setCursor(115, 290); - display.print(" [ <<<<<< >>>>>> ]"); - if(String(backlightMode) == "Control by Key"){ + if(keylock == false){ + display.print(" [ <<<<<< >>>>>> ]"); + } + else{ + display.print(" [ Keylock active ]"); + } + if(String(backlightMode) == "Control by Key"){ // Key for illumination display.setCursor(343, 290); display.print("[ILUM]"); } diff --git a/lib/obp60task/Pagedata.h b/lib/obp60task/Pagedata.h index 89bee62..b5ebb67 100644 --- a/lib/obp60task/Pagedata.h +++ b/lib/obp60task/Pagedata.h @@ -16,7 +16,6 @@ typedef struct{ GwApi::Status status; GwLog *logger=NULL; GwConfigHandler *config=NULL; - bool keylock = false; } CommonData; //a base class that all pages must inherit from diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index 4c4aeb3..c9b2d17 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -50,14 +50,13 @@ void underVoltageDetection(){ Timer1.stop(); // Stop Timer1 setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off setPortPin(OBP_FLASH_LED, false); // Flash LED Off - buzzer(TONE4, 20); // Buzzer tone 4kHz 20% 20ms - setPortPin(OBP_POWER_50, false); // Power rail 5.0V Off setPortPin(OBP_POWER_33, false); // Power rail 3.3V Off + buzzer(TONE4, 20); // Buzzer tone 4kHz 20ms + setPortPin(OBP_POWER_50, false); // Power rail 5.0V Off // Shutdown EInk display display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE); // Draw white sreen -// display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, false); // Partial update + display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, false); // Partial update display.update(); - // display._sleep(); // Display shut dow // Stop system while(true){ esp_deep_sleep_start(); // Deep Sleep without weakup. Weakup only after power cycle (restart). @@ -483,14 +482,7 @@ void OBP60Task(GwApi *api){ display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE); // Draw white sreen display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Needs partial update before full update to refresh the frame buffer display.update(); // Full update - } - // #11 Keylock -/* - if (keyboardMessage == 11) - { - commonData.keylock = !commonData.keylock; // Toggle keylock - } -*/ + } } LOG_DEBUG(GwLog::LOG,"set pagenumber to %d",pageNumber); }