further debounce button presses
This commit is contained in:
parent
bd8e6a6d98
commit
00552be862
|
@ -6,7 +6,7 @@ from subprocess import call
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
button_count = 2
|
button_count = 2
|
||||||
longpress_delay = 0.4
|
longpress_delay = 0.6
|
||||||
shortpress_count_max_delay = 0.5
|
shortpress_count_max_delay = 0.5
|
||||||
inter_press_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']}})
|
print({'shortpress':{'delay':shortpress_delay,'count':c_pin['shortpress']['count']}})
|
||||||
|
|
||||||
def switch_pressed(event):
|
def switch_pressed(event):
|
||||||
|
event_time = time.time()
|
||||||
c_pin = pin[event.pin_num]
|
c_pin = pin[event.pin_num]
|
||||||
# debouncing
|
# debouncing
|
||||||
c_pin['last_press'] = 0
|
c_pin['last_press'] = 0
|
||||||
time.sleep(0.02)
|
time.sleep(0.08)
|
||||||
if event.chip.input_pins[event.pin_num].value == 0:
|
if event.chip.input_pins[event.pin_num].value == 0:
|
||||||
return
|
return
|
||||||
# remove scheduled event
|
# remove scheduled event
|
||||||
c_pin['sched_time'] = 0
|
c_pin['sched_time'] = 0
|
||||||
c_pin['last_press'] = time.time()
|
c_pin['last_press'] = event_time
|
||||||
|
|
||||||
def switch_unpressed(event):
|
def switch_unpressed(event):
|
||||||
|
event_time = time.time()
|
||||||
c_pin = pin[event.pin_num]
|
c_pin = pin[event.pin_num]
|
||||||
if c_pin['last_press'] == 0:
|
if c_pin['last_press'] == 0:
|
||||||
return
|
return
|
||||||
c_pin['last_unpress'] = time.time()
|
c_pin['last_unpress'] = event_time
|
||||||
press_time = c_pin['last_unpress'] - c_pin['last_press']
|
press_time = c_pin['last_unpress'] - c_pin['last_press']
|
||||||
if press_time < longpress_delay:
|
if press_time < longpress_delay:
|
||||||
# parse data inter_press_max_delay seconds after no event
|
# parse data inter_press_max_delay seconds after no event
|
||||||
|
@ -159,4 +161,4 @@ if __name__ == "__main__":
|
||||||
c_pin['sched_time'] = 0
|
c_pin['sched_time'] = 0
|
||||||
setattr(listener, 'pin_num', i)
|
setattr(listener, 'pin_num', i)
|
||||||
exec_chch_button_cmd(listener)
|
exec_chch_button_cmd(listener)
|
||||||
time.sleep(0.001)
|
time.sleep(0.01)
|
||||||
|
|
Loading…
Reference in New Issue