mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-29 06:06:40 +00:00
Add dispatch_idle and rename dispatch_current_page
This commit is contained in:
parent
67a0902d75
commit
4a4f410303
@ -116,24 +116,38 @@ bool hasp_update_sleep_state()
|
|||||||
|
|
||||||
if(sleepTimeLong > 0 && idle >= (sleepTimeShort + sleepTimeLong) * 1000U) {
|
if(sleepTimeLong > 0 && idle >= (sleepTimeShort + sleepTimeLong) * 1000U) {
|
||||||
if(hasp_sleep_state != HASP_SLEEP_LONG) {
|
if(hasp_sleep_state != HASP_SLEEP_LONG) {
|
||||||
dispatch_output_idle_state(HASP_SLEEP_LONG);
|
|
||||||
hasp_sleep_state = HASP_SLEEP_LONG;
|
hasp_sleep_state = HASP_SLEEP_LONG;
|
||||||
|
dispatch_idle(NULL, NULL);
|
||||||
}
|
}
|
||||||
} else if(sleepTimeShort > 0 && idle >= sleepTimeShort * 1000U) {
|
} else if(sleepTimeShort > 0 && idle >= sleepTimeShort * 1000U) {
|
||||||
if(hasp_sleep_state != HASP_SLEEP_SHORT) {
|
if(hasp_sleep_state != HASP_SLEEP_SHORT) {
|
||||||
dispatch_output_idle_state(HASP_SLEEP_SHORT);
|
|
||||||
hasp_sleep_state = HASP_SLEEP_SHORT;
|
hasp_sleep_state = HASP_SLEEP_SHORT;
|
||||||
|
dispatch_idle(NULL, NULL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(hasp_sleep_state != HASP_SLEEP_OFF) {
|
if(hasp_sleep_state != HASP_SLEEP_OFF) {
|
||||||
dispatch_output_idle_state(HASP_SLEEP_OFF);
|
|
||||||
hasp_sleep_state = HASP_SLEEP_OFF;
|
hasp_sleep_state = HASP_SLEEP_OFF;
|
||||||
|
dispatch_idle(NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (hasp_sleep_state != HASP_SLEEP_OFF);
|
return (hasp_sleep_state != HASP_SLEEP_OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hasp_get_sleep_state(char* payload)
|
||||||
|
{
|
||||||
|
switch(hasp_sleep_state) {
|
||||||
|
case HASP_SLEEP_LONG:
|
||||||
|
memcpy_P(payload, PSTR("long"), 5);
|
||||||
|
break;
|
||||||
|
case HASP_SLEEP_SHORT:
|
||||||
|
memcpy_P(payload, PSTR("short"), 6);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
memcpy_P(payload, PSTR("off"), 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void hasp_enable_wakeup_touch()
|
void hasp_enable_wakeup_touch()
|
||||||
{
|
{
|
||||||
lv_obj_set_click(lv_disp_get_layer_sys(NULL), true); // enable first touch
|
lv_obj_set_click(lv_disp_get_layer_sys(NULL), true); // enable first touch
|
||||||
|
@ -68,6 +68,7 @@ bool haspSetConfig(const JsonObject& settings);
|
|||||||
lv_font_t* hasp_get_font(uint8_t fontid);
|
lv_font_t* hasp_get_font(uint8_t fontid);
|
||||||
|
|
||||||
bool hasp_update_sleep_state();
|
bool hasp_update_sleep_state();
|
||||||
|
void hasp_get_sleep_state(char* payload);
|
||||||
void hasp_get_sleep_time(uint16_t& short_time, uint16_t& long_time);
|
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_set_sleep_time(uint16_t short_time, uint16_t long_time);
|
||||||
void hasp_enable_wakeup_touch();
|
void hasp_enable_wakeup_touch();
|
||||||
|
@ -38,13 +38,11 @@
|
|||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern uint8_t hasp_sleep_state;
|
|
||||||
|
|
||||||
dispatch_conf_t dispatch_setings = {.teleperiod = 300};
|
dispatch_conf_t dispatch_setings = {.teleperiod = 300};
|
||||||
|
|
||||||
uint32_t dispatchLastMillis = -3000000; // force discovery
|
uint32_t dispatchLastMillis = -3000000; // force discovery
|
||||||
uint8_t nCommands = 0;
|
uint8_t nCommands = 0;
|
||||||
haspCommand_t commands[18];
|
haspCommand_t commands[19];
|
||||||
|
|
||||||
struct moodlight_t
|
struct moodlight_t
|
||||||
{
|
{
|
||||||
@ -217,10 +215,8 @@ static void dispatch_gpio(const char* topic, const char* payload)
|
|||||||
pin = atoi(topic);
|
pin = atoi(topic);
|
||||||
if(strlen(payload) > 0) {
|
if(strlen(payload) > 0) {
|
||||||
|
|
||||||
if(1)
|
|
||||||
val = atoi(payload);
|
val = atoi(payload);
|
||||||
else
|
if(val == 0) val = Parser::is_true(payload);
|
||||||
val = Parser::is_true(payload);
|
|
||||||
|
|
||||||
gpio_set_value(pin, val);
|
gpio_set_value(pin, val);
|
||||||
} else {
|
} else {
|
||||||
@ -238,6 +234,8 @@ void dispatch_command(const char* topic, const char* payload)
|
|||||||
{
|
{
|
||||||
/* ================================= Standard payload commands ======================================= */
|
/* ================================= Standard payload commands ======================================= */
|
||||||
|
|
||||||
|
if(dispatch_parse_button_attribute(topic, payload)) return; // matched pxby.attr
|
||||||
|
|
||||||
// check and execute commands from commands array
|
// check and execute commands from commands array
|
||||||
for(int i = 0; i < nCommands; i++) {
|
for(int i = 0; i < nCommands; i++) {
|
||||||
if(!strcasecmp_P(topic, commands[i].p_cmdstr)) {
|
if(!strcasecmp_P(topic, commands[i].p_cmdstr)) {
|
||||||
@ -256,8 +254,6 @@ void dispatch_command(const char* topic, const char* payload)
|
|||||||
|
|
||||||
// } else if(strcasecmp_P(topic, PSTR("screenshot")) == 0) {
|
// } else if(strcasecmp_P(topic, PSTR("screenshot")) == 0) {
|
||||||
// guiTakeScreenshot("/screenshot.bmp"); // Literal String
|
// guiTakeScreenshot("/screenshot.bmp"); // Literal String
|
||||||
} else if((topic[0] == 'p' || topic[0] == 'P') && dispatch_parse_button_attribute(topic, payload)) {
|
|
||||||
return; // matched pxby.attr
|
|
||||||
|
|
||||||
#if HASP_USE_CONFIG > 0
|
#if HASP_USE_CONFIG > 0
|
||||||
|
|
||||||
@ -293,8 +289,6 @@ void dispatch_command(const char* topic, const char* payload)
|
|||||||
// Strip command/config prefix from the topic and process the payload
|
// Strip command/config prefix from the topic and process the payload
|
||||||
void dispatch_topic_payload(const char* topic, const char* payload)
|
void dispatch_topic_payload(const char* topic, const char* payload)
|
||||||
{
|
{
|
||||||
// LOG_VERBOSE(TAG_MSGR,F("TOPIC: short topic: %s"), topic);
|
|
||||||
|
|
||||||
if(!strcmp_P(topic, PSTR("command"))) {
|
if(!strcmp_P(topic, PSTR("command"))) {
|
||||||
dispatch_text_line((char*)payload);
|
dispatch_text_line((char*)payload);
|
||||||
return;
|
return;
|
||||||
@ -307,7 +301,7 @@ void dispatch_topic_payload(const char* topic, const char* payload)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if HASP_USE_CONFIG > 0
|
#if HASP_USE_CONFIG > 0
|
||||||
if(topic == strstr_P(topic, PSTR("config/"))) { // startsWith command/
|
if(topic == strstr_P(topic, PSTR("config/"))) { // startsWith config/
|
||||||
topic += 7u;
|
topic += 7u;
|
||||||
dispatch_config(topic, (char*)payload);
|
dispatch_config(topic, (char*)payload);
|
||||||
return;
|
return;
|
||||||
@ -354,31 +348,6 @@ void dispatch_text_line(const char* cmnd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatch_get_idle_state(uint8_t state, char* payload)
|
|
||||||
{
|
|
||||||
switch(state) {
|
|
||||||
case HASP_SLEEP_LONG:
|
|
||||||
memcpy_P(payload, PSTR("long"), 5);
|
|
||||||
break;
|
|
||||||
case HASP_SLEEP_SHORT:
|
|
||||||
memcpy_P(payload, PSTR("short"), 6);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
memcpy_P(payload, PSTR("off"), 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// send idle state to the client
|
|
||||||
void dispatch_output_idle_state(uint8_t state)
|
|
||||||
{
|
|
||||||
char topic[6];
|
|
||||||
char payload[6];
|
|
||||||
memcpy_P(topic, PSTR("idle"), 5);
|
|
||||||
|
|
||||||
dispatch_get_idle_state(state, payload);
|
|
||||||
dispatch_state_subtopic(topic, payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
// void dispatch_output_group_state(uint8_t groupid, uint16_t state)
|
// void dispatch_output_group_state(uint8_t groupid, uint16_t state)
|
||||||
// {
|
// {
|
||||||
// char payload[64];
|
// char payload[64];
|
||||||
@ -652,7 +621,7 @@ void dispatch_parse_jsonl(const char*, const char* payload)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatch_output_current_page()
|
void dispatch_current_page()
|
||||||
{
|
{
|
||||||
char topic[8];
|
char topic[8];
|
||||||
char payload[8];
|
char payload[8];
|
||||||
@ -666,19 +635,19 @@ void dispatch_output_current_page()
|
|||||||
void dispatch_page_next(lv_scr_load_anim_t animation)
|
void dispatch_page_next(lv_scr_load_anim_t animation)
|
||||||
{
|
{
|
||||||
haspPages.next(animation);
|
haspPages.next(animation);
|
||||||
dispatch_output_current_page();
|
dispatch_current_page();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatch_page_prev(lv_scr_load_anim_t animation)
|
void dispatch_page_prev(lv_scr_load_anim_t animation)
|
||||||
{
|
{
|
||||||
haspPages.prev(animation);
|
haspPages.prev(animation);
|
||||||
dispatch_output_current_page();
|
dispatch_current_page();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatch_page_back(lv_scr_load_anim_t animation)
|
void dispatch_page_back(lv_scr_load_anim_t animation)
|
||||||
{
|
{
|
||||||
haspPages.back(animation);
|
haspPages.back(animation);
|
||||||
dispatch_output_current_page();
|
dispatch_current_page();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatch_set_page(uint8_t pageid)
|
void dispatch_set_page(uint8_t pageid)
|
||||||
@ -689,13 +658,13 @@ void dispatch_set_page(uint8_t pageid)
|
|||||||
void dispatch_set_page(uint8_t pageid, lv_scr_load_anim_t animation)
|
void dispatch_set_page(uint8_t pageid, lv_scr_load_anim_t animation)
|
||||||
{
|
{
|
||||||
haspPages.set(pageid, animation);
|
haspPages.set(pageid, animation);
|
||||||
dispatch_output_current_page();
|
dispatch_current_page();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatch_page(const char*, const char* page)
|
void dispatch_page(const char*, const char* page)
|
||||||
{
|
{
|
||||||
if(strlen(page) == 0) {
|
if(strlen(page) == 0) {
|
||||||
dispatch_output_current_page(); // No payload, send current page
|
dispatch_current_page(); // No payload, send current page
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -867,9 +836,9 @@ void dispatch_reboot(bool saveConfig)
|
|||||||
|
|
||||||
void dispatch_current_state()
|
void dispatch_current_state()
|
||||||
{
|
{
|
||||||
dispatch_output_statusupdate(NULL, NULL);
|
dispatch_statusupdate(NULL, NULL);
|
||||||
dispatch_output_idle_state(hasp_sleep_state);
|
dispatch_idle(NULL, NULL);
|
||||||
dispatch_output_current_page();
|
dispatch_current_page();
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************* Command Wrapper Functions *********************************/
|
/******************************************* Command Wrapper Functions *********************************/
|
||||||
@ -917,7 +886,7 @@ void dispatch_send_discovery(const char*, const char*)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Periodically publish a JSON string indicating system status
|
// Periodically publish a JSON string indicating system status
|
||||||
void dispatch_output_statusupdate(const char*, const char*)
|
void dispatch_statusupdate(const char*, const char*)
|
||||||
{
|
{
|
||||||
#if HASP_USE_MQTT > 0
|
#if HASP_USE_MQTT > 0
|
||||||
|
|
||||||
@ -926,8 +895,8 @@ void dispatch_output_statusupdate(const char*, const char*)
|
|||||||
{
|
{
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
|
|
||||||
|
hasp_get_sleep_state(topic);
|
||||||
haspGetVersion(buffer, sizeof(buffer));
|
haspGetVersion(buffer, sizeof(buffer));
|
||||||
dispatch_get_idle_state(hasp_sleep_state, topic);
|
|
||||||
snprintf_P(data, sizeof(data), PSTR("{\"node\":\"%s\",\"idle\":\"%s\",\"version\":\"%s\",\"uptime\":%lu,"),
|
snprintf_P(data, sizeof(data), PSTR("{\"node\":\"%s\",\"idle\":\"%s\",\"version\":\"%s\",\"uptime\":%lu,"),
|
||||||
haspDevice.get_hostname(), topic, buffer, long(millis() / 1000)); // \"status\":\"available\",
|
haspDevice.get_hostname(), topic, buffer, long(millis() / 1000)); // \"status\":\"available\",
|
||||||
|
|
||||||
@ -987,6 +956,16 @@ void dispatch_sleep(const char*, const char*)
|
|||||||
hasp_enable_wakeup_touch();
|
hasp_enable_wakeup_touch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dispatch_idle(const char*, const char*)
|
||||||
|
{
|
||||||
|
char topic[6];
|
||||||
|
char payload[6];
|
||||||
|
memcpy_P(topic, PSTR("idle"), 5);
|
||||||
|
|
||||||
|
hasp_get_sleep_state(payload);
|
||||||
|
dispatch_state_subtopic(topic, payload);
|
||||||
|
}
|
||||||
|
|
||||||
void dispatch_reboot(const char*, const char*)
|
void dispatch_reboot(const char*, const char*)
|
||||||
{
|
{
|
||||||
dispatch_reboot(true);
|
dispatch_reboot(true);
|
||||||
@ -1024,10 +1003,11 @@ void dispatchSetup()
|
|||||||
dispatch_add_command(PSTR("page"), dispatch_page);
|
dispatch_add_command(PSTR("page"), dispatch_page);
|
||||||
dispatch_add_command(PSTR("wakeup"), dispatch_wakeup);
|
dispatch_add_command(PSTR("wakeup"), dispatch_wakeup);
|
||||||
dispatch_add_command(PSTR("sleep"), dispatch_sleep);
|
dispatch_add_command(PSTR("sleep"), dispatch_sleep);
|
||||||
dispatch_add_command(PSTR("statusupdate"), dispatch_output_statusupdate);
|
dispatch_add_command(PSTR("statusupdate"), dispatch_statusupdate);
|
||||||
dispatch_add_command(PSTR("clearpage"), dispatch_clear_page);
|
dispatch_add_command(PSTR("clearpage"), dispatch_clear_page);
|
||||||
dispatch_add_command(PSTR("jsonl"), dispatch_parse_jsonl);
|
dispatch_add_command(PSTR("jsonl"), dispatch_parse_jsonl);
|
||||||
dispatch_add_command(PSTR("dim"), dispatch_dim);
|
dispatch_add_command(PSTR("dim"), dispatch_dim);
|
||||||
|
dispatch_add_command(PSTR("idle"), dispatch_idle);
|
||||||
dispatch_add_command(PSTR("brightness"), dispatch_dim);
|
dispatch_add_command(PSTR("brightness"), dispatch_dim);
|
||||||
dispatch_add_command(PSTR("light"), dispatch_backlight);
|
dispatch_add_command(PSTR("light"), dispatch_backlight);
|
||||||
dispatch_add_command(PSTR("moodlight"), dispatch_moodlight);
|
dispatch_add_command(PSTR("moodlight"), dispatch_moodlight);
|
||||||
@ -1053,7 +1033,7 @@ void dispatchEverySecond()
|
|||||||
{
|
{
|
||||||
if(dispatch_setings.teleperiod > 0 && (millis() - dispatchLastMillis) >= dispatch_setings.teleperiod * 1000) {
|
if(dispatch_setings.teleperiod > 0 && (millis() - dispatchLastMillis) >= dispatch_setings.teleperiod * 1000) {
|
||||||
dispatchLastMillis += dispatch_setings.teleperiod * 1000;
|
dispatchLastMillis += dispatch_setings.teleperiod * 1000;
|
||||||
dispatch_output_statusupdate(NULL, NULL);
|
dispatch_statusupdate(NULL, NULL);
|
||||||
dispatch_send_discovery(NULL, NULL);
|
dispatch_send_discovery(NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1068,7 +1048,7 @@ void everySecond()
|
|||||||
|
|
||||||
if(elapsed.count() >= dispatch_setings.teleperiod) {
|
if(elapsed.count() >= dispatch_setings.teleperiod) {
|
||||||
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
||||||
dispatch_output_statusupdate(NULL, NULL);
|
dispatch_statusupdate(NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,10 +58,11 @@ void dispatch_backlight(const char*, const char* payload);
|
|||||||
void dispatch_web_update(const char*, const char* espOtaUrl);
|
void dispatch_web_update(const char*, const char* espOtaUrl);
|
||||||
void dispatch_reboot(bool saveConfig);
|
void dispatch_reboot(bool saveConfig);
|
||||||
|
|
||||||
void dispatch_output_idle_state(uint8_t state);
|
void dispatch_statusupdate(const char*, const char*);
|
||||||
void dispatch_output_statusupdate(const char*, const char*);
|
void dispatch_idle(const char*, const char*);
|
||||||
|
|
||||||
void dispatch_current_state();
|
void dispatch_current_state();
|
||||||
void dispatch_output_current_page();
|
void dispatch_current_page();
|
||||||
|
|
||||||
void dispatch_gpio_input_event(uint8_t pin, uint8_t group, uint8_t eventid);
|
void dispatch_gpio_input_event(uint8_t pin, uint8_t group, uint8_t eventid);
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ void swipe_event_handler(lv_obj_t* obj, lv_event_t event)
|
|||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dispatch_output_current_page();
|
dispatch_current_page();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,7 +336,7 @@ void generic_event_handler(lv_obj_t* obj, lv_event_t event)
|
|||||||
default:
|
default:
|
||||||
haspPages.set(obj->user_data.actionid, transitionid);
|
haspPages.set(obj->user_data.actionid, transitionid);
|
||||||
}
|
}
|
||||||
dispatch_output_current_page();
|
dispatch_current_page();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char data[40];
|
char data[40];
|
||||||
|
@ -104,7 +104,7 @@ static inline void debug_flush()
|
|||||||
void debugEverySecond()
|
void debugEverySecond()
|
||||||
{
|
{
|
||||||
// if(debugTelePeriod > 0 && (millis() - debugLastMillis) >= debugTelePeriod * 1000) {
|
// if(debugTelePeriod > 0 && (millis() - debugLastMillis) >= debugTelePeriod * 1000) {
|
||||||
// dispatch_output_statusupdate(NULL, NULL);
|
// dispatch_statusupdate(NULL, NULL);
|
||||||
// debugLastMillis = millis();
|
// debugLastMillis = millis();
|
||||||
// }
|
// }
|
||||||
// printLocalTime();
|
// printLocalTime();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user