<commit_before>import warnings
import time

import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.PWM as PWM

if __name__ == "__main__":

    import sys
    sys.path.append('.')

import ctrl.block as block

class Motor(block.Block):
        
    def __init__(self, *vars, **kwargs):

        # PWM1 PINS
        self.pwm_pin = kwargs.pop('pwm_pin', 'P9_14')
        self.dir_A   = kwargs.pop('dir_A', 'P9_15')
        self.dir_B   = kwargs.pop('dir_B', 'P9_23')
        self.enable_pin = kwargs.pop('enable_pin', None)

        # call super
        super().__init__(*vars, **kwargs)

        # initialize pwm1
        PWM.start(self.pwm_pin)
        GPIO.setup(self.dir_A, GPIO.OUT)
        GPIO.setup(self.dir_B, GPIO.OUT)
        if self.enable_pin:
            GPIO.setup(self.enable_pin, GPIO.OUT)

    def set_enabled(self, enabled = True):

        # call super
        super().set_enabled(enabled)

        # raise enable pin?
        if enabled and self.enable_pin:
            warnings.warn('Raising enable_pin\n')
            GPIO.output(self.enable_pin, 1)

        if not enabled:

            # wait
            time.sleep(0.1)

            # and write 0 to motor
            PWM.set_duty_cycle(self.pwm_pin, 0)

            # lower enable pin?
            if self.enable_pin:
                warnings.warn('Lowering enable_pin\n')
                GPIO.output(self.enable_pin, 0)

    def write(self, *values):

        #print('> write to motor')
        if self.enabled:

            pwm = values[0]
            if pwm >= 0:

                pwm = min(100, pwm)
                GPIO.output(self.dir_A, 1)
                GPIO.output(self.dir_B, 0)<commit_msg>Added enabled_pin to motor<commit_after>import warnings
import time

import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.PWM as PWM

if __name__ == "__main__":

    import sys
    sys.path.append('.')

import ctrl.block as block

class Motor(block.Block):
        
    def __init__(self, *vars, **kwargs):

        # PWM1 PINS
        self.pwm_pin = kwargs.pop('pwm_pin', 'P9_14')
        self.dir_A   = kwargs.pop('dir_A', 'P9_15')
        self.dir_B   = kwargs.pop('dir_B', 'P9_23')
        self.enable_pin = kwargs.pop('enable_pin', None)

        # call super
        super().__init__(*vars, **kwargs)

        # initialize pwm1
        PWM.start(self.pwm_pin)
        GPIO.setup(self.dir_A, GPIO.OUT)
        GPIO.setup(self.dir_B, GPIO.OUT)
        if self.enable_pin:
            GPIO.setup(self.enable_pin, GPIO.OUT)

    def set_enabled(self, enabled = True):

        # call super
        super().set_enabled(enabled)

        # raise enable pin?
        if enabled and self.enable_pin:
            print('> Raising enable_pin\n')
            GPIO.output(self.enable_pin, 1)

        if not enabled:

            # wait
            time.sleep(0.1)

            # and write 0 to motor
            PWM.set_duty_cycle(self.pwm_pin, 0)

            # lower enable pin?
            if self.enable_pin:
                print('> Lowering enable_pin\n')
                GPIO.output(self.enable_pin, 0)

    def write(self, *values):

        #print('> write to motor')
        if self.enabled:

            pwm = values[0]
            if pwm >= 0:

                pwm = min(100, pwm)
                GPIO.output(self.dir_A, 1)
                GPIO.output(self.dir_B, 0)
{'fraction_non_alphanumeric': 0.11346670647954614, 'fraction_numerical': 0.01433263660794267, 'mean_word_length': 1.7963272120200333, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '779767', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1090, 'n_words': 238}