<commit_before>import glob
import sys
from time import sleep

import numpy as np
from serial import Serial
from serial.serialutil import SerialException


class DummySerial:
    def write(self, data):
        sleep(0.01)

    def reset_input_buffer(self):
        pass

    def reset_output_buffer(self):
        pass


class Arduino:
    INITIAL_DELAY = 4

    def __init__(self):
        self._serial = None
        self._brightness = 0.25

    @property
    def brightness(self):
        return self._brightness

    @brightness.setter
    def brightness(self, value):
        self._brightness = min(1, max(value, 0))

    def start(self):
        for device in glob.glob("/dev/ttyUSB*"):
            print("Trying to connect to %s" % device)
            try:
                self._serial = Serial(device, 115200)
                print("Connected to serial port %s" % device)
                sleep(self.INITIAL_DELAY)
                self._serial.reset_input_buffer()
                self._serial.reset_output_buffer()
                return
            except SerialException:
                pass

        self._serial = DummySerial()
        print("Failed to connect to a serial port.")
<commit_msg>Simplified arduino communication.<commit_after>import glob
import sys
from time import sleep

import numpy as np
from serial import Serial
from serial.serialutil import SerialException


class DummySerial:
    def write(self, data):
        sleep(0.01)

    def reset_input_buffer(self):
        pass

    def reset_output_buffer(self):
        pass


class Arduino:
    INITIAL_DELAY = 4

    def __init__(self):
        self._serial = None
        self._brightness = 0.25

    @property
    def brightness(self):
        return self._brightness

    @brightness.setter
    def brightness(self, value):
        self._brightness = min(1, max(value, 0))

    def start(self):
        for device in glob.glob("/dev/ttyUSB*"):
            print("Trying to connect to %s" % device)
            try:
                self._serial = Serial(device, 115200)
                self._serial.reset_input_buffer()
                self._serial.reset_output_buffer()
                print("Connected to serial port %s" % device)
                sleep(self.INITIAL_DELAY)
                return
            except SerialException:
                pass

        self._serial = DummySerial()
        print("Failed to connect to a serial port.")

{'fraction_non_alphanumeric': 0.08106995884773663, 'fraction_numerical': 0.012345679012345678, 'mean_word_length': 2.02363184079602, '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': '774483', 'n_tokens_mistral': 719, 'n_tokens_neox': 649, 'n_words': 188}