further debounce button presses

This commit is contained in:
root 2019-07-06 21:18:54 +00:00
parent bd8e6a6d98
commit 00552be862
1 changed files with 7 additions and 5 deletions

View File

@ -6,7 +6,7 @@ from subprocess import call
import sys
button_count = 2
longpress_delay = 0.4
longpress_delay = 0.6
shortpress_count_max_delay = 0.5
inter_press_max_delay = 0.5
@ -120,21 +120,23 @@ def switch_shortpressed(event):
print({'shortpress':{'delay':shortpress_delay,'count':c_pin['shortpress']['count']}})
def switch_pressed(event):
event_time = time.time()
c_pin = pin[event.pin_num]
# debouncing
c_pin['last_press'] = 0
time.sleep(0.02)
time.sleep(0.08)
if event.chip.input_pins[event.pin_num].value == 0:
return
# remove scheduled event
c_pin['sched_time'] = 0
c_pin['last_press'] = time.time()
c_pin['last_press'] = event_time
def switch_unpressed(event):
event_time = time.time()
c_pin = pin[event.pin_num]
if c_pin['last_press'] == 0:
return
c_pin['last_unpress'] = time.time()
c_pin['last_unpress'] = event_time
press_time = c_pin['last_unpress'] - c_pin['last_press']
if press_time < longpress_delay:
# parse data inter_press_max_delay seconds after no event
@ -159,4 +161,4 @@ if __name__ == "__main__":
c_pin['sched_time'] = 0
setattr(listener, 'pin_num', i)
exec_chch_button_cmd(listener)
time.sleep(0.001)
time.sleep(0.01)