Skip to content

Commit

Permalink
simplify holdMode callback handling
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvinSchiller committed May 5, 2024
1 parent 2ac5a6f commit 1096465
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions components/gpio_control/GPIODevices/simple_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ def callbackFunctionHandler(self, *args):
if inval != GPIO.LOW:
return None

if self.hold_mode in ('Repeat', 'Postpone', 'SecondFunc', 'SecondFuncRepeat'):
return self.longPressHandler(*args)
else:
logger.info('{}: execute callback'.format(self.name))
return self.when_pressed(*args)
return self._handleCallbackFunction(*args)

@property
def when_pressed(self):
Expand All @@ -136,8 +132,8 @@ def when_pressed(self, func):
def set_callbackFunction(self, callbackFunction):
self.when_pressed = callbackFunction

def longPressHandler(self, *args):
logger.info('{}: longPressHandler, mode: {}'.format(self.name, self.hold_mode))
def _handleCallbackFunction(self, *args):
logger.info('{}: handleCallbackFunction, mode: {}'.format(self.name, self.hold_mode))

# action(s) after hold_time
if self.hold_mode == "Repeat":
Expand Down Expand Up @@ -173,6 +169,9 @@ def longPressHandler(self, *args):
while checkGpioStaysInState(self.hold_time, self.pin, GPIO.LOW):
self.when_held(*args)

else:
self.when_pressed(*args)

def __del__(self):
logger.debug('remove event detection')
GPIO.remove_event_detect(self.pin)
Expand Down

0 comments on commit 1096465

Please sign in to comment.