Align button disabled events with project

This commit is contained in:
aderusha 2021-06-27 10:31:54 -04:00
parent 8052c8c6e2
commit 38b8615492

View File

@ -131,7 +131,6 @@ String mqttLightStateTopic; // MQTT topic for outgoing
String mqttLightBrightCommandTopic; // MQTT topic for incoming panel backlight dimmer commands
String mqttLightBrightStateTopic; // MQTT topic for outgoing panel backlight dimmer 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
const byte nextionSuffix[] = {0xFF, 0xFF, 0xFF}; // Standard suffix for Nextion commands
uint32_t tftFileSize = 0; // Filesize for TFT firmware upload
@ -219,7 +218,9 @@ void setup()
webServer.on("/firmware", webHandleFirmware);
webServer.on("/espfirmware", webHandleEspFirmware);
webServer.on(
"/lcdupload", HTTP_POST, []() { webServer.send(200); }, webHandleLcdUpload);
"/lcdupload", HTTP_POST, []()
{ webServer.send(200); },
webHandleLcdUpload);
webServer.on("/tftFileSize", webHandleTftFileSize);
webServer.on("/lcddownload", webHandleLcdDownload);
webServer.on("/lcdOtaSuccess", webHandleLcdUpdateSuccess);
@ -378,7 +379,6 @@ void mqttConnect()
mqttLightBrightCommandTopic = "hasp/" + String(haspNode) + "/brightness/set";
mqttLightBrightStateTopic = "hasp/" + String(haspNode) + "/brightness/state";
mqttMotionStateTopic = "hasp/" + String(haspNode) + "/motion/state";
mqttEventWhileScreenOffTopic = "hasp/" + String(haspNode) + "/eventwhilescreenoff";
const String mqttCommandSubscription = mqttCommandTopic + "/#";
const String mqttGroupCommandSubscription = mqttGroupCommandTopic + "/#";
@ -874,15 +874,7 @@ void nextionProcessInput()
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
// 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)
if (nextionReturnBuffer[0] == 0x00 && nextionReturnBuffer[1] == 0x00 && nextionReturnBuffer[2] == 0x00)
{ // Nextion Startup
debugPrintln(String(F("HMI IN: [Nextion Startup] 0x00 0x00 0x00")));
if (mqttClient.connected())
@ -1088,6 +1080,15 @@ void nextionProcessInput()
{
debugPrintln(String(F("HMI IN: [Button ON] 'p[")) + nextionPage + "].b[" + nextionButtonID + "]'");
if (mqttClient.connected())
{
// Only process touch events if screen backlight is on and configured to do so.
if (ignoreTouchWhenOff && !lcdBacklightOn)
{
String mqttButtonJSONEvent = String(F("{\"event_type\":\"button_press_disabled\",\"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("'")));
}
else
{
String mqttButtonTopic = mqttStateTopic + "/p[" + nextionPage + "].b[" + nextionButtonID + "]";
mqttClient.publish(mqttButtonTopic, "ON");
@ -1096,6 +1097,7 @@ void nextionProcessInput()
mqttClient.publish(mqttStateJSONTopic, mqttButtonJSONEvent);
debugPrintln(String(F("MQTT OUT: '")) + mqttStateJSONTopic + String(F("' : '")) + mqttButtonJSONEvent + String(F("'")));
}
}
if (beepEnabled)
{
beepOnTime = 500;
@ -1108,10 +1110,19 @@ void nextionProcessInput()
espReset();
}
}
if (nextionButtonAction == 0x00)
else if (nextionButtonAction == 0x00)
{
debugPrintln(String(F("HMI IN: [Button OFF] 'p[")) + nextionPage + "].b[" + nextionButtonID + "]'");
if (mqttClient.connected())
{
// Only process touch events if screen backlight is on and configured to do so.
if (ignoreTouchWhenOff && !lcdBacklightOn)
{
String mqttButtonJSONEvent = String(F("{\"event_type\":\"button_release_disabled\",\"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("'")));
}
else
{
String mqttButtonTopic = mqttStateTopic + "/p[" + nextionPage + "].b[" + nextionButtonID + "]";
mqttClient.publish(mqttButtonTopic, "OFF");
@ -1130,6 +1141,7 @@ void nextionProcessInput()
}
}
}
}
else if (nextionReturnBuffer[0] == 0x66)
{ // Handle incoming "sendme" page number
// 0x66+PageNum+End
@ -2010,23 +2022,25 @@ void espSetupOta()
ArduinoOTA.setPassword(configPassword);
ArduinoOTA.setRebootOnSuccess(false);
ArduinoOTA.onStart([]() {
ArduinoOTA.onStart([]()
{
debugPrintln(F("ESP OTA: update start"));
nextionSetAttr("p[0].b[1].txt", "\"\\rHASP update:\\r\\r\\r \"");
nextionSendCmd("page 0");
nextionSendCmd("vis 4,1");
});
ArduinoOTA.onEnd([]() {
ArduinoOTA.onEnd([]()
{
debugPrintln(F("ESP OTA: update complete"));
nextionSetAttr("p[0].b[1].txt", "\"\\rHASP update:\\r\\r Complete!\\rRestarting.\"");
nextionSendCmd("vis 4,1");
delay(1000);
espReset();
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
nextionUpdateProgress(progress, total);
});
ArduinoOTA.onError([](ota_error_t error) {
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total)
{ nextionUpdateProgress(progress, total); });
ArduinoOTA.onError([](ota_error_t error)
{
debugPrintln(String(F("ESP OTA: ERROR code ")) + String(error));
if (error == OTA_AUTH_ERROR)
debugPrintln(F("ESP OTA: ERROR - Auth Failed"));