mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Move sleep from gui to hasp
This commit is contained in:
parent
f9a67dbedc
commit
4e61e74d0a
@ -20,8 +20,8 @@
|
|||||||
//#include "ft6x36.h"
|
//#include "ft6x36.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../hasp/hasp_sleep.h"
|
#include "../hasp/hasp.h" // for hasp_sleep_state
|
||||||
extern uint8_t sleep_state;
|
extern uint8_t hasp_sleep_state;
|
||||||
|
|
||||||
void drv_touch_init(uint8_t rotation)
|
void drv_touch_init(uint8_t rotation)
|
||||||
{
|
{
|
||||||
@ -76,7 +76,7 @@ bool drv_touch_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
|
|||||||
#ifdef TOUCH_CS
|
#ifdef TOUCH_CS
|
||||||
uint16_t touchX, touchY;
|
uint16_t touchX, touchY;
|
||||||
bool touched = drv_touchpad_getXY(&touchX, &touchY);
|
bool touched = drv_touchpad_getXY(&touchX, &touchY);
|
||||||
if(touched && sleep_state != HASP_SLEEP_OFF) sleep_check_state(); // update Idle
|
if(touched && hasp_sleep_state != HASP_SLEEP_OFF) hasp_update_sleep_state(); // update Idle
|
||||||
|
|
||||||
// Ignore first press?
|
// Ignore first press?
|
||||||
|
|
||||||
|
@ -60,6 +60,9 @@ LV_IMG_DECLARE(img_bubble_pattern)
|
|||||||
void haspLoadPage(const char * pages);
|
void haspLoadPage(const char * pages);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
uint8_t hasp_sleep_state = HASP_SLEEP_OFF; // Used in hasp_drv_touch.cpp
|
||||||
|
static uint16_t sleepTimeShort = 60; // 1 second resolution
|
||||||
|
static uint16_t sleepTimeLong = 120; // 1 second resolution
|
||||||
|
|
||||||
uint8_t haspStartDim = 100;
|
uint8_t haspStartDim = 100;
|
||||||
uint8_t haspStartPage = 0;
|
uint8_t haspStartPage = 0;
|
||||||
@ -89,6 +92,49 @@ lv_font_t * hasp_get_font(uint8_t fontid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WakeUp the display using a command instead of touch
|
||||||
|
*/
|
||||||
|
void hasp_wakeup()
|
||||||
|
{
|
||||||
|
lv_disp_trig_activity(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if sleep state needs to be updated
|
||||||
|
*/
|
||||||
|
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) {
|
||||||
|
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) {
|
||||||
|
dispatch_output_idle_state(HASP_SLEEP_SHORT);
|
||||||
|
hasp_sleep_state = HASP_SLEEP_SHORT;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(hasp_sleep_state != HASP_SLEEP_OFF) {
|
||||||
|
dispatch_output_idle_state(HASP_SLEEP_OFF);
|
||||||
|
hasp_sleep_state = HASP_SLEEP_OFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (hasp_sleep_state != HASP_SLEEP_OFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if we went to sleep, wake up is handled in the event handlers
|
||||||
|
*/
|
||||||
|
// void haspEverySecond()
|
||||||
|
// {
|
||||||
|
// hasp_update_sleep_state();
|
||||||
|
// }
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/**
|
/**
|
||||||
* Get Page Object by PageID
|
* Get Page Object by PageID
|
||||||
@ -234,7 +280,7 @@ static void custom_font_apply_cb(lv_theme_t * th, lv_obj_t * obj, lv_theme_style
|
|||||||
/**
|
/**
|
||||||
* Create a demo application
|
* Create a demo application
|
||||||
*/
|
*/
|
||||||
void haspSetup()
|
void haspSetup(void)
|
||||||
{
|
{
|
||||||
guiSetDim(haspStartDim);
|
guiSetDim(haspStartDim);
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@ extern "C" {
|
|||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
|
#define HASP_SLEEP_OFF 0
|
||||||
|
#define HASP_SLEEP_SHORT 1
|
||||||
|
#define HASP_SLEEP_LONG 2
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
@ -35,8 +38,10 @@ extern "C" {
|
|||||||
/**
|
/**
|
||||||
* Create a hasp application
|
* Create a hasp application
|
||||||
*/
|
*/
|
||||||
void haspSetup();
|
void haspSetup(void);
|
||||||
void IRAM_ATTR haspLoop(void);
|
void IRAM_ATTR haspLoop(void);
|
||||||
|
//void haspEverySecond(void); // See MACROS
|
||||||
|
|
||||||
void haspReconnect(void);
|
void haspReconnect(void);
|
||||||
void haspDisconnect(void);
|
void haspDisconnect(void);
|
||||||
|
|
||||||
@ -59,9 +64,13 @@ bool haspSetConfig(const JsonObject & settings);
|
|||||||
|
|
||||||
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();
|
||||||
|
void hasp_wakeup(void);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
**********************/
|
**********************/
|
||||||
|
#define haspEverySecond hasp_update_sleep_state
|
||||||
|
|
||||||
#endif /*HASP_USE_APP*/
|
#endif /*HASP_USE_APP*/
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include "hasp_dispatch.h"
|
#include "hasp_dispatch.h"
|
||||||
#include "hasp_object.h"
|
#include "hasp_object.h"
|
||||||
#include "hasp_sleep.h"
|
|
||||||
#include "hasp.h"
|
#include "hasp.h"
|
||||||
|
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
@ -693,7 +692,7 @@ void dispatch_calibrate(const char *, const char *)
|
|||||||
|
|
||||||
void dispatch_wakeup(const char *, const char *)
|
void dispatch_wakeup(const char *, const char *)
|
||||||
{
|
{
|
||||||
sleep_wakeup();
|
hasp_wakeup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatch_reboot(const char *, const char *)
|
void dispatch_reboot(const char *, const char *)
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include "hasp_object.h"
|
#include "hasp_object.h"
|
||||||
#include "hasp_dispatch.h"
|
#include "hasp_dispatch.h"
|
||||||
#include "hasp_attribute.h"
|
#include "hasp_attribute.h"
|
||||||
#include "hasp_sleep.h"
|
|
||||||
|
|
||||||
// ##################### Object Finders ########################################################
|
// ##################### Object Finders ########################################################
|
||||||
|
|
||||||
@ -311,7 +310,7 @@ void IRAM_ATTR btn_event_handler(lv_obj_t * obj, lv_event_t event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep_check_state(); // wakeup?
|
hasp_update_sleep_state(); // wakeup?
|
||||||
dispatch_object_event(obj, eventid); // send object event
|
dispatch_object_event(obj, eventid); // send object event
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,7 +322,7 @@ void IRAM_ATTR btn_event_handler(lv_obj_t * obj, lv_event_t event)
|
|||||||
void wakeup_event_handler(lv_obj_t * obj, lv_event_t event)
|
void wakeup_event_handler(lv_obj_t * obj, lv_event_t event)
|
||||||
{
|
{
|
||||||
if(obj == lv_disp_get_layer_sys(NULL)) {
|
if(obj == lv_disp_get_layer_sys(NULL)) {
|
||||||
sleep_check_state(); // wakeup?
|
hasp_update_sleep_state(); // wakeup?
|
||||||
lv_obj_set_click(obj, false); // disable fist click
|
lv_obj_set_click(obj, false); // disable fist click
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,7 +335,7 @@ void wakeup_event_handler(lv_obj_t * obj, lv_event_t event)
|
|||||||
static void btnmap_event_handler(lv_obj_t * obj, lv_event_t event)
|
static void btnmap_event_handler(lv_obj_t * obj, lv_event_t event)
|
||||||
{
|
{
|
||||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||||
sleep_check_state(); // wakeup?
|
hasp_update_sleep_state(); // wakeup?
|
||||||
hasp_send_obj_attribute_val(obj, lv_btnmatrix_get_active_btn(obj));
|
hasp_send_obj_attribute_val(obj, lv_btnmatrix_get_active_btn(obj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -349,7 +348,7 @@ static void btnmap_event_handler(lv_obj_t * obj, lv_event_t event)
|
|||||||
static void table_event_handler(lv_obj_t * obj, lv_event_t event)
|
static void table_event_handler(lv_obj_t * obj, lv_event_t event)
|
||||||
{
|
{
|
||||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||||
sleep_check_state(); // wakeup?
|
hasp_update_sleep_state(); // wakeup?
|
||||||
|
|
||||||
uint16_t row;
|
uint16_t row;
|
||||||
uint16_t col;
|
uint16_t col;
|
||||||
@ -365,7 +364,7 @@ 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)
|
void IRAM_ATTR toggle_event_handler(lv_obj_t * obj, lv_event_t event)
|
||||||
{
|
{
|
||||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||||
sleep_check_state(); // wakeup?
|
hasp_update_sleep_state(); // wakeup?
|
||||||
hasp_send_obj_attribute_val(obj, lv_checkbox_is_checked(obj));
|
hasp_send_obj_attribute_val(obj, lv_checkbox_is_checked(obj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -378,7 +377,7 @@ void IRAM_ATTR toggle_event_handler(lv_obj_t * obj, lv_event_t event)
|
|||||||
static void switch_event_handler(lv_obj_t * obj, lv_event_t event)
|
static void switch_event_handler(lv_obj_t * obj, lv_event_t event)
|
||||||
{
|
{
|
||||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||||
sleep_check_state(); // wakeup?
|
hasp_update_sleep_state(); // wakeup?
|
||||||
hasp_send_obj_attribute_val(obj, lv_switch_get_state(obj));
|
hasp_send_obj_attribute_val(obj, lv_switch_get_state(obj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,6 @@
|
|||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
|
|
||||||
#define HASP_SLEEP_OFF 0
|
|
||||||
#define HASP_SLEEP_SHORT 1
|
|
||||||
#define HASP_SLEEP_LONG 2
|
|
||||||
|
|
||||||
/* ===== Default Event Processors ===== */
|
/* ===== Default Event Processors ===== */
|
||||||
void guiSetup();
|
void guiSetup();
|
||||||
void IRAM_ATTR guiLoop(void);
|
void IRAM_ATTR guiLoop(void);
|
||||||
@ -24,12 +20,10 @@ void guiTakeScreenshot(const char * pFileName); // to file
|
|||||||
void guiTakeScreenshot(); // webclient
|
void guiTakeScreenshot(); // webclient
|
||||||
|
|
||||||
/* ===== Getter and Setter Functions ===== */
|
/* ===== Getter and Setter Functions ===== */
|
||||||
void guiWakeUp(void);
|
|
||||||
void guiSetDim(int8_t level);
|
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 IRAM_ATTR guiCheckSleep();
|
|
||||||
|
|
||||||
/* ===== Read/Write Configuration ===== */
|
/* ===== Read/Write Configuration ===== */
|
||||||
#if HASP_USE_CONFIG > 0
|
#if HASP_USE_CONFIG > 0
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include "hasp_oobe.h"
|
#include "hasp_oobe.h"
|
||||||
|
|
||||||
#include "hasp/hasp_dispatch.h"
|
#include "hasp/hasp_dispatch.h"
|
||||||
#include "hasp/hasp_sleep.h"
|
|
||||||
#include "hasp/hasp.h"
|
#include "hasp/hasp.h"
|
||||||
|
|
||||||
#include "net/hasp_network.h"
|
#include "net/hasp_network.h"
|
||||||
@ -156,7 +155,7 @@ void loop()
|
|||||||
/* Timer Loop */
|
/* Timer Loop */
|
||||||
if(millis() - mainLastLoopTime >= 1000) {
|
if(millis() - mainLastLoopTime >= 1000) {
|
||||||
/* Runs Every Second */
|
/* Runs Every Second */
|
||||||
sleepEverySecond();
|
haspEverySecond();
|
||||||
debugEverySecond(); // statusupdate
|
debugEverySecond(); // statusupdate
|
||||||
#if HASP_USE_OTA > 0
|
#if HASP_USE_OTA > 0
|
||||||
otaEverySecond(); // progressbar
|
otaEverySecond(); // progressbar
|
||||||
|
Loading…
x
Reference in New Issue
Block a user