diff --git a/Arduino_Sketch/HASwitchPlate/HASwitchPlate.ino b/Arduino_Sketch/HASwitchPlate/HASwitchPlate.ino
index 7385e5a..70e91db 100644
--- a/Arduino_Sketch/HASwitchPlate/HASwitchPlate.ino
+++ b/Arduino_Sketch/HASwitchPlate/HASwitchPlate.ino
@@ -91,6 +91,7 @@ unsigned long nextionAckTimer = 0; // Timer to track Nextion
const unsigned long telnetInputMax = 128; // Size of user input buffer for user telnet session
bool motionEnabled = false; // Motion sensor is enabled
bool mdnsEnabled = true; // mDNS enabled
+bool ignoreTouchWhenOff = false; // Ignore touch events when backlight is off and instead send mqtt msg
bool beepEnabled = false; // Keypress beep enabled
unsigned long beepOnTime = 1000; // milliseconds of on-time for beep
unsigned long beepOffTime = 1000; // milliseconds of off-time for beep
@@ -131,6 +132,7 @@ 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
@@ -377,6 +379,7 @@ 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 + "/#";
@@ -872,7 +875,15 @@ void nextionProcessInput()
debugPrintln(String(F("HMI IN: [")) + String(nextionReturnIndex) + String(F(" bytes]: ")) + printHex8(nextionReturnBuffer, nextionReturnIndex));
- if (nextionReturnBuffer[0] == 0x00 && nextionReturnBuffer[1] == 0x00 && nextionReturnBuffer[2] == 0x00)
+ // 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)
{ // Nextion Startup
debugPrintln(String(F("HMI IN: [Nextion Startup] 0x00 0x00 0x00")));
if (mqttClient.connected())
@@ -2231,6 +2242,17 @@ void configRead()
beepEnabled = false;
}
}
+ if (!jsonConfigValues["ignoreTouchWhenOff"].isNull())
+ {
+ if (jsonConfigValues["ignoreTouchWhenOff"])
+ {
+ ignoreTouchWhenOff = true;
+ }
+ else
+ {
+ ignoreTouchWhenOff = false;
+ }
+ }
String jsonConfigValuesStr;
serializeJson(jsonConfigValues, jsonConfigValuesStr);
debugPrintln(String(F("SPIFFS: read ")) + String(configFile.size()) + String(F(" bytes and parsed json:")) + jsonConfigValuesStr);
@@ -2282,6 +2304,7 @@ void configSave()
jsonConfigValues["debugTelnetEnabled"] = debugTelnetEnabled;
jsonConfigValues["mdnsEnabled"] = mdnsEnabled;
jsonConfigValues["beepEnabled"] = beepEnabled;
+ jsonConfigValues["ignoreTouchWhenOff"] = ignoreTouchWhenOff;
debugPrintln(String(F("SPIFFS: mqttServer = ")) + String(mqttServer));
debugPrintln(String(F("SPIFFS: mqttPort = ")) + String(mqttPort));
@@ -2299,6 +2322,7 @@ void configSave()
debugPrintln(String(F("SPIFFS: debugTelnetEnabled = ")) + String(debugTelnetEnabled));
debugPrintln(String(F("SPIFFS: mdnsEnabled = ")) + String(mdnsEnabled));
debugPrintln(String(F("SPIFFS: beepEnabled = ")) + String(beepEnabled));
+ debugPrintln(String(F("SPIFFS: ignoreTouchWhenOff = ")) + String(ignoreTouchWhenOff));
File configFile = SPIFFS.open("/config.json", "w");
if (!configFile)
@@ -2503,6 +2527,11 @@ void webHandleRoot()
{
webServer.sendContent(F(" checked='checked'"));
}
+ webServer.sendContent(F(">
Ignore touchevents when backlight is off: