Skip to content

Commit

Permalink
fix instant execution of main action on holding
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvinSchiller committed Apr 23, 2024
1 parent 4626e5d commit 8d7f3cf
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions components/gpio_control/GPIODevices/simple_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down

0 comments on commit 8d7f3cf

Please sign in to comment.