Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
norbert-walter committed Jan 23, 2025
2 parents 78b5861 + d6a7323 commit b4ebec8
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 16 deletions.
32 changes: 32 additions & 0 deletions lib/obp60task/OBP60Extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions lib/obp60task/OBP60Extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ Point rotatePoint(const Point& origin, const Point& p, double angle);
std::vector<Point> rotatePoints(const Point& origin, const std::vector<Point>& pts, double angle);
void fillPoly4(const std::vector<Point>& 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
Expand Down
6 changes: 3 additions & 3 deletions lib/obp60task/PageBME280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand Down
36 changes: 29 additions & 7 deletions lib/obp60task/PageSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions lib/obp60task/PageWhite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}

};
};
Expand Down
1 change: 1 addition & 0 deletions lib/obp60task/Pagedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
41 changes: 37 additions & 4 deletions lib/obp60task/obp60task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -356,6 +366,8 @@ void deepSleep(CommonData &common){
}
#endif



// OBP60 Task
//####################################################################################
void OBP60Task(GwApi *api){
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit b4ebec8

Please sign in to comment.