diff --git a/lib/obp60task/OBP60Extensions.cpp b/lib/obp60task/OBP60Extensions.cpp index 8c4ec27e..a98cba50 100644 --- a/lib/obp60task/OBP60Extensions.cpp +++ b/lib/obp60task/OBP60Extensions.cpp @@ -70,6 +70,9 @@ bool statusBacklightLED = false;// Actual status of flash LED on/off int uvDuration = 0; // Under voltage duration in n x 100ms +RTC_DATA_ATTR uint8_t RTC_lastpage; // Remember last page while deep sleeping + + LedTaskData *ledTaskData=nullptr; void hardwareInit(GwApi *api) @@ -118,6 +121,35 @@ void startLedTask(GwApi *api){ createSpiLedTask(ledTaskData); } +uint8_t getLastPage() { + return RTC_lastpage; +} + +#ifdef BOARD_OBP60S3 +void deepSleep(CommonData &common){ + RTC_lastpage = common.data.actpage - 1; + // Switch off all power lines + setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off + setFlashLED(false); // Flash LED Off + buzzer(TONE4, 20); // Buzzer tone 4kHz 20ms + // Shutdown EInk display + getdisplay().setFullWindow(); // Set full Refresh + getdisplay().fillScreen(common.bgcolor); // Clear screen + getdisplay().setTextColor(common.fgcolor); + getdisplay().setFont(&Ubuntu_Bold20pt7b); + getdisplay().setCursor(85, 150); + getdisplay().print("Sleep Mode"); + getdisplay().setFont(&Ubuntu_Bold8pt7b); + getdisplay().setCursor(65, 175); + getdisplay().print("For wakeup press key and wait 5s"); + getdisplay().nextPage(); // Update display contents + getdisplay().powerOff(); // Display power off + setPortPin(OBP_POWER_50, false); // Power off ePaper display + // Stop system + esp_deep_sleep_start(); // Deep Sleep with weakup via GPIO pin +} +#endif + // Valid colors see hue Color colorMapping(const String &colorString){ Color color = COLOR_RED; diff --git a/lib/obp60task/OBP60Extensions.h b/lib/obp60task/OBP60Extensions.h index fa80cc99..727f9122 100644 --- a/lib/obp60task/OBP60Extensions.h +++ b/lib/obp60task/OBP60Extensions.h @@ -64,6 +64,12 @@ Point rotatePoint(const Point& origin, const Point& p, double angle); std::vector rotatePoints(const Point& origin, const std::vector& pts, double angle); void fillPoly4(const std::vector& p4, uint16_t color); +#ifdef BOARD_OBP60S3 +void deepSleep(CommonData &common); +#endif + +uint8_t getLastPage(); + void hardwareInit(GwApi *api); void setPortPin(uint pin, bool value); // Set port pin for extension port diff --git a/lib/obp60task/PageBME280.cpp b/lib/obp60task/PageBME280.cpp index d731005c..9bf0df2c 100644 --- a/lib/obp60task/PageBME280.cpp +++ b/lib/obp60task/PageBME280.cpp @@ -48,7 +48,7 @@ class PageBME280 : public Page value1 = 23.0 + float(random(0, 10)) / 10.0; } // Display data when sensor activated - if((String(useenvsensor) == "BME280") or (String(useenvsensor) == "BMP280")){ + if((useenvsensor == "BME280") or (useenvsensor == "BMP280") or (useenvsensor == "BMP180")){ svalue1 = String(value1, 1); // Formatted value as string including unit conversion and switching decimal places } else{ @@ -66,7 +66,7 @@ class PageBME280 : public Page value2 = 43 + float(random(0, 4)); } // Display data when sensor activated - if(String(useenvsensor) == "BME280"){ + if(useenvsensor == "BME280"){ svalue2 = String(value2, 0); // Formatted value as string including unit conversion and switching decimal places } else{ @@ -84,7 +84,7 @@ class PageBME280 : public Page value3 = 1006 + float(random(0, 5)); } // Display data when sensor activated - if((String(useenvsensor) == "BME280") or (String(useenvsensor) == "BMP280")){ + if((useenvsensor == "BME280") or (useenvsensor == "BMP280") or (useenvsensor == "BMP180")){ svalue3 = String(value3 / 100, 1); // Formatted value as string including unit conversion and switching decimal places } else{ diff --git a/lib/obp60task/PageSystem.cpp b/lib/obp60task/PageSystem.cpp index 7beb13d2..64b08d70 100644 --- a/lib/obp60task/PageSystem.cpp +++ b/lib/obp60task/PageSystem.cpp @@ -48,7 +48,7 @@ char mode = 'N'; // (N)ormal, (D)evice list commonData->keydata[0].label = "EXIT"; commonData->keydata[1].label = "MODE"; commonData->keydata[2].label = ""; - commonData->keydata[3].label = ""; + commonData->keydata[3].label = "RST"; commonData->keydata[4].label = "STBY"; commonData->keydata[5].label = "ILUM"; } @@ -67,9 +67,17 @@ char mode = 'N'; // (N)ormal, (D)evice list return 0; } // grab cursor keys to disable page navigation - if (key == 3 or key == 4) { + if (key == 3) { return 0; } + // soft reset + if (key == 4) { + ESP.restart(); + } + // standby / deep sleep + if (key == 5) { + deepSleep(*commonData); + } // Code for keylock if (key == 11) { commonData->keylock = !commonData->keylock; @@ -133,11 +141,25 @@ char mode = 'N'; // (N)ormal, (D)evice list getdisplay().setCursor(120, y0 + 16); getdisplay().print(env_module); + // total RAM free + int Heap_free = esp_get_free_heap_size(); + getdisplay().setCursor(202, y0 + 16); + getdisplay().print("Total free:"); + getdisplay().setCursor(300, y0 + 16); + getdisplay().print(String(Heap_free)); + getdisplay().setCursor(2, y0 + 32); getdisplay().print("Buzzer:"); getdisplay().setCursor(120, y0 + 32); getdisplay().print(buzzer_mode); + // RAM free for task + int RAM_free = uxTaskGetStackHighWaterMark(NULL); + getdisplay().setCursor(202, y0 + 32); + getdisplay().print("Task free:"); + getdisplay().setCursor(300, y0 + 32); + getdisplay().print(String(RAM_free)); + getdisplay().setCursor(2, y0 + 48); getdisplay().print("CPU speed:"); getdisplay().setCursor(120, y0 + 48); @@ -146,11 +168,6 @@ char mode = 'N'; // (N)ormal, (D)evice list int cpu_freq = esp_clk_cpu_freq() / 1000000; getdisplay().print(String(cpu_freq)); - getdisplay().setCursor(2, y0 + 64); - getdisplay().print("RTC:"); - getdisplay().setCursor(120, y0 + 64); - getdisplay().print(rtc_module); - getdisplay().setCursor(202, y0 + 64); getdisplay().print("GPS:"); getdisplay().setCursor(300, y0 + 64); @@ -161,6 +178,11 @@ char mode = 'N'; // (N)ormal, (D)evice list getdisplay().setCursor(120, y0 + 80); getdisplay().print(hasFRAM ? "available" : "not found"); + getdisplay().setCursor(202, y0 + 80); + getdisplay().print("RTC:"); + getdisplay().setCursor(300, y0 + 80); + getdisplay().print(rtc_module); + getdisplay().setCursor(2, y0 + 120); getdisplay().print("Firmware Version: "); getdisplay().print(VERSINFO); diff --git a/lib/obp60task/PageWhite.cpp b/lib/obp60task/PageWhite.cpp index a2b6737f..e40a3aca 100644 --- a/lib/obp60task/PageWhite.cpp +++ b/lib/obp60task/PageWhite.cpp @@ -13,6 +13,7 @@ char mode = 'W'; // display mode (W)hite | (L)ogo | (M)FD logo PageWhite(CommonData &common){ commonData = &common; common.logger->logDebug(GwLog::LOG,"Instantiate PageWhite"); + refreshtime = 15000; } virtual int handleKey(int key) { @@ -53,7 +54,11 @@ char mode = 'W'; // display mode (W)hite | (L)ogo | (M)FD logo int bgcolor = GxEPD_WHITE; // Set display in partial refresh mode - getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update + if (mode == 'W') { + getdisplay().setFullWindow(); + } else { + getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update + } if (mode == 'L') { getdisplay().drawBitmap(0, 0, gImage_Logo_OBP_400x300_sw, getdisplay().width(), getdisplay().height(), commonData->fgcolor); @@ -62,7 +67,10 @@ char mode = 'W'; // display mode (W)hite | (L)ogo | (M)FD logo } // Update display - getdisplay().nextPage(); // Partial update (fast) + getdisplay().nextPage(); + if (mode == 'W') { + getdisplay().hibernate(); + } }; }; diff --git a/lib/obp60task/Pagedata.h b/lib/obp60task/Pagedata.h index cc4c45b8..b385b5cf 100644 --- a/lib/obp60task/Pagedata.h +++ b/lib/obp60task/Pagedata.h @@ -100,6 +100,7 @@ class Page{ protected: CommonData *commonData; public: + int refreshtime = 1000; virtual void displayPage(PageData &pageData)=0; virtual void displayNew(PageData &pageData){} virtual void setupKeys() { diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index b2cbe2ee..3defb2bf 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -117,6 +117,16 @@ void OBP60Init(GwApi *api){ } #endif + #ifdef BOARD_OBP60S3 + touchSleepWakeUpEnable(TP1, 45); + touchSleepWakeUpEnable(TP2, 45); + touchSleepWakeUpEnable(TP3, 45); + touchSleepWakeUpEnable(TP4, 45); + touchSleepWakeUpEnable(TP5, 45); + touchSleepWakeUpEnable(TP6, 45); + esp_sleep_enable_touchpad_wakeup(); + #endif + // Get CPU speed int freq = getCpuFrequencyMhz(); api->getLogger()->logDebug(GwLog::LOG,"CPU speed at boot: %i MHz", freq); @@ -356,6 +366,8 @@ void deepSleep(CommonData &common){ } #endif + + // OBP60 Task //#################################################################################### void OBP60Task(GwApi *api){ @@ -440,6 +452,18 @@ void OBP60Task(GwApi *api){ PageStruct pages[MAX_PAGE_NUMBER]; // Set start page int pageNumber = int(api->getConfig()->getConfigItem(api->getConfig()->startPage,true)->asInt()) - 1; + +#ifdef BOARD_OBP60S3 + LOG_DEBUG(GwLog::LOG,"Checking wakeup..."); + if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TOUCHPAD) { + LOG_DEBUG(GwLog::LOG,"Wake up by touch pad %d",esp_sleep_get_touchpad_wakeup_status()); + pageNumber = getLastPage(); + } else { + LOG_DEBUG(GwLog::LOG,"Other wakeup reason"); + } + LOG_DEBUG(GwLog::LOG,"...done"); +#endif + int lastPage=pageNumber; BoatValueList boatValues; //all the boat values for the api query @@ -550,8 +574,10 @@ void OBP60Task(GwApi *api){ //#################################################################################### bool systemPage = false; + Page *currentPage; while (true){ delay(100); // Delay 100ms (loop time) + bool keypressed = false; // Undervoltage detection if(uvoltage == true){ @@ -593,8 +619,8 @@ void OBP60Task(GwApi *api){ int keyboardMessage=0; while (xQueueReceive(allParameters.queue,&keyboardMessage,0)){ LOG_DEBUG(GwLog::LOG,"new key from keyboard %d",keyboardMessage); + keypressed = true; - Page *currentPage; if (keyboardMessage == 12) { LOG_DEBUG(GwLog::LOG, "Calling system page"); systemPage = true; // System page is out of band @@ -725,9 +751,17 @@ void OBP60Task(GwApi *api){ } } - // Refresh display data all 1s - if(millis() > starttime3 + 1000){ + // Refresh display data, default all 1s + currentPage = pages[pageNumber].page; + int pagetime = 1000; + if ((lastPage == pageNumber) and (!keypressed)) { + // same page we use page defined time + pagetime = currentPage->refreshtime; + } + if(millis() > starttime3 + pagetime){ + LOG_DEBUG(GwLog::DEBUG,"Page with refreshtime=%d", pagetime); starttime3 = millis(); + //refresh data from api api->getBoatDataValues(boatValues.numValues,boatValues.allBoatValues); api->getStatus(commonData.status); @@ -749,7 +783,6 @@ void OBP60Task(GwApi *api){ syspage->displayPage(sysparams); } else { - Page *currentPage = pages[pageNumber].page; if (currentPage == NULL){ LOG_DEBUG(GwLog::ERROR,"page number %d not found", pageNumber); // Error handling for missing page