Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gpio debugging #1165

Merged
merged 3 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions components/gpio_control/GPIODevices/simple_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
22 changes: 20 additions & 2 deletions components/gpio_control/GPIODevices/two_button_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down