Update guiSleeping code

This commit is contained in:
fvanroie 2020-11-18 19:14:11 +01:00
parent c7fdbc8944
commit 6f3c76128d
3 changed files with 47 additions and 28 deletions

View File

@ -63,7 +63,7 @@ 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 guiSleeping = 0; // 0 = off, 1 = short, 2 = long
static uint8_t guiSleeping = HASP_SLEEP_OFF;
static uint8_t guiTickPeriod = 20;
static uint8_t guiRotation = TFT_ROTATION;
#if ESP32 > 0 || ESP8266 > 0
@ -74,27 +74,32 @@ static Ticker tick(lv_tick_handler, LVGL_TICK_PERIOD); // guiTickPeriod);
// static TFT_eSPI tft; // = TFT_eSPI(); /* TFT instance */
static uint16_t calData[5] = {0, 65535, 0, 65535, 0};
static bool guiCheckSleep()
bool guiCheckSleep()
{
char idle_state[6];
uint32_t idle = lv_disp_get_inactive_time(NULL);
if(idle >= (guiSleepTime1 + guiSleepTime2) * 1000U) {
if(guiSleeping != 2) {
dispatch_output_idle_state(("LONG")); // Literal string
guiSleeping = 2;
if(guiSleeping != HASP_SLEEP_SHORT) {
snprintf_P(idle_state, sizeof(idle_state), PSTR("LONG"));
dispatch_output_idle_state(idle_state);
guiSleeping = HASP_SLEEP_LONG;
}
return true;
} else if(idle >= guiSleepTime1 * 1000U) {
if(guiSleeping != 1) {
dispatch_output_idle_state(("SHORT")); // Literal string
guiSleeping = 1;
if(guiSleeping != HASP_SLEEP_SHORT) {
snprintf_P(idle_state, sizeof(idle_state), PSTR("SHORT"));
dispatch_output_idle_state(idle_state);
guiSleeping = HASP_SLEEP_SHORT;
}
} else {
if(guiSleeping != HASP_SLEEP_OFF) {
snprintf_P(idle_state, sizeof(idle_state), PSTR("OFF"));
dispatch_output_idle_state(idle_state);
guiSleeping = HASP_SLEEP_OFF;
}
return true;
}
if(guiSleeping != 0) {
dispatch_output_idle_state(("OFF")); // Literal string
guiSleeping = 0;
}
return false;
return (guiSleeping != HASP_SLEEP_OFF);
}
/* Experimental Display flushing */
@ -391,11 +396,11 @@ bool IRAM_ATTR my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t *
#else
// xpt2046_alt_drv_read(indev_driver, data);
xpt2046_read(indev_driver, data);
if(data->state && guiSleeping > 0) guiCheckSleep();
if(data->state && guiSleeping != HASP_SLEEP_OFF) guiCheckSleep();
return false;
#endif
if(touched && guiSleeping > 0) guiCheckSleep(); // update Idle
if(touched && guiSleeping != HASP_SLEEP_OFF) guiCheckSleep(); // update Idle
// Ignore first press?
@ -811,7 +816,7 @@ bool guiSetConfig(const JsonObject & settings)
if(calData[0] != 0 || calData[1] != 65535 || calData[2] != 0 || calData[3] != 65535) {
Log.verbose(TAG_GUI, F("calData set [%u, %u, %u, %u, %u]"), calData[0], calData[1], calData[2], calData[3],
calData[4]);
calData[4]);
oobeSetAutoCalibrate(false);
} else {
Log.notice(TAG_GUI, F("First Touch Calibration enabled"));

View File

@ -6,6 +6,10 @@
#include "lvgl.h"
#define HASP_SLEEP_OFF 0
#define HASP_SLEEP_SHORT 1
#define HASP_SLEEP_LONG 2
// #if defined(ARDUINO_ARCH_ESP8266)
// #include <ESP8266WebServer.h>
// void guiTakeScreenshot(ESP8266WebServer & client);
@ -30,6 +34,7 @@ void guiSetDim(int8_t level);
int8_t guiGetDim(void);
void guiSetBacklight(bool lighton);
bool guiGetBacklight();
bool guiCheckSleep();
bool guiGetConfig(const JsonObject & settings);
bool guiSetConfig(const JsonObject & settings);

View File

@ -13,6 +13,7 @@
#include "ArduinoLog.h"
#include "hasp.h"
#include "hasp_gui.h"
#include "hasp_object.h"
#include "hasp_dispatch.h"
#include "hasp_attribute.h"
@ -221,7 +222,7 @@ static inline void hasp_send_obj_attribute_txt(lv_obj_t * obj, const char * txt)
void IRAM_ATTR btn_event_handler(lv_obj_t * obj, lv_event_t event)
{
uint8_t eventid;
char buffer[64];
char buffer[6];
switch(event) {
case LV_EVENT_PRESSED:
@ -268,9 +269,11 @@ void IRAM_ATTR btn_event_handler(lv_obj_t * obj, lv_event_t event)
return;
}
guiCheckSleep();
if(obj == lv_disp_get_layer_sys(NULL)) {
#if HASP_USE_MQTT > 0
mqtt_send_state(F("wakeuptouch"), buffer);
mqtt_send_state(F("wakeuptouch"), buffer); // TODO: enable wakeuptouch
#endif
} else {
// hasp_send_obj_attribute_event(obj, buffer);
@ -298,9 +301,9 @@ static void table_event_handler(lv_obj_t * obj, lv_event_t event)
if(event == LV_EVENT_VALUE_CHANGED) {
uint16_t row;
uint16_t col;
if(lv_table_get_pressed_cell(obj, &row, &col) == LV_RES_OK) {
hasp_send_obj_attribute_val(obj, row);
}
guiCheckSleep();
if(lv_table_get_pressed_cell(obj, &row, &col) == LV_RES_OK) hasp_send_obj_attribute_val(obj, row);
}
}
@ -311,9 +314,13 @@ static void table_event_handler(lv_obj_t * obj, lv_event_t event)
*/
void IRAM_ATTR toggle_event_handler(lv_obj_t * obj, lv_event_t event)
{
bool toggled =
lv_btn_get_state(obj) == LV_BTN_STATE_CHECKED_PRESSED || lv_btn_get_state(obj) == LV_BTN_STATE_CHECKED_RELEASED;
if(event == LV_EVENT_VALUE_CHANGED) hasp_send_obj_attribute_val(obj, toggled);
if(event == LV_EVENT_VALUE_CHANGED) {
bool toggled = lv_btn_get_state(obj) == LV_BTN_STATE_CHECKED_PRESSED ||
lv_btn_get_state(obj) == LV_BTN_STATE_CHECKED_RELEASED;
guiCheckSleep();
hasp_send_obj_attribute_val(obj, toggled);
}
}
/**
@ -368,8 +375,10 @@ static void slider_event_handler(lv_obj_t * obj, lv_event_t event)
*/
static void cpicker_event_handler(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_VALUE_CHANGED)
hasp_send_obj_attribute_color(obj, "color", lv_cpicker_get_color(obj)); // Literial string
char color[6];
snprintf_P(color, sizeof(color), PSTR("color"));
if(event == LV_EVENT_VALUE_CHANGED) hasp_send_obj_attribute_color(obj, color, lv_cpicker_get_color(obj));
}
/**