Fix idle state wonkiness

This commit is contained in:
fvanroie 2021-01-26 15:30:25 +01:00
parent fe5e80529a
commit 8c2fbe9c4b
3 changed files with 47 additions and 22 deletions

View File

@ -114,13 +114,13 @@ bool IRAM_ATTR hasp_update_sleep_state()
{ {
uint32_t idle = lv_disp_get_inactive_time(NULL); uint32_t idle = lv_disp_get_inactive_time(NULL);
if(idle >= (sleepTimeShort + sleepTimeLong) * 1000U) { if(sleepTimeLong > 0 && idle >= (sleepTimeShort + sleepTimeLong) * 1000U) {
if(hasp_sleep_state != HASP_SLEEP_LONG && sleepTimeLong > 0) { if(hasp_sleep_state != HASP_SLEEP_LONG) {
dispatch_output_idle_state(HASP_SLEEP_LONG); dispatch_output_idle_state(HASP_SLEEP_LONG);
hasp_sleep_state = HASP_SLEEP_LONG; hasp_sleep_state = HASP_SLEEP_LONG;
} }
} else if(idle >= sleepTimeShort * 1000U) { } else if(sleepTimeShort > 0 && idle >= sleepTimeShort * 1000U) {
if(hasp_sleep_state != HASP_SLEEP_SHORT && sleepTimeShort > 0) { if(hasp_sleep_state != HASP_SLEEP_SHORT) {
dispatch_output_idle_state(HASP_SLEEP_SHORT); dispatch_output_idle_state(HASP_SLEEP_SHORT);
hasp_sleep_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 (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 * Checks if we went to sleep, wake up is handled in the event handlers
*/ */

View File

@ -11,7 +11,7 @@
#include "hasp_conf.h" #include "hasp_conf.h"
#if HASP_USE_DEBUG > 0 #if HASP_USE_DEBUG > 0
#include "../hasp_debug.h" #include "../hasp_debug.h"
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
@ -24,12 +24,12 @@ extern "C" {
#if HASP_USE_APP > 0 #if HASP_USE_APP > 0
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
#define HASP_SLEEP_OFF 0 #define HASP_SLEEP_OFF 0
#define HASP_SLEEP_SHORT 1 #define HASP_SLEEP_SHORT 1
#define HASP_SLEEP_LONG 2 #define HASP_SLEEP_LONG 2
/********************** /**********************
* TYPEDEFS * TYPEDEFS
@ -44,7 +44,7 @@ extern "C" {
*/ */
void haspSetup(void); void haspSetup(void);
void IRAM_ATTR haspLoop(void); void IRAM_ATTR haspLoop(void);
//void haspEverySecond(void); // See MACROS // void haspEverySecond(void); // See MACROS
void haspReconnect(void); void haspReconnect(void);
void haspDisconnect(void); void haspDisconnect(void);
@ -56,27 +56,29 @@ void haspSetPage(uint8_t id);
uint8_t haspGetPage(); uint8_t haspGetPage();
void haspClearPage(uint16_t pageid); void haspClearPage(uint16_t pageid);
void haspGetVersion(char* version,size_t len); void haspGetVersion(char * version, size_t len);
//void haspBackground(uint16_t pageid, uint16_t imageid); // void haspBackground(uint16_t pageid, uint16_t imageid);
// void haspNewObject(const JsonObject & config, uint8_t & saved_page_id); // void haspNewObject(const JsonObject & config, uint8_t & saved_page_id);
void haspProgressVal(uint8_t val); void haspProgressVal(uint8_t val);
#if HASP_USE_CONFIG > 0 #if HASP_USE_CONFIG > 0
bool haspGetConfig(const JsonObject & settings); bool haspGetConfig(const JsonObject & settings);
bool haspSetConfig(const JsonObject & settings); bool haspSetConfig(const JsonObject & settings);
#endif #endif
lv_font_t * hasp_get_font(uint8_t fontid); lv_font_t * hasp_get_font(uint8_t fontid);
bool IRAM_ATTR hasp_update_sleep_state(); 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); void hasp_wakeup(void);
/********************** /**********************
* MACROS * MACROS
**********************/ **********************/
#define haspEverySecond hasp_update_sleep_state #define haspEverySecond hasp_update_sleep_state
#endif /*HASP_USE_APP*/ #endif /*HASP_USE_APP*/

View File

@ -55,8 +55,6 @@ static bool guiShowPointer = false;
static bool guiBacklightIsOn = true; static bool guiBacklightIsOn = true;
static int8_t guiDimLevel = -1; static int8_t guiDimLevel = -1;
static int8_t guiBacklightPin = TFT_BCKL; 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 guiTickPeriod = 20;
static uint8_t guiRotation = TFT_ROTATION; static uint8_t guiRotation = TFT_ROTATION;
static uint8_t guiInvertDisplay = INVERT_COLORS; static uint8_t guiInvertDisplay = INVERT_COLORS;
@ -487,6 +485,9 @@ int8_t guiGetDim()
bool guiGetConfig(const JsonObject & settings) bool guiGetConfig(const JsonObject & settings)
{ {
bool changed = false; bool changed = false;
uint16_t guiSleepTime1;
uint16_t guiSleepTime2;
hasp_get_sleep_time(guiSleepTime1, guiSleepTime2);
if(guiTickPeriod != settings[FPSTR(F_GUI_TICKPERIOD)].as<uint8_t>()) changed = true; if(guiTickPeriod != settings[FPSTR(F_GUI_TICKPERIOD)].as<uint8_t>()) changed = true;
settings[FPSTR(F_GUI_TICKPERIOD)] = guiTickPeriod; settings[FPSTR(F_GUI_TICKPERIOD)] = guiTickPeriod;
@ -556,6 +557,8 @@ bool guiSetConfig(const JsonObject & settings)
{ {
configOutput(settings, TAG_GUI); configOutput(settings, TAG_GUI);
bool changed = false; bool changed = false;
uint16_t guiSleepTime1;
uint16_t guiSleepTime2;
changed |= configSet(guiTickPeriod, settings[FPSTR(F_GUI_TICKPERIOD)], F("guiTickPeriod")); changed |= configSet(guiTickPeriod, settings[FPSTR(F_GUI_TICKPERIOD)], F("guiTickPeriod"));
changed |= configSet(guiBacklightPin, settings[FPSTR(F_GUI_BACKLIGHTPIN)], F("guiBacklightPin")); 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(guiRotation, settings[FPSTR(F_GUI_ROTATION)], F("guiRotation"));
changed |= configSet(guiInvertDisplay, settings[FPSTR(F_GUI_INVERT)], F("guiInvertDisplay")); changed |= configSet(guiInvertDisplay, settings[FPSTR(F_GUI_INVERT)], F("guiInvertDisplay"));
hasp_set_sleep_time(guiSleepTime1, guiSleepTime2);
if(!settings[FPSTR(F_GUI_POINTER)].isNull()) { if(!settings[FPSTR(F_GUI_POINTER)].isNull()) {
if(guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as<bool>()) { if(guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as<bool>()) {
Log.verbose(TAG_GUI, F("guiShowPointer set")); Log.verbose(TAG_GUI, F("guiShowPointer set"));