mirror of
https://github.com/HASwitchPlate/HASPone.git
synced 2025-07-28 05:36:36 +00:00
Align button disabled events with project
This commit is contained in:
parent
8052c8c6e2
commit
38b8615492
@ -131,7 +131,6 @@ String mqttLightStateTopic; // MQTT topic for outgoing
|
|||||||
String mqttLightBrightCommandTopic; // MQTT topic for incoming panel backlight dimmer commands
|
String mqttLightBrightCommandTopic; // MQTT topic for incoming panel backlight dimmer commands
|
||||||
String mqttLightBrightStateTopic; // MQTT topic for outgoing panel backlight dimmer state
|
String mqttLightBrightStateTopic; // MQTT topic for outgoing panel backlight dimmer state
|
||||||
String mqttMotionStateTopic; // MQTT topic for outgoing motion sensor state
|
String mqttMotionStateTopic; // MQTT topic for outgoing motion sensor state
|
||||||
String mqttEventWhileScreenOffTopic; // MQTT topic for dropped outgoing panel interactions
|
|
||||||
String nextionModel; // Record reported model number of LCD panel
|
String nextionModel; // Record reported model number of LCD panel
|
||||||
const byte nextionSuffix[] = {0xFF, 0xFF, 0xFF}; // Standard suffix for Nextion commands
|
const byte nextionSuffix[] = {0xFF, 0xFF, 0xFF}; // Standard suffix for Nextion commands
|
||||||
uint32_t tftFileSize = 0; // Filesize for TFT firmware upload
|
uint32_t tftFileSize = 0; // Filesize for TFT firmware upload
|
||||||
@ -219,7 +218,9 @@ void setup()
|
|||||||
webServer.on("/firmware", webHandleFirmware);
|
webServer.on("/firmware", webHandleFirmware);
|
||||||
webServer.on("/espfirmware", webHandleEspFirmware);
|
webServer.on("/espfirmware", webHandleEspFirmware);
|
||||||
webServer.on(
|
webServer.on(
|
||||||
"/lcdupload", HTTP_POST, []() { webServer.send(200); }, webHandleLcdUpload);
|
"/lcdupload", HTTP_POST, []()
|
||||||
|
{ webServer.send(200); },
|
||||||
|
webHandleLcdUpload);
|
||||||
webServer.on("/tftFileSize", webHandleTftFileSize);
|
webServer.on("/tftFileSize", webHandleTftFileSize);
|
||||||
webServer.on("/lcddownload", webHandleLcdDownload);
|
webServer.on("/lcddownload", webHandleLcdDownload);
|
||||||
webServer.on("/lcdOtaSuccess", webHandleLcdUpdateSuccess);
|
webServer.on("/lcdOtaSuccess", webHandleLcdUpdateSuccess);
|
||||||
@ -378,7 +379,6 @@ void mqttConnect()
|
|||||||
mqttLightBrightCommandTopic = "hasp/" + String(haspNode) + "/brightness/set";
|
mqttLightBrightCommandTopic = "hasp/" + String(haspNode) + "/brightness/set";
|
||||||
mqttLightBrightStateTopic = "hasp/" + String(haspNode) + "/brightness/state";
|
mqttLightBrightStateTopic = "hasp/" + String(haspNode) + "/brightness/state";
|
||||||
mqttMotionStateTopic = "hasp/" + String(haspNode) + "/motion/state";
|
mqttMotionStateTopic = "hasp/" + String(haspNode) + "/motion/state";
|
||||||
mqttEventWhileScreenOffTopic = "hasp/" + String(haspNode) + "/eventwhilescreenoff";
|
|
||||||
|
|
||||||
const String mqttCommandSubscription = mqttCommandTopic + "/#";
|
const String mqttCommandSubscription = mqttCommandTopic + "/#";
|
||||||
const String mqttGroupCommandSubscription = mqttGroupCommandTopic + "/#";
|
const String mqttGroupCommandSubscription = mqttGroupCommandTopic + "/#";
|
||||||
@ -774,7 +774,7 @@ void mqttDiscovery()
|
|||||||
|
|
||||||
// AlwaysOn topic for RGB lights
|
// AlwaysOn topic for RGB lights
|
||||||
mqttClient.publish((String(F("hasp/")) + String(haspNode) + String(F("/alwayson"))), "ON", true, 1);
|
mqttClient.publish((String(F("hasp/")) + String(haspNode) + String(F("/alwayson"))), "ON", true, 1);
|
||||||
debugPrintln(String(F("MQTT OUT: 'hasp/"))+ String(haspNode) + String(F("/alwayson' : 'ON'")));
|
debugPrintln(String(F("MQTT OUT: 'hasp/")) + String(haspNode) + String(F("/alwayson' : 'ON'")));
|
||||||
|
|
||||||
// rgb light discovery for selectedforegroundcolor
|
// rgb light discovery for selectedforegroundcolor
|
||||||
mqttDiscoveryTopic = String(F("homeassistant/light/")) + String(haspNode) + String(F("/selectedforegroundcolor/config"));
|
mqttDiscoveryTopic = String(F("homeassistant/light/")) + String(haspNode) + String(F("/selectedforegroundcolor/config"));
|
||||||
@ -874,15 +874,7 @@ void nextionProcessInput()
|
|||||||
|
|
||||||
debugPrintln(String(F("HMI IN: [")) + String(nextionReturnIndex) + String(F(" bytes]: ")) + printHex8(nextionReturnBuffer, nextionReturnIndex));
|
debugPrintln(String(F("HMI IN: [")) + String(nextionReturnIndex) + String(F(" bytes]: ")) + printHex8(nextionReturnBuffer, nextionReturnIndex));
|
||||||
|
|
||||||
// only process touch events if screen backlight is on and configured to do so. otherwise drop it and send a
|
if (nextionReturnBuffer[0] == 0x00 && nextionReturnBuffer[1] == 0x00 && nextionReturnBuffer[2] == 0x00)
|
||||||
// message to mqtt so HA can determine what to do. 0x65 seems to be the only event type that needs to be dropped
|
|
||||||
if (ignoreTouchWhenOff && !lcdBacklightOn && nextionReturnBuffer[0] == 0x65)
|
|
||||||
{ // screen backlight off, send msg to ha.
|
|
||||||
String mqttButtonEvent = "Touch event dropped per configuration as the backlight off";
|
|
||||||
mqttClient.publish(mqttEventWhileScreenOffTopic, mqttButtonEvent);
|
|
||||||
debugPrintln(String(F("MQTT OUT: '")) + mqttEventWhileScreenOffTopic + String(F("' : '")) + mqttButtonEvent + String(F("'")));
|
|
||||||
}
|
|
||||||
else if (nextionReturnBuffer[0] == 0x00 && nextionReturnBuffer[1] == 0x00 && nextionReturnBuffer[2] == 0x00)
|
|
||||||
{ // Nextion Startup
|
{ // Nextion Startup
|
||||||
debugPrintln(String(F("HMI IN: [Nextion Startup] 0x00 0x00 0x00")));
|
debugPrintln(String(F("HMI IN: [Nextion Startup] 0x00 0x00 0x00")));
|
||||||
if (mqttClient.connected())
|
if (mqttClient.connected())
|
||||||
@ -1089,12 +1081,22 @@ void nextionProcessInput()
|
|||||||
debugPrintln(String(F("HMI IN: [Button ON] 'p[")) + nextionPage + "].b[" + nextionButtonID + "]'");
|
debugPrintln(String(F("HMI IN: [Button ON] 'p[")) + nextionPage + "].b[" + nextionButtonID + "]'");
|
||||||
if (mqttClient.connected())
|
if (mqttClient.connected())
|
||||||
{
|
{
|
||||||
String mqttButtonTopic = mqttStateTopic + "/p[" + nextionPage + "].b[" + nextionButtonID + "]";
|
// Only process touch events if screen backlight is on and configured to do so.
|
||||||
mqttClient.publish(mqttButtonTopic, "ON");
|
if (ignoreTouchWhenOff && !lcdBacklightOn)
|
||||||
debugPrintln(String(F("MQTT OUT: '")) + mqttButtonTopic + "' : 'ON'");
|
{
|
||||||
String mqttButtonJSONEvent = String(F("{\"event_type\":\"button_short_press\",\"event\":\"p[")) + nextionPage + String(F("].b[")) + nextionButtonID + String(F("]\",\"value\":\"ON\"}"));
|
String mqttButtonJSONEvent = String(F("{\"event_type\":\"button_press_disabled\",\"event\":\"p[")) + nextionPage + String(F("].b[")) + nextionButtonID + String(F("]\",\"value\":\"ON\"}"));
|
||||||
mqttClient.publish(mqttStateJSONTopic, mqttButtonJSONEvent);
|
mqttClient.publish(mqttStateJSONTopic, mqttButtonJSONEvent);
|
||||||
debugPrintln(String(F("MQTT OUT: '")) + mqttStateJSONTopic + String(F("' : '")) + mqttButtonJSONEvent + String(F("'")));
|
debugPrintln(String(F("MQTT OUT: '")) + mqttStateJSONTopic + String(F("' : '")) + mqttButtonJSONEvent + String(F("'")));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String mqttButtonTopic = mqttStateTopic + "/p[" + nextionPage + "].b[" + nextionButtonID + "]";
|
||||||
|
mqttClient.publish(mqttButtonTopic, "ON");
|
||||||
|
debugPrintln(String(F("MQTT OUT: '")) + mqttButtonTopic + "' : 'ON'");
|
||||||
|
String mqttButtonJSONEvent = String(F("{\"event_type\":\"button_short_press\",\"event\":\"p[")) + nextionPage + String(F("].b[")) + nextionButtonID + String(F("]\",\"value\":\"ON\"}"));
|
||||||
|
mqttClient.publish(mqttStateJSONTopic, mqttButtonJSONEvent);
|
||||||
|
debugPrintln(String(F("MQTT OUT: '")) + mqttStateJSONTopic + String(F("' : '")) + mqttButtonJSONEvent + String(F("'")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (beepEnabled)
|
if (beepEnabled)
|
||||||
{
|
{
|
||||||
@ -1108,25 +1110,35 @@ void nextionProcessInput()
|
|||||||
espReset();
|
espReset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nextionButtonAction == 0x00)
|
else if (nextionButtonAction == 0x00)
|
||||||
{
|
{
|
||||||
debugPrintln(String(F("HMI IN: [Button OFF] 'p[")) + nextionPage + "].b[" + nextionButtonID + "]'");
|
debugPrintln(String(F("HMI IN: [Button OFF] 'p[")) + nextionPage + "].b[" + nextionButtonID + "]'");
|
||||||
if (mqttClient.connected())
|
if (mqttClient.connected())
|
||||||
{
|
{
|
||||||
String mqttButtonTopic = mqttStateTopic + "/p[" + nextionPage + "].b[" + nextionButtonID + "]";
|
// Only process touch events if screen backlight is on and configured to do so.
|
||||||
mqttClient.publish(mqttButtonTopic, "OFF");
|
if (ignoreTouchWhenOff && !lcdBacklightOn)
|
||||||
debugPrintln(String(F("MQTT OUT: '")) + mqttButtonTopic + "' : 'OFF'");
|
{
|
||||||
String mqttButtonJSONEvent = String(F("{\"event_type\":\"button_short_release\",\"event\":\"p[")) + nextionPage + String(F("].b[")) + nextionButtonID + String(F("]\",\"value\":\"OFF\"}"));
|
String mqttButtonJSONEvent = String(F("{\"event_type\":\"button_release_disabled\",\"event\":\"p[")) + nextionPage + String(F("].b[")) + nextionButtonID + String(F("]\",\"value\":\"ON\"}"));
|
||||||
mqttClient.publish(mqttStateJSONTopic, mqttButtonJSONEvent);
|
mqttClient.publish(mqttStateJSONTopic, mqttButtonJSONEvent);
|
||||||
debugPrintln(String(F("MQTT OUT: '")) + mqttStateJSONTopic + String(F("' : '")) + mqttButtonJSONEvent + String(F("'")));
|
debugPrintln(String(F("MQTT OUT: '")) + mqttStateJSONTopic + String(F("' : '")) + mqttButtonJSONEvent + String(F("'")));
|
||||||
// Now see if this object has a .val that might have been updated. Works for sliders,
|
}
|
||||||
// two-state buttons, etc, returns 0 for normal buttons
|
else
|
||||||
mqttGetSubtopic = "/p[" + nextionPage + "].b[" + nextionButtonID + "].val";
|
{
|
||||||
mqttGetSubtopicJSON = "p[" + nextionPage + "].b[" + nextionButtonID + "].val";
|
String mqttButtonTopic = mqttStateTopic + "/p[" + nextionPage + "].b[" + nextionButtonID + "]";
|
||||||
// This right here is dicey. We're done w/ this command so reset the index allowing this to be kinda-reentrant
|
mqttClient.publish(mqttButtonTopic, "OFF");
|
||||||
// because the call to nextionGetAttr is going to call us back.
|
debugPrintln(String(F("MQTT OUT: '")) + mqttButtonTopic + "' : 'OFF'");
|
||||||
nextionReturnIndex = 0;
|
String mqttButtonJSONEvent = String(F("{\"event_type\":\"button_short_release\",\"event\":\"p[")) + nextionPage + String(F("].b[")) + nextionButtonID + String(F("]\",\"value\":\"OFF\"}"));
|
||||||
nextionGetAttr("p[" + nextionPage + "].b[" + nextionButtonID + "].val");
|
mqttClient.publish(mqttStateJSONTopic, mqttButtonJSONEvent);
|
||||||
|
debugPrintln(String(F("MQTT OUT: '")) + mqttStateJSONTopic + String(F("' : '")) + mqttButtonJSONEvent + String(F("'")));
|
||||||
|
// Now see if this object has a .val that might have been updated. Works for sliders,
|
||||||
|
// two-state buttons, etc, returns 0 for normal buttons
|
||||||
|
mqttGetSubtopic = "/p[" + nextionPage + "].b[" + nextionButtonID + "].val";
|
||||||
|
mqttGetSubtopicJSON = "p[" + nextionPage + "].b[" + nextionButtonID + "].val";
|
||||||
|
// This right here is dicey. We're done w/ this command so reset the index allowing this to be kinda-reentrant
|
||||||
|
// because the call to nextionGetAttr is going to call us back.
|
||||||
|
nextionReturnIndex = 0;
|
||||||
|
nextionGetAttr("p[" + nextionPage + "].b[" + nextionButtonID + "].val");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2010,39 +2022,41 @@ void espSetupOta()
|
|||||||
ArduinoOTA.setPassword(configPassword);
|
ArduinoOTA.setPassword(configPassword);
|
||||||
ArduinoOTA.setRebootOnSuccess(false);
|
ArduinoOTA.setRebootOnSuccess(false);
|
||||||
|
|
||||||
ArduinoOTA.onStart([]() {
|
ArduinoOTA.onStart([]()
|
||||||
debugPrintln(F("ESP OTA: update start"));
|
{
|
||||||
nextionSetAttr("p[0].b[1].txt", "\"\\rHASP update:\\r\\r\\r \"");
|
debugPrintln(F("ESP OTA: update start"));
|
||||||
nextionSendCmd("page 0");
|
nextionSetAttr("p[0].b[1].txt", "\"\\rHASP update:\\r\\r\\r \"");
|
||||||
nextionSendCmd("vis 4,1");
|
nextionSendCmd("page 0");
|
||||||
});
|
nextionSendCmd("vis 4,1");
|
||||||
ArduinoOTA.onEnd([]() {
|
});
|
||||||
debugPrintln(F("ESP OTA: update complete"));
|
ArduinoOTA.onEnd([]()
|
||||||
nextionSetAttr("p[0].b[1].txt", "\"\\rHASP update:\\r\\r Complete!\\rRestarting.\"");
|
{
|
||||||
nextionSendCmd("vis 4,1");
|
debugPrintln(F("ESP OTA: update complete"));
|
||||||
delay(1000);
|
nextionSetAttr("p[0].b[1].txt", "\"\\rHASP update:\\r\\r Complete!\\rRestarting.\"");
|
||||||
espReset();
|
nextionSendCmd("vis 4,1");
|
||||||
});
|
delay(1000);
|
||||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
espReset();
|
||||||
nextionUpdateProgress(progress, total);
|
});
|
||||||
});
|
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total)
|
||||||
ArduinoOTA.onError([](ota_error_t error) {
|
{ nextionUpdateProgress(progress, total); });
|
||||||
debugPrintln(String(F("ESP OTA: ERROR code ")) + String(error));
|
ArduinoOTA.onError([](ota_error_t error)
|
||||||
if (error == OTA_AUTH_ERROR)
|
{
|
||||||
debugPrintln(F("ESP OTA: ERROR - Auth Failed"));
|
debugPrintln(String(F("ESP OTA: ERROR code ")) + String(error));
|
||||||
else if (error == OTA_BEGIN_ERROR)
|
if (error == OTA_AUTH_ERROR)
|
||||||
debugPrintln(F("ESP OTA: ERROR - Begin Failed"));
|
debugPrintln(F("ESP OTA: ERROR - Auth Failed"));
|
||||||
else if (error == OTA_CONNECT_ERROR)
|
else if (error == OTA_BEGIN_ERROR)
|
||||||
debugPrintln(F("ESP OTA: ERROR - Connect Failed"));
|
debugPrintln(F("ESP OTA: ERROR - Begin Failed"));
|
||||||
else if (error == OTA_RECEIVE_ERROR)
|
else if (error == OTA_CONNECT_ERROR)
|
||||||
debugPrintln(F("ESP OTA: ERROR - Receive Failed"));
|
debugPrintln(F("ESP OTA: ERROR - Connect Failed"));
|
||||||
else if (error == OTA_END_ERROR)
|
else if (error == OTA_RECEIVE_ERROR)
|
||||||
debugPrintln(F("ESP OTA: ERROR - End Failed"));
|
debugPrintln(F("ESP OTA: ERROR - Receive Failed"));
|
||||||
nextionSendCmd("vis 4,0");
|
else if (error == OTA_END_ERROR)
|
||||||
nextionSetAttr("p[0].b[1].txt", "\"HASP update:\\r FAILED\\rerror: " + String(error) + "\"");
|
debugPrintln(F("ESP OTA: ERROR - End Failed"));
|
||||||
delay(1000);
|
nextionSendCmd("vis 4,0");
|
||||||
nextionSendCmd("page " + String(nextionActivePage));
|
nextionSetAttr("p[0].b[1].txt", "\"HASP update:\\r FAILED\\rerror: " + String(error) + "\"");
|
||||||
});
|
delay(1000);
|
||||||
|
nextionSendCmd("page " + String(nextionActivePage));
|
||||||
|
});
|
||||||
ArduinoOTA.begin();
|
ArduinoOTA.begin();
|
||||||
debugPrintln(F("ESP OTA: Over the Air firmware update ready"));
|
debugPrintln(F("ESP OTA: Over the Air firmware update ready"));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user