mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Bug fix in clearpage and code cleanup
This commit is contained in:
parent
7676fa3d0f
commit
377fa31a9b
@ -100,14 +100,6 @@ 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
|
||||
*/
|
||||
@ -529,7 +521,7 @@ void haspGetVersion(char * version, size_t len)
|
||||
void haspClearPage(uint16_t pageid)
|
||||
{
|
||||
lv_obj_t * page = get_page_obj(pageid);
|
||||
if(!page || pageid > (pageid > sizeof pages / sizeof *pages)) {
|
||||
if(!page || (pageid > HASP_NUM_PAGES)) {
|
||||
Log.warning(TAG_HASP, F("Invalid page %u"), pageid);
|
||||
} else if(page == lv_layer_sys() /*|| page == lv_layer_top()*/) {
|
||||
Log.warning(TAG_HASP, F("Cannot clear system layer"));
|
||||
|
@ -73,7 +73,6 @@ lv_font_t * hasp_get_font(uint8_t fontid);
|
||||
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);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
@ -32,6 +32,7 @@
|
||||
#endif
|
||||
|
||||
extern unsigned long debugLastMillis; // UpdateStatus timer
|
||||
extern uint8_t hasp_sleep_state;
|
||||
|
||||
uint8_t nCommands = 0;
|
||||
haspCommand_t commands[16];
|
||||
@ -81,39 +82,48 @@ inline void dispatch_process_button_attribute(String strTopic, const char * payl
|
||||
{
|
||||
// Log.verbose(TAG_MSGR,F("BTN ATTR: %s = %s"), strTopic.c_str(), payload);
|
||||
|
||||
String strPageId((char *)0);
|
||||
String strTemp((char *)0);
|
||||
unsigned int pageid, objid;
|
||||
const char * topic_p = strTopic.c_str();
|
||||
|
||||
strPageId = strTopic.substring(2, strTopic.indexOf("]"));
|
||||
strTemp = strTopic.substring(strTopic.indexOf("]") + 1, strTopic.length());
|
||||
if(sscanf(topic_p, "p%ub%u.", &pageid, &objid) == 2) { // Literal String
|
||||
|
||||
if(strTemp.startsWith(".b[")) {
|
||||
String strObjId((char *)0);
|
||||
String strAttr((char *)0);
|
||||
// OK, continue below
|
||||
|
||||
strObjId = strTemp.substring(3, strTemp.indexOf("]"));
|
||||
strAttr = strTemp.substring(strTemp.indexOf("]") + 1, strTemp.length());
|
||||
// debugPrintln(strPageId + " && " + strObjId + " && " + strAttr);
|
||||
} else if(sscanf(topic_p, "p[%u]b[%u].", &pageid, &objid) == 2) { // Literal String
|
||||
|
||||
int pageid = strPageId.toInt();
|
||||
int objid = strObjId.toInt();
|
||||
|
||||
if(pageid >= 0 && pageid <= 255 && objid >= 0 && objid <= 255) {
|
||||
hasp_process_attribute((uint8_t)pageid, (uint8_t)objid, strAttr.c_str(), payload);
|
||||
} // valid page
|
||||
// TODO: obsolete old syntax p[x].b[]y
|
||||
// OK, continue below
|
||||
|
||||
} else {
|
||||
|
||||
unsigned int pageid, objid;
|
||||
const char * topic_p = strTopic.c_str();
|
||||
|
||||
if(sscanf(topic_p, "p%ub%u.", &pageid, &objid) == 2) { // Literal String
|
||||
while(*topic_p++ != '.') {
|
||||
// strip to '.' character
|
||||
}
|
||||
hasp_process_attribute((uint8_t)pageid, (uint8_t)objid, topic_p, payload);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
while(*topic_p++ != '.') {
|
||||
// strip to '.' character
|
||||
}
|
||||
hasp_process_attribute((uint8_t)pageid, (uint8_t)objid, topic_p, payload);
|
||||
|
||||
// String strPageId((char *)0);
|
||||
// String strTemp((char *)0);
|
||||
|
||||
// strPageId = strTopic.substring(2, strTopic.indexOf("]"));
|
||||
// strTemp = strTopic.substring(strTopic.indexOf("]") + 1, strTopic.length());
|
||||
|
||||
// if(strTemp.startsWith(".b[")) {
|
||||
// String strObjId((char *)0);
|
||||
// String strAttr((char *)0);
|
||||
|
||||
// strObjId = strTemp.substring(3, strTemp.indexOf("]"));
|
||||
// strAttr = strTemp.substring(strTemp.indexOf("]") + 1, strTemp.length());
|
||||
// // debugPrintln(strPageId + " && " + strObjId + " && " + strAttr);
|
||||
|
||||
// pageid = strPageId.toInt();
|
||||
// objid = strObjId.toInt();
|
||||
|
||||
// if(pageid >= 0 && pageid <= 255 && objid >= 0 && objid <= 255) {
|
||||
// hasp_process_attribute(pageid, objid, strAttr.c_str(), payload);
|
||||
// } // valid page
|
||||
// }
|
||||
}
|
||||
|
||||
// objectattribute=value
|
||||
@ -398,11 +408,11 @@ bool dispatch_get_event_state(uint8_t eventid)
|
||||
case HASP_EVENT_LONG:
|
||||
case HASP_EVENT_HOLD:
|
||||
return true;
|
||||
case HASP_EVENT_OFF:
|
||||
case HASP_EVENT_UP:
|
||||
case HASP_EVENT_SHORT:
|
||||
case HASP_EVENT_DOUBLE:
|
||||
case HASP_EVENT_LOST:
|
||||
// case HASP_EVENT_OFF:
|
||||
// case HASP_EVENT_UP:
|
||||
// case HASP_EVENT_SHORT:
|
||||
// case HASP_EVENT_DOUBLE:
|
||||
// case HASP_EVENT_LOST:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -742,6 +752,13 @@ void dispatch_reboot(bool saveConfig)
|
||||
halRestartMcu();
|
||||
}
|
||||
|
||||
void dispatch_current_state()
|
||||
{
|
||||
dispatch_output_current_page();
|
||||
dispatch_output_statusupdate(NULL, NULL);
|
||||
dispatch_output_idle_state(hasp_sleep_state);
|
||||
}
|
||||
|
||||
/******************************************* Command Wrapper Functions *********************************/
|
||||
|
||||
// Periodically publish a JSON string indicating system status
|
||||
@ -791,14 +808,15 @@ void dispatch_output_statusupdate(const char *, const char *)
|
||||
#endif
|
||||
}
|
||||
|
||||
void dispatch_calibrate(const char *, const char *)
|
||||
void dispatch_calibrate(const char * topic = NULL, const char * payload = NULL)
|
||||
{
|
||||
guiCalibrate();
|
||||
}
|
||||
|
||||
void dispatch_wakeup(const char *, const char *)
|
||||
{
|
||||
hasp_wakeup();
|
||||
dispatch_calibrate();
|
||||
lv_disp_trig_activity(NULL);
|
||||
}
|
||||
|
||||
void dispatch_reboot(const char *, const char *)
|
||||
@ -855,7 +873,7 @@ void dispatchSetup()
|
||||
/* WARNING: remember to expand the commands array when adding new commands */
|
||||
}
|
||||
|
||||
void IRAM_ATTR dispatchLoop()
|
||||
void dispatchLoop()
|
||||
{
|
||||
// Not used
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ enum hasp_event_t { // even = released, odd = pressed
|
||||
|
||||
/* ===== Default Event Processors ===== */
|
||||
void dispatchSetup(void);
|
||||
void IRAM_ATTR dispatchLoop(void);
|
||||
void dispatchLoop(void);
|
||||
void dispatchEverySecond(void);
|
||||
void dispatchStart(void);
|
||||
void dispatchStop(void);
|
||||
@ -45,7 +45,7 @@ void dispatch_reboot(bool saveConfig);
|
||||
|
||||
void dispatch_output_idle_state(uint8_t state);
|
||||
void dispatch_output_statusupdate(const char *, const char *);
|
||||
void dispatch_output_current_page();
|
||||
void dispatch_current_state();
|
||||
|
||||
void dispatch_gpio_input_event(uint8_t pin, uint8_t group, uint8_t eventid);
|
||||
void dispatch_object_event(lv_obj_t * obj, uint8_t eventid);
|
||||
@ -59,7 +59,7 @@ void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char *
|
||||
void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char * attribute, int32_t val);
|
||||
void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char * attribute, uint8_t r, uint8_t g,
|
||||
uint8_t b);
|
||||
|
||||
|
||||
/* ===== Getter and Setter Functions ===== */
|
||||
|
||||
/* ===== Read/Write Configuration ===== */
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "PubSubClient.h"
|
||||
|
||||
#include "hasp/hasp.h"
|
||||
#include "hasp_mqtt.h"
|
||||
#include "hasp_mqtt_ha.h"
|
||||
|
||||
@ -38,8 +39,6 @@ EthernetClient mqttNetworkClient;
|
||||
#include "hasp_config.h"
|
||||
|
||||
#include "../hasp/hasp_dispatch.h"
|
||||
#include "../hasp/hasp.h" // for hasp_sleep_state
|
||||
extern uint8_t hasp_sleep_state;
|
||||
|
||||
#ifdef USE_CONFIG_OVERRIDE
|
||||
#include "user_config_override.h"
|
||||
@ -115,13 +114,6 @@ static bool mqttPublish(const char * topic, const char * payload, bool retain =
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Send changed values OUT
|
||||
|
||||
void mqtt_send_current_states()
|
||||
{
|
||||
dispatch_output_current_page();
|
||||
dispatch_output_statusupdate(NULL, NULL);
|
||||
dispatch_output_idle_state(hasp_sleep_state);
|
||||
}
|
||||
|
||||
bool IRAM_ATTR mqttIsConnected()
|
||||
{
|
||||
return mqttEnabled && mqttClient.connected();
|
||||
@ -179,7 +171,7 @@ static void mqtt_message_cb(char * topic, byte * payload, unsigned int length)
|
||||
|
||||
} else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic
|
||||
if(mqttHAautodiscover && !strcasecmp_P((char *)payload, PSTR("online"))) {
|
||||
mqtt_send_current_states();
|
||||
dispatch_current_state();
|
||||
mqtt_ha_send_backlight();
|
||||
}
|
||||
return;
|
||||
@ -253,13 +245,13 @@ void mqttStart()
|
||||
|
||||
switch(mqttClient.state()) {
|
||||
case MQTT_CONNECTION_TIMEOUT:
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("Network connection timeout"));
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("Connection timeout"));
|
||||
break;
|
||||
case MQTT_CONNECTION_LOST:
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("Network connection lost"));
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("Connection lost"));
|
||||
break;
|
||||
case MQTT_CONNECT_FAILED:
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("Network connection failed"));
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("Connection failed"));
|
||||
break;
|
||||
case MQTT_DISCONNECTED:
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("Disconnected"));
|
||||
@ -267,10 +259,10 @@ void mqttStart()
|
||||
case MQTT_CONNECTED:
|
||||
break;
|
||||
case MQTT_CONNECT_BAD_PROTOCOL:
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("Server doesn't support the requested version of MQTT"));
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("MQTT version not suported"));
|
||||
break;
|
||||
case MQTT_CONNECT_BAD_CLIENT_ID:
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("Server rejected the client ID"));
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("Client ID rejected"));
|
||||
break;
|
||||
case MQTT_CONNECT_UNAVAILABLE:
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("Server unavailable"));
|
||||
@ -319,7 +311,7 @@ void mqttStart()
|
||||
haspReconnect();
|
||||
haspProgressVal(255);
|
||||
|
||||
mqtt_send_current_states();
|
||||
dispatch_current_state();
|
||||
}
|
||||
|
||||
void mqttSetup()
|
||||
|
@ -159,7 +159,7 @@ void mqtt_ha_register_backlight()
|
||||
// doc[F("brightness")] = true;
|
||||
doc[F("bri_scl")] = 100;
|
||||
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("hasp_%s-backlight"), halGetMacAddress(0, "").c_str(), mqttNodeName);
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("hasp_%s-backlight"), halGetMacAddress(0, "").c_str());
|
||||
doc[F("uniq_id")] = buffer;
|
||||
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("%s/light/%s/backlight/config"), discovery_prefix, mqttNodeName);
|
||||
@ -184,11 +184,11 @@ void mqtt_ha_register_moodlight()
|
||||
doc[F("avty_t")] = F("~LWT");
|
||||
doc[F("bri_stat_t")] = F("~state/moodlight/dim");
|
||||
doc[F("bri_cmd_t")] = F("~command/moodlight/dim");
|
||||
//doc[F("rgb")] = true;
|
||||
doc[F("bri_scl")] = 100;
|
||||
// doc[F("rgb")] = true;
|
||||
doc[F("bri_scl")] = 100;
|
||||
|
||||
doc[F("rgb_stat_t")] = F("~state/moodlight/rgb");
|
||||
doc[F("rgb_cmd_t")] = F("~command/moodlight/rgb");
|
||||
doc[F("rgb_stat_t")] = F("~state/moodlight/rgb");
|
||||
doc[F("rgb_cmd_t")] = F("~command/moodlight/rgb");
|
||||
// doc[F("state_value_template")] = F("~command/moodlight/light");
|
||||
// doc[F("brightness_value_template")] = F("{{ value_json.brightness }}");
|
||||
// doc[F("rgb_command_template")] = F("{{ '%02x%02x%02x0000'| format(red, green, blue) }}");
|
||||
@ -215,7 +215,7 @@ void mqtt_ha_register_idle()
|
||||
doc[F("avty_t")] = F("~LWT");
|
||||
doc[F("json_attr_t")] = F("~state/statusupdate");
|
||||
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("hasp_%s-idlestate"), halGetMacAddress(0, "").c_str(), mqttNodeName);
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("hasp_%s-idlestate"), halGetMacAddress(0, "").c_str());
|
||||
doc[F("uniq_id")] = buffer;
|
||||
|
||||
// "value_template" : "{{ value | capitalize }}",
|
||||
|
Loading…
x
Reference in New Issue
Block a user