From 00552be86235ae751e3b90a6df11fee2b06ef8e4 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 6 Jul 2019 21:18:54 +0000 Subject: [PATCH] further debounce button presses --- chch-power.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/chch-power.py b/chch-power.py index 3e411ee..2156c81 100644 --- a/chch-power.py +++ b/chch-power.py @@ -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)