Home-Assistant-nextion_handler
Home-Assistant-nextion_handler copied to clipboard
Realtime Swipe and Press Gestures and Dual-state buttons
Great work on the gesture detection!
When using dual-state buttons, the Nextion firmware immediately changes the state of the button on touch. So if you start a gesture on a dual-state button then the button has an incorrect state after the gesture is detected. I fixed this by adding the following code to invert the state of the button again when a gesture is detected:
if(b[tc0.val].type==53) // Swipe triggered, restore dual-state button state
{
b[tc0.val].val=b[tc0.val].val^1
}
These few lines of code are added to the Timer Event code in the following location:
//
// Movement > 100px => SWIPE
if(dsq>10000)
{
if(b[tc0.val].type==53) // Swipe triggered, restore dual state button state
{
b[tc0.val].val=b[tc0.val].val^1
}
if(dx>100)
{
//>>
gest_type=1 // right
//page 0 // <- CUSTOM*** live action here
// t1.txt=">>" // ***DEGBUG/DEMO
}else if(dx<-100)
Normally I would have created a PR, but unfortunately HMI files are binary files. Instead of updating the Tips_and_Tricks.HMI file I thought it would be better to just create an issue with the solution.
Thanks for the tip. I'll test this out and look at adding it when I next get a chance to update the project.