diff --git a/components/gpio_control/GPIODevices/simple_button.py b/components/gpio_control/GPIODevices/simple_button.py index 250a59739..2e2c8202f 100644 --- a/components/gpio_control/GPIODevices/simple_button.py +++ b/components/gpio_control/GPIODevices/simple_button.py @@ -72,10 +72,11 @@ def __init__(self, pin, action=lambda *args: None, name=None, bouncetime=500, ed self._action = action GPIO.add_event_detect(self.pin, edge=self.edge, callback=self.callbackFunctionHandler, bouncetime=self.bouncetime) + self.callback_with_pin_argument = False def callbackFunctionHandler(self, *args): - if (len(args) > 0 and args[0] == self.pin): - logger.debug('args before: {}'.format(args)) + if len(args) > 0 and args[0] == self.pin and not self.callback_with_pin_argument: + logger.debug('Remove pin argument by callbackFunctionHandler - args before: {}'.format(args)) args = args[1:] logger.debug('args after: {}'.format(args)) diff --git a/components/gpio_control/GPIODevices/two_button_control.py b/components/gpio_control/GPIODevices/two_button_control.py index 83e3e9214..ef861e275 100644 --- a/components/gpio_control/GPIODevices/two_button_control.py +++ b/components/gpio_control/GPIODevices/two_button_control.py @@ -11,9 +11,17 @@ def functionCallTwoButtons(btn1, btn2, functionCall1, functionCall2, functionCallBothPressed=None): def functionCallTwoButtons(*args): + btn1_pin=btn1.pin + btn2_pin=btn2.pin + pressed_button=None + if len(args) > 0 and args[0] in (btn1_pin,btn2_pin): + logger.debug('Remove pin argument by TwoButtonCallbackFunctionHandler - args before: {}'.format(args)) + pressed_button=args[0] + args = args[1:] + logger.debug('args after: {}'.format(args)) btn1_pressed = btn1.is_pressed btn2_pressed = btn2.is_pressed - logger.debug('Btn1 {}, Btn2 {}'.format(btn1_pressed, btn2_pressed)) + logger.info('Btn1 {}, Btn2 {}-args:{}'.format(btn1_pressed,btn2_pressed,args)) if btn1_pressed and btn2_pressed: logger.debug("Both buttons was pressed") if functionCallBothPressed is not None: @@ -29,8 +37,16 @@ def functionCallTwoButtons(*args): logger.debug("Btn2 is pressed, action: functionCall2") logger.info('functionCall2') return functionCall2(*args) + elif pressed_button == btn1_pin: + logger.debug("No Button recognized, called by {}-pin1:functionCall1".format(args)) + logger.info('functionCall1') + return functionCall1(*args) + elif pressed_button == btn2_pin: + logger.debug("No Button recognized, called by {}-pin2:functionCall2".format(args)) + logger.info('functionCall2') + return functionCall2(*args) else: - logger.debug("No Button Pressed: no action") + logger.debug("No Button recognized, cannot evaluate reason for function call - {}".format(args)) return None return functionCallTwoButtons @@ -60,6 +76,7 @@ def __init__(self, edge=GPIO.FALLING, hold_time=hold_time, hold_repeat=hold_repeat) + self.btn1.callback_with_pin_argument = True self.btn2 = SimpleButton(pin=bcmPin2, action=lambda *args: None, @@ -68,6 +85,7 @@ def __init__(self, name=name + 'Btn2', bouncetime=500, edge=GPIO.FALLING) + self.btn2.callback_with_pin_argument = True generatedTwoButtonFunctionCall = functionCallTwoButtons(self.btn1, self.btn2, self.functionCallBtn1,