<commit_before>"""Class for communicating with the GrovePi motor controller."""

import logging
logging.basicConfig()
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.getLevelName('INFO'))
try:
    from GrovePi.Software.Python.\
        grove_i2c_motor_driver.grove_i2c_motor_driver \
        import motor_driver
except ImportError:
    LOGGER.warn("GrovePi I2C motor driver lib unavailable. Using dummy.")
    from drivers.dummy_grovepi_interface import motor_driver


class GrovePiMotors:
    """Helper functions for setting the GrovePi motor controllers."""

    PORT_A = 'a'
    PORT_B = 'b'
    DIRECTION_FORWARD = 'forward'
    DIRECTION_BACKWARD = 'backward'

    def __init__(self):
        """Create an instance of motor interface."""
        self.interface = motor_driver()
        self.speeds = {self.PORT_A: 0, self.PORT_B: 0}
        self.directions = {self.PORT_A: 0, self.PORT_B: 0}

    def set_speed(self, port, speed, direction):
        """Set the speed of the motors."""
        port, direction = port.lower(), direction.lower()
        if self.speeds[port] == speed and self.directions[port] == direction:
            return
        self.speeds[port], self.directions[port] = speed, direction

        self.interface.MotorSpeedSetAB(self.speeds[self.PORT_A],
                                       self.speeds[self.PORT_B])

        direction_bits = \
            (self._direction_bits(self.directions[self.PORT_A]) << 2) + \
            (self._direction_bits(self.directions[self.PORT_B]))
        self.interface.DirectionSet(direction_bits)

    def _direction_bits(self, direction):
        return 0b10 if direction == self.DIRECTION_FORWARD else 0b01<commit_msg>Simplify GrovePi driver direction handling<commit_after>"""Class for communicating with the GrovePi motor controller."""

import logging
logging.basicConfig()
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.getLevelName('INFO'))
try:
    from GrovePi.Software.Python.\
        grove_i2c_motor_driver.grove_i2c_motor_driver \
        import motor_driver
except ImportError:
    LOGGER.warn("GrovePi I2C motor driver lib unavailable. Using dummy.")
    from drivers.dummy_grovepi_interface import motor_driver


class GrovePiMotors:
    """Helper functions for setting the GrovePi motor controllers."""

    PORT_A = 'a'
    PORT_B = 'b'
    DIRECTION_FORWARD = 0b10
    DIRECTION_BACKWARD = 0b01

    def __init__(self):
        """Create an instance of motor interface."""
        self.interface = motor_driver()
        self.speeds = {self.PORT_A: 0, self.PORT_B: 0}
        self.directions = {self.PORT_A: 0, self.PORT_B: 0}

    def set_speed(self, port, speed, direction):
        """Set the speed of the motors."""
        port, direction = port.lower(), direction.lower()
        if self.speeds[port] == speed and self.directions[port] == direction:
            return
        self.speeds[port], self.directions[port] = speed, direction

        self.interface.MotorSpeedSetAB(self.speeds[self.PORT_A],
                                       self.speeds[self.PORT_B])

        direction_bits = \
            (self.directions[self.PORT_A] << 2) + \
            (self.directions[self.PORT_B])
        self.interface.DirectionSet(direction_bits)
{'fraction_non_alphanumeric': 0.10705521472392639, 'fraction_numerical': 0.008588957055214725, 'mean_word_length': 2.976829268292683, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '803037', 'n_tokens_mistral': 1031, 'n_tokens_neox': 965, 'n_words': 223}