mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-14 14:33:07 +01:00
Add sleep mode for OBP40 and cleanup code
This commit is contained in:
@@ -157,5 +157,9 @@
|
||||
#define OBP_POWER_50 41 // Power LED
|
||||
#define OBP_POWER_EPD 7 // ePaper power
|
||||
#define OBP_POWER_SD 42 // SD card power
|
||||
// Deep sleep wakeup
|
||||
#define OBP_WAKEUP_LEVEL 0 // //1 = High, 0 = Low, depends on switch
|
||||
#define OBP_WAKEWUP_PIN GPIO_NUM_5// Wakeup pin, same as CONF (wheel press)
|
||||
// Must define as GPIO_NUM_X
|
||||
#endif
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
#include "OBP60Keypad.h" // Functions for keypad
|
||||
|
||||
#ifdef BOARD_OBP40S3
|
||||
#include <FS.h> // SD-Card access
|
||||
#include "driver/rtc_io.h" // Needs for weakup from deep sleep
|
||||
#include <FS.h> // SD-Card access
|
||||
#include <SD.h>
|
||||
#include <SPI.h>
|
||||
#endif
|
||||
@@ -80,6 +81,11 @@ void OBP60Init(GwApi *api){
|
||||
LOG_DEBUG(GwLog::LOG,"SD card type %s of size %d MB detected", sdtype, cardSize);
|
||||
}
|
||||
}
|
||||
|
||||
// Deep sleep wakeup configuration
|
||||
esp_sleep_enable_ext0_wakeup(OBP_WAKEWUP_PIN, 0); // 1 = High, 0 = Low
|
||||
rtc_gpio_pullup_en(OBP_WAKEWUP_PIN); // Activate pullup resistor
|
||||
rtc_gpio_pulldown_dis(OBP_WAKEWUP_PIN); // Disable pulldown resistor
|
||||
#endif
|
||||
|
||||
// Init power rail 5.0V
|
||||
@@ -320,6 +326,34 @@ void underVoltageDetection(GwApi *api, CommonData &common){
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BOARD_OBP40S3
|
||||
// Deep sleep funktion
|
||||
void deepSleep(CommonData &common){
|
||||
// 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().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update
|
||||
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 wheel and wait 5s");
|
||||
getdisplay().nextPage(); // Partial update
|
||||
getdisplay().powerOff(); // Display power off
|
||||
setPortPin(OBP_POWER_EPD, false); // Power off ePaper display
|
||||
// Stop system
|
||||
while(true){
|
||||
esp_deep_sleep_start(); // Deep Sleep with weakup via GPIO pin
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
// OBP60 Task
|
||||
//####################################################################################
|
||||
void OBP60Task(GwApi *api){
|
||||
@@ -520,7 +554,7 @@ void OBP60Task(GwApi *api){
|
||||
// Undervoltage detection
|
||||
if(uvoltage == true){
|
||||
underVoltageDetection(api, commonData);
|
||||
}
|
||||
}
|
||||
|
||||
// Set CPU speed after boot after 1min
|
||||
if(millis() > firststart + (1 * 60 * 1000) && cpuspeedsetted == false){
|
||||
@@ -588,6 +622,12 @@ void OBP60Task(GwApi *api){
|
||||
toggleBacklightLED(commonData.backlight.brightness, commonData.backlight.color);
|
||||
}
|
||||
}
|
||||
#ifdef BOARD_OBP40S3
|
||||
// #3 Deep sleep mode for OBP40
|
||||
if (keyboardMessage == 3){
|
||||
deepSleep(commonData);
|
||||
}
|
||||
#endif
|
||||
// #9 Swipe right or #4 key right
|
||||
if ((keyboardMessage == 9) or (keyboardMessage == 4))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user