From 8d7f3cfe475c022de2974437f0141046e0a59447 Mon Sep 17 00:00:00 2001 From: Alvin Schiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Wed, 24 Apr 2024 00:38:42 +0200 Subject: [PATCH] fix instant execution of main action on holding --- .../gpio_control/GPIODevices/simple_button.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/components/gpio_control/GPIODevices/simple_button.py b/components/gpio_control/GPIODevices/simple_button.py index a022a812f..1256dc7cb 100644 --- a/components/gpio_control/GPIODevices/simple_button.py +++ b/components/gpio_control/GPIODevices/simple_button.py @@ -138,13 +138,11 @@ def set_callbackFunction(self, callbackFunction): def longPressHandler(self, *args): logger.info('{}: longPressHandler, mode: {}'.format(self.name, self.hold_mode)) - # instant action (except Postpone mode) - if self.hold_mode != "Postpone": - self.when_pressed(*args) # action(s) after hold_time if self.hold_mode == "Repeat": - # Repeated call of main action (multiple times if button is held long enough) + # Repeated call of main action (instantly and multiple times if button is held long enough) + self.when_pressed(*args) while checkGpioStaysInState(self.hold_time, self.pin, GPIO.LOW): self.when_pressed(*args) @@ -157,13 +155,21 @@ def longPressHandler(self, *args): elif self.hold_mode == "SecondFunc": # Call of secondary action (once) + # execute main action if not held past hold_time if checkGpioStaysInState(self.hold_time, self.pin, GPIO.LOW): self.when_held(*args) + else: + self.when_pressed(*args) while checkGpioStaysInState(self.hold_time, self.pin, GPIO.LOW): pass elif self.hold_mode == "SecondFuncRepeat": # Repeated call of secondary action (multiple times if button is held long enough) + # execute main action if not held past hold_time + if checkGpioStaysInState(self.hold_time, self.pin, GPIO.LOW): + self.when_held(*args) + else: + self.when_pressed(*args) while checkGpioStaysInState(self.hold_time, self.pin, GPIO.LOW): self.when_held(*args)