mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Improve idle checking
This commit is contained in:
parent
2855dc7b38
commit
aba681e351
@ -241,18 +241,31 @@ void dispatch_text_line(const char * cmnd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send idle state to the client
|
// send idle state to the client
|
||||||
void dispatch_output_idle_state(const char * state)
|
void dispatch_output_idle_state(uint8_t state)
|
||||||
{
|
{
|
||||||
|
char buffer[6];
|
||||||
|
|
||||||
|
switch(state) {
|
||||||
|
case HASP_SLEEP_LONG:
|
||||||
|
memcpy_P(buffer, PSTR("LONG"), sizeof(buffer));
|
||||||
|
break;
|
||||||
|
case HASP_SLEEP_SHORT:
|
||||||
|
memcpy_P(buffer, PSTR("SHORT"), sizeof(buffer));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
memcpy_P(buffer, PSTR("OFF"), sizeof(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE)
|
#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE)
|
||||||
Log.notice(TAG_MSGR, F("idle = %s"), state);
|
Log.notice(TAG_MSGR, F("idle = %s"), buffer);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#if HASP_USE_MQTT > 0
|
#if HASP_USE_MQTT > 0
|
||||||
mqtt_send_state(F("idle"), state);
|
mqtt_send_state(F("idle"), buffer);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HASP_USE_TASMOTA_SLAVE > 0
|
#if HASP_USE_TASMOTA_SLAVE > 0
|
||||||
slave_send_state(F("idle"), state);
|
slave_send_state(F("idle"), buffer);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,7 +31,7 @@ void dispatch_backlight(const char * payload);
|
|||||||
void dispatch_web_update(const char * espOtaUrl);
|
void dispatch_web_update(const char * espOtaUrl);
|
||||||
void dispatch_reboot(bool saveConfig);
|
void dispatch_reboot(bool saveConfig);
|
||||||
|
|
||||||
void dispatch_output_idle_state(const char * state);
|
void dispatch_output_idle_state(uint8_t state);
|
||||||
void dispatch_output_statusupdate(void);
|
void dispatch_output_statusupdate(void);
|
||||||
void dispatch_output_current_page();
|
void dispatch_output_current_page();
|
||||||
|
|
||||||
|
@ -79,27 +79,23 @@ static Ticker tick; /* timer for interrupt handler */
|
|||||||
static Ticker tick(lv_tick_handler, LVGL_TICK_PERIOD); // guiTickPeriod);
|
static Ticker tick(lv_tick_handler, LVGL_TICK_PERIOD); // guiTickPeriod);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool guiCheckSleep()
|
bool IRAM_ATTR guiCheckSleep()
|
||||||
{
|
{
|
||||||
char idle_state[6];
|
|
||||||
uint32_t idle = lv_disp_get_inactive_time(NULL);
|
uint32_t idle = lv_disp_get_inactive_time(NULL);
|
||||||
|
|
||||||
if(idle >= (guiSleepTime1 + guiSleepTime2) * 1000U) {
|
if(idle >= (guiSleepTime1 + guiSleepTime2) * 1000U) {
|
||||||
if(guiSleeping != HASP_SLEEP_SHORT) {
|
if(guiSleeping != HASP_SLEEP_LONG) {
|
||||||
snprintf_P(idle_state, sizeof(idle_state), PSTR("LONG"));
|
dispatch_output_idle_state(HASP_SLEEP_LONG);
|
||||||
dispatch_output_idle_state(idle_state);
|
|
||||||
guiSleeping = HASP_SLEEP_LONG;
|
guiSleeping = HASP_SLEEP_LONG;
|
||||||
}
|
}
|
||||||
} else if(idle >= guiSleepTime1 * 1000U) {
|
} else if(idle >= guiSleepTime1 * 1000U) {
|
||||||
if(guiSleeping != HASP_SLEEP_SHORT) {
|
if(guiSleeping != HASP_SLEEP_SHORT) {
|
||||||
snprintf_P(idle_state, sizeof(idle_state), PSTR("SHORT"));
|
dispatch_output_idle_state(HASP_SLEEP_SHORT);
|
||||||
dispatch_output_idle_state(idle_state);
|
|
||||||
guiSleeping = HASP_SLEEP_SHORT;
|
guiSleeping = HASP_SLEEP_SHORT;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(guiSleeping != HASP_SLEEP_OFF) {
|
if(guiSleeping != HASP_SLEEP_OFF) {
|
||||||
snprintf_P(idle_state, sizeof(idle_state), PSTR("OFF"));
|
dispatch_output_idle_state(HASP_SLEEP_OFF);
|
||||||
dispatch_output_idle_state(idle_state);
|
|
||||||
guiSleeping = HASP_SLEEP_OFF;
|
guiSleeping = HASP_SLEEP_OFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -600,7 +596,8 @@ void guiSetup()
|
|||||||
lv_bar_set_value(bar, 10, LV_ANIM_OFF);
|
lv_bar_set_value(bar, 10, LV_ANIM_OFF);
|
||||||
lv_obj_set_size(bar, 200, 15);
|
lv_obj_set_size(bar, 200, 15);
|
||||||
lv_obj_align(bar, lv_layer_sys(), LV_ALIGN_CENTER, 0, -10);
|
lv_obj_align(bar, lv_layer_sys(), LV_ALIGN_CENTER, 0, -10);
|
||||||
lv_obj_set_user_data(bar, 10);
|
lv_obj_user_data_t udata = (lv_obj_user_data_t){10, 1, 0};
|
||||||
|
lv_obj_set_user_data(bar, udata);
|
||||||
lv_obj_set_style_local_value_color(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
lv_obj_set_style_local_value_color(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
||||||
lv_obj_set_style_local_value_align(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_ALIGN_CENTER);
|
lv_obj_set_style_local_value_align(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_ALIGN_CENTER);
|
||||||
lv_obj_set_style_local_value_ofs_y(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, 20);
|
lv_obj_set_style_local_value_ofs_y(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, 20);
|
||||||
|
@ -28,7 +28,7 @@ void guiSetDim(int8_t level);
|
|||||||
int8_t guiGetDim(void);
|
int8_t guiGetDim(void);
|
||||||
void guiSetBacklight(bool lighton);
|
void guiSetBacklight(bool lighton);
|
||||||
bool guiGetBacklight();
|
bool guiGetBacklight();
|
||||||
bool guiCheckSleep();
|
bool IRAM_ATTR guiCheckSleep();
|
||||||
|
|
||||||
/* ===== Read/Write Configuration ===== */
|
/* ===== Read/Write Configuration ===== */
|
||||||
bool guiGetConfig(const JsonObject & settings);
|
bool guiGetConfig(const JsonObject & settings);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user