<commit_before>#!/usr/bin/env python

### Class to control encoders ###

import Adafruit_BBIO.UART as UART
import serial
import struct


class EncoderController(object):
    def __init__(self, port="/dev/ttyO4", baudrate=38400, UART):
        UART.setup(UART)
        self.encoderCom = serial.Serial(port=port, baudrate=baudrate)
        self.encoderCom.close()

    def getDistance(self):
        if not self.encoderCom.isOpen():
            self.encoderCom.open()

        read_one = self.encoderCom.readline().strip()
        read_two = self.encoderCom.readline().strip()
            if read_one.startswith("D"):
                value = read_one[1:]
                value = struct.unpack('!i', value.decode('hex'))[0]
                self.encoderCom.close()
                return value
            elif read_two.startswith("D"):
                value = read_two[1:]
                value = struct.unpack('!i', value.decode('hex'))[0]
                self.encoderCom.close()
                return value
            else:
                return 0

    def getVelocity(self):
        if not seld.encoderCom.isOpen():
            self.encoderCom.open()

        read_one = self.encoderCom.readline().strip()
        read_two = self.encoderCom.readline().strip()
            if read_one.startswith("V"):
                value = read_one[1:]
                value = int(value, 16)
                self.encoderCom.close()
                return value
            elif read_two.startswith("V"):
                value = read_two[1:]
                value = int(value, 16)
                self.encoderCom.close()
                return value
            else:
                return 0

    def close(self):
        self.encoderCom.close()<commit_msg>updated encoder.py to attempt up to 10 reads<commit_after>#!/usr/bin/env python

### Class to control encoders ###

import Adafruit_BBIO.UART as UART
import serial
import struct


class EncoderController(object):
    def __init__(self, port="/dev/ttyO4", baudrate=38400, UART):
        UART.setup(UART)
        self.encoderCom = serial.Serial(port=port, baudrate=baudrate)
        self.encoderCom.close()

    def getDistance(self):
        if not self.encoderCom.isOpen():
            self.encoderCom.open()

        for i in xrange(0, 10):
            read = self.encoderCom.readline().strip()
            if read.startswith("D"):
                value = read[1:]
                value = struct.unpack('!i', value.decode('hex'))[0]
                self.encoderCom.close()
                break
            else:
                pass
        return value

    def getVelocity(self):
        if not self.encoderCom.isOpen():
            self.encoderCom.open()

        for i in xrange(0, 10):
            read = self.encoderCom.readline().strip()
            if read.startswith("V"):
                value = read[1:]
                value = int(value, 16)
                self.encoderCom.close()
                break
            else:
                pass
        return value

    def close(self):
        self.encoderCom.close()
{'fraction_non_alphanumeric': 0.11508452535760728, 'fraction_numerical': 0.012028608582574773, 'mean_word_length': 1.6967572304995617, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4773779', 'n_tokens_mistral': 933, 'n_tokens_neox': 861, 'n_words': 182}