<commit_before>from components.gpio_control.SimpleButton import SimpleButton
from RPi import GPIO
import logging
logger = logging.getLogger(__name__)

GPIO.setmode(GPIO.BCM)


def functionCallTwoButtons(btn1, btn2, functionCall1, functionCall2, functionCallBothPressed=None):
    def functionCallTwoButtons(*args):
        btn1_pressed = btn1.is_pressed
        btn2_pressed = btn2.is_pressed
        print('Btn1 {}, Btn2 {}'.format(btn1_pressed,btn2_pressed))
        if btn1_pressed and btn2_pressed:
            logger.debug("Both buttons was pressed")
            if functionCallBothPressed is not None:
                logger.debug("Both Btns are pressed, action: functionCallBothPressed")
                return functionCallBothPressed(*args)
            logger.debug('No two button pressed action defined')
        elif btn1_pressed:
            logger.debug("Btn1 is pressed, secondary Btn not pressed, action: functionCall1")
            return functionCall1(*args)
        elif btn2_pressed:
            logger.debug("Btn2 is pressed, action: functionCall2")
            return functionCall2(*args)
        else:
            logger.debug("No Button Pressed: no action")
            return None

    return functionCallTwoButtons


class TwoButtonControl:
    def __init__(self,
                 bcmPin1,
                 bcmPin2,
                 functionCallBtn1,
                 functionCallBtn2,
                 functionCallTwoBtns=None,
                 pull_up=True,
                 hold_repeat=True,
                 hold_time=0.3,
                 name='TwoButtonControl'):
        self.functionCallBtn1 = functionCallBtn1
        self.functionCallBtn2 = functionCallBtn2
        self.functionCallTwoBtns = functionCallTwoBtns
        self.bcmPin1 = bcmPin1
        self.bcmPin2 = bcmPin2
        self.btn1 = SimpleButton(
            pin=bcmPin1,
            action=lambda *args: None,
            name=name+'Btn2',
            bouncetime=500,
            edge=GPIO.FALLING,
            hold_time=hold_time,
            hold_repeat=hold_repeat)

        self.btn2 = SimpleButton(pin=bcmPin2,
                                 action=lambda *args: None,
                                 hold_time=hold_time,
                                 hold_repeat=hold_repeat,
                                 name=name+'Btn2',
                                 bouncetime=500,
                                 edge=GPIO.FALLING)
        generatedTwoButtonFunctionCall = functionCallTwoButtons(self.btn1,
                                                                self.btn2,
                                                                self.functionCallBtn1,
                                                                self.functionCallBtn2,
                                                                self.functionCallTwoBtns
                                                                )
        self.action = generatedTwoButtonFunctionCall

        self.btn1.when_pressed = generatedTwoButtonFunctionCall
        self.btn2.when_pressed = generatedTwoButtonFunctionCall
        self.name = name

    def __repr__(self):
        two_btns_action = self.functionCallTwoBtns is not None
        return f'<TwoBtnControl-{self.name}({self.bcmPin1}, {self.bcmPin2},two_buttons_action={two_btns_action})>'


if __name__ == "__main__":
    logging.basicConfig(level='DEBUG')
    pin1 = int(input('please enter first pin'))
    pin2 = int(input('please enter second pin'))
    func1 = lambda *args: print('Function Btn1 executed with {}'.format(args))
    func2 = lambda *args: print('Function Btn2 executed with {}'.format(args))
    func3 = lambda *args: print('Function BothBtns executed with {}'.format(args))
    two_btn_control = TwoButtonControl(pin1,pin2,func1,func2,func3)

    print('running')
    while True:
        pass
<commit_msg>removing f-string for py3.5 compatibility<commit_after>from components.gpio_control.SimpleButton import SimpleButton
from RPi import GPIO
import logging
logger = logging.getLogger(__name__)

GPIO.setmode(GPIO.BCM)


def functionCallTwoButtons(btn1, btn2, functionCall1, functionCall2, functionCallBothPressed=None):
    def functionCallTwoButtons(*args):
        btn1_pressed = btn1.is_pressed
        btn2_pressed = btn2.is_pressed
        print('Btn1 {}, Btn2 {}'.format(btn1_pressed,btn2_pressed))
        if btn1_pressed and btn2_pressed:
            logger.debug("Both buttons was pressed")
            if functionCallBothPressed is not None:
                logger.debug("Both Btns are pressed, action: functionCallBothPressed")
                return functionCallBothPressed(*args)
            logger.debug('No two button pressed action defined')
        elif btn1_pressed:
            logger.debug("Btn1 is pressed, secondary Btn not pressed, action: functionCall1")
            return functionCall1(*args)
        elif btn2_pressed:
            logger.debug("Btn2 is pressed, action: functionCall2")
            return functionCall2(*args)
        else:
            logger.debug("No Button Pressed: no action")
            return None

    return functionCallTwoButtons


class TwoButtonControl:
    def __init__(self,
                 bcmPin1,
                 bcmPin2,
                 functionCallBtn1,
                 functionCallBtn2,
                 functionCallTwoBtns=None,
                 pull_up=True,
                 hold_repeat=True,
                 hold_time=0.3,
                 name='TwoButtonControl'):
        self.functionCallBtn1 = functionCallBtn1
        self.functionCallBtn2 = functionCallBtn2
        self.functionCallTwoBtns = functionCallTwoBtns
        self.bcmPin1 = bcmPin1
        self.bcmPin2 = bcmPin2
        self.btn1 = SimpleButton(
            pin=bcmPin1,
            action=lambda *args: None,
            name=name+'Btn2',
            bouncetime=500,
            edge=GPIO.FALLING,
            hold_time=hold_time,
            hold_repeat=hold_repeat)

        self.btn2 = SimpleButton(pin=bcmPin2,
                                 action=lambda *args: None,
                                 hold_time=hold_time,
                                 hold_repeat=hold_repeat,
                                 name=name+'Btn2',
                                 bouncetime=500,
                                 edge=GPIO.FALLING)
        generatedTwoButtonFunctionCall = functionCallTwoButtons(self.btn1,
                                                                self.btn2,
                                                                self.functionCallBtn1,
                                                                self.functionCallBtn2,
                                                                self.functionCallTwoBtns
                                                                )
        self.action = generatedTwoButtonFunctionCall

        self.btn1.when_pressed = generatedTwoButtonFunctionCall
        self.btn2.when_pressed = generatedTwoButtonFunctionCall
        self.name = name

    def __repr__(self):
        two_btns_action = self.functionCallTwoBtns is not None
        return '<TwoBtnControl-{name}({bcmPin1}, {bcmPin2},two_buttons_action={two_btns_action})>'.format(
            name=self.name,
            bcmPin1=self.bcmPin1,
            bcmPin2=self.bcmPin2,
            two_btns_action=two_btns_action
        )


if __name__ == "__main__":
    logging.basicConfig(level='DEBUG')
    pin1 = int(input('please enter first pin'))
    pin2 = int(input('please enter second pin'))
    func1 = lambda *args: print('Function Btn1 executed with {}'.format(args))
    func2 = lambda *args: print('Function Btn2 executed with {}'.format(args))
    func3 = lambda *args: print('Function BothBtns executed with {}'.format(args))
    two_btn_control = TwoButtonControl(pin1,pin2,func1,func2,func3)

    print('running')
    while True:
        pass

{'fraction_non_alphanumeric': 0.07548125633232017, 'fraction_numerical': 0.017983789260385005, 'mean_word_length': 1.7467826086956522, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2755655', 'n_tokens_mistral': 2058, 'n_tokens_neox': 2023, 'n_words': 406}