-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
We get fake long pressed buttons when conect device to PI. #5
Comments
Please next time use this for commenting code as in python indentation is essential: Your code This is how I am interpreting your code (Tell me if I am interpreting wrong): longpress_time = 1
longpress_time2 = 5
def vol_down(self, channel):
if GPIO.input(channel) == 1:
if self.down_time_vol_down + longpress_time > time.time():
self.frontend.input({'key': 'volume_down', 'long': False})
elif self.down_time_vol_down + longpress_time2 > time.time():
self.frontend.input({'key': 'volume_down', 'long': True})
else:
self.down_time_vol_down = time.time() I am not able to reproduce the error as I am using a powered USB hub. Without the hub the pi reboots when I insert a USB. So to be sure if I understood this correctly. The problem is that when you plug a USB, GPIO value changes so fast that GPIO.input(channel) is never 0 and down_time is not updated. So as the down time is a old value longpress is triggered. To fix that your idea is that it should be a max time (5 seconds in your example) for a button press and that we should ignore that press as it will probably be a false positive. Another fix I think of could be to check if the time has been updated: def vol_down(self, channel):
if GPIO.input(channel) == 1:
if self.down_time_vol_down >= 0:
if self.down_time_vol_down + longpress_time > time.time():
self.frontend.input({'key': 'volume_down', 'long': False})
else:
self.frontend.input({'key': 'volume_down', 'long': True})
self.down_time_vol_down = -1
else:
self.down_time_vol_down = time.time() Please try this code and reply if it fixes or not. Thanks for your help in making mopidy-ttspio better! |
Hi,
Thanks for your help too. |
Thanks for the feedback! The fix will be included in next release |
Hi,
on my PI I very often get fake long pressed buttons. It happens when I connect devices, like usb flash drive. I analyzed issue. To my mind, the main reason is electromagnetic interference. The signal causes GPIO.add_event_detect and after that very quickly set GPIO.input(channel) == 1. The self.down_time_previous has previos value (from last call of function) - as result we get long press button. I changed code (ex: volume down button):
longpress_time = 1
longpress_time2 = 5
def vol_down(self, channel):
if GPIO.input(channel) == 1:
if self.down_time_vol_down + longpress_time > time.time():
self.frontend.input({'key': 'volume_down', 'long': False})
elif self.down_time_vol_down + longpress_time2 > time.time():
self.frontend.input({'key': 'volume_down', 'long': True})
else:
self.down_time_vol_down = time.time()
Now I don't get fake long pressed buttons. Please, check it and fix.
The text was updated successfully, but these errors were encountered: