Touchphat function no longer working

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.

Is there anything that can be done to fix this?

Anyone? If I can’t get a fix for this is there a way to download an earlier version of the module? This update has totally ruined the way I used to use this HAT.

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:

@touchphat.on_release(['A'])
def handle_touch(event):
    print("Kitchen Amp Off")
    try:
        time.sleep(.1)

        tn.close()
        time.sleep(.2)
        tn.open('192.168.0.2')
        tn.write("ST04OFF\r\n")
        tn.close()
        time.sleep(.2)
    except:
        pass
        time.sleep(.2)

@touchphat.on_touch(['A'])
def handle_touch(event):
    print("Kitchen Room Amp On")
    try:
        my_kodi.Settings.SetSettingValue({ "setting":"audiooutput.audiodevice","value":"ALSA:sysdefault:CARD=IQaudIODAC" })
        time.sleep(.1)
    
        tn.close()
        time.sleep(.2)
        tn.open('192.168.0.2')
        tn.write("ST04ASIG\r\n")
        tn.close()
        time.sleep(.2)
    except:
        pass 
        time.sleep(.2)