diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index b8503796..39992ba1 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -114,13 +114,13 @@ bool IRAM_ATTR hasp_update_sleep_state() { uint32_t idle = lv_disp_get_inactive_time(NULL); - if(idle >= (sleepTimeShort + sleepTimeLong) * 1000U) { - if(hasp_sleep_state != HASP_SLEEP_LONG && sleepTimeLong > 0) { + if(sleepTimeLong > 0 && idle >= (sleepTimeShort + sleepTimeLong) * 1000U) { + if(hasp_sleep_state != HASP_SLEEP_LONG) { dispatch_output_idle_state(HASP_SLEEP_LONG); hasp_sleep_state = HASP_SLEEP_LONG; } - } else if(idle >= sleepTimeShort * 1000U) { - if(hasp_sleep_state != HASP_SLEEP_SHORT && sleepTimeShort > 0) { + } else if(sleepTimeShort > 0 && idle >= sleepTimeShort * 1000U) { + if(hasp_sleep_state != HASP_SLEEP_SHORT) { dispatch_output_idle_state(HASP_SLEEP_SHORT); hasp_sleep_state = HASP_SLEEP_SHORT; } @@ -134,6 +134,24 @@ bool IRAM_ATTR hasp_update_sleep_state() return (hasp_sleep_state != HASP_SLEEP_OFF); } +/** + * Return the sleep times + */ +void hasp_get_sleep_time(uint16_t & short_time, uint16_t & long_time) +{ + short_time = sleepTimeShort; + long_time = sleepTimeLong; +} + +/** + * Set the sleep times + */ +void hasp_set_sleep_time(uint16_t short_time, uint16_t long_time) +{ + sleepTimeShort = short_time; + sleepTimeLong = long_time; +} + /** * Checks if we went to sleep, wake up is handled in the event handlers */ diff --git a/src/hasp/hasp.h b/src/hasp/hasp.h index 7e258b47..f5e2fc07 100644 --- a/src/hasp/hasp.h +++ b/src/hasp/hasp.h @@ -11,7 +11,7 @@ #include "hasp_conf.h" #if HASP_USE_DEBUG > 0 -#include "../hasp_debug.h" + #include "../hasp_debug.h" #endif #ifdef __cplusplus @@ -24,12 +24,12 @@ extern "C" { #if HASP_USE_APP > 0 -/********************* - * DEFINES - *********************/ -#define HASP_SLEEP_OFF 0 -#define HASP_SLEEP_SHORT 1 -#define HASP_SLEEP_LONG 2 + /********************* + * DEFINES + *********************/ + #define HASP_SLEEP_OFF 0 + #define HASP_SLEEP_SHORT 1 + #define HASP_SLEEP_LONG 2 /********************** * TYPEDEFS @@ -44,7 +44,7 @@ extern "C" { */ void haspSetup(void); void IRAM_ATTR haspLoop(void); -//void haspEverySecond(void); // See MACROS +// void haspEverySecond(void); // See MACROS void haspReconnect(void); void haspDisconnect(void); @@ -56,27 +56,29 @@ void haspSetPage(uint8_t id); uint8_t haspGetPage(); void haspClearPage(uint16_t pageid); -void haspGetVersion(char* version,size_t len); -//void haspBackground(uint16_t pageid, uint16_t imageid); +void haspGetVersion(char * version, size_t len); +// void haspBackground(uint16_t pageid, uint16_t imageid); // void haspNewObject(const JsonObject & config, uint8_t & saved_page_id); void haspProgressVal(uint8_t val); -#if HASP_USE_CONFIG > 0 + #if HASP_USE_CONFIG > 0 bool haspGetConfig(const JsonObject & settings); bool haspSetConfig(const JsonObject & settings); -#endif + #endif lv_font_t * hasp_get_font(uint8_t fontid); bool IRAM_ATTR hasp_update_sleep_state(); +void hasp_get_sleep_time(uint16_t & short_time, uint16_t & long_time); +void hasp_set_sleep_time(uint16_t short_time, uint16_t long_time); void hasp_wakeup(void); -/********************** - * MACROS - **********************/ -#define haspEverySecond hasp_update_sleep_state + /********************** + * MACROS + **********************/ + #define haspEverySecond hasp_update_sleep_state #endif /*HASP_USE_APP*/ diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index 9d088d9e..fcdac06a 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -55,8 +55,6 @@ static bool guiShowPointer = false; static bool guiBacklightIsOn = true; static int8_t guiDimLevel = -1; static int8_t guiBacklightPin = TFT_BCKL; -static uint16_t guiSleepTime1 = 60; // 1 second resolution -static uint16_t guiSleepTime2 = 120; // 1 second resolution static uint8_t guiTickPeriod = 20; static uint8_t guiRotation = TFT_ROTATION; static uint8_t guiInvertDisplay = INVERT_COLORS; @@ -487,6 +485,9 @@ int8_t guiGetDim() bool guiGetConfig(const JsonObject & settings) { bool changed = false; + uint16_t guiSleepTime1; + uint16_t guiSleepTime2; + hasp_get_sleep_time(guiSleepTime1, guiSleepTime2); if(guiTickPeriod != settings[FPSTR(F_GUI_TICKPERIOD)].as()) changed = true; settings[FPSTR(F_GUI_TICKPERIOD)] = guiTickPeriod; @@ -556,6 +557,8 @@ bool guiSetConfig(const JsonObject & settings) { configOutput(settings, TAG_GUI); bool changed = false; + uint16_t guiSleepTime1; + uint16_t guiSleepTime2; changed |= configSet(guiTickPeriod, settings[FPSTR(F_GUI_TICKPERIOD)], F("guiTickPeriod")); changed |= configSet(guiBacklightPin, settings[FPSTR(F_GUI_BACKLIGHTPIN)], F("guiBacklightPin")); @@ -564,6 +567,8 @@ bool guiSetConfig(const JsonObject & settings) changed |= configSet(guiRotation, settings[FPSTR(F_GUI_ROTATION)], F("guiRotation")); changed |= configSet(guiInvertDisplay, settings[FPSTR(F_GUI_INVERT)], F("guiInvertDisplay")); + hasp_set_sleep_time(guiSleepTime1, guiSleepTime2); + if(!settings[FPSTR(F_GUI_POINTER)].isNull()) { if(guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as()) { Log.verbose(TAG_GUI, F("guiShowPointer set"));