The touchphat python module was updated earlier this year and it seems that a function was broken at the time.
The behaviour of “on_touch” is now the same as “on_release”. It’s frustrating as now I can’t use the buttons the way I want eg on_touch would turn on my amp and the led would light up and when I pressed it again on_release would then switch it off. Now it just switches on then immediately off.
To be honest, it sounds like the current behaviour is correct - pressing a button should generate an on_touch (when you touch it) plus an on_release (when you take your finger off it), so your code should probably deal with the toggle yourself.
That said, there’s nothing terribly obvious in the code changes that would explain the behaviour change, so it may be in your code - what are you running (and has that changed)?
Regardless; you can ask pip to install previous versions easily enough:
pip install touchphat==0.0.1
(or pip3, depending on your local environment - whichever you used to initially install)
Thank you for your reply. Your explanation was helpful - the update earlier this year probably hasn’t broken it, more likely fixed it. Unfortunately for me the broken module was more useful.
I’l explain the situation and share some of the code and maybe someone can help me fix it.
So before the update when I first pressed a button it would light up and stay lit. The on_touch command for me would switch on my amp. Pressing the button again would switch the led light off and also my amp - this was linked to on_release. Here is the part of the code:
Anybody any ideas about this, or point me in the right direction to get help?
I just don’t understand how I can use ‘ontouch’ and ‘onrelease’ and have a different outcome? When I press the button both the ‘ontouch’ bit of code and ‘onrelease’ part are being triggered at the same time. This is obviously not desireable.
Every time you press the button you generate two actions - ontouch when your finger arrives, and onrelease when it moves away.
The normal way would be to have code in your ontouch handler to toggle your amp control (i.e. turn it off if it’s on, or on if it’s off) and not be dealing with onrelease at all (or the other way around, but that’s a bit of a design choice).
I know nothing about your amp so I can’t write the whole code for you.
Then again, if you were happy with it using the previous version of the library is there a reason you didn’t just re-install the old version and carry on as before?