<commit_before>from .device import Device
from .. import config as c

class Encoder(Device):

    DEVICE_CODE =   c.devices.encoder.code
    WRITE_CODE =    c.devices.encoder.write_code
    READ_CODE  =    c.devices.encoder.read_code

    def __init__(self, tamproxy, pin_a, pin_b):
        self.pin_a = pin_a
        self.pin_b = pin_b
        self.val = 0
        super(Encoder, self).__init__(tamproxy)
        while self.id is None: pass

    @property
    def add_payload(self):
        return self.DEVICE_CODE + chr(self.pin_a) + chr(self.pin_b)

    def write(self, value):
        value = int(value) & 0xFFFFFFFF
        self.tamp.send_request(self.id,
                               self.WRITE_CODE +
                               chr((int(value) >> 24) & 0xFF) +
                               chr((int(value) >> 16) & 0xFF) +
                               chr((int(value) >> 8) & 0xFF) +
                               chr(int(value) & 0xFF))

    def update(self):
        self.tamp.send_request(self.id, self.READ_CODE, self._handle_update)

    def start_continuous(self, weight=1):
        self.tamp.send_request(self.id, self.READ_CODE, self._handle_update, 
                             continuous=True, weight=weight)

    def stop_continuous(self):
        self.tamp.send_request(self.id, self.READ_CODE, self.tamp.empty_callback, 
                             continuous=True, weight=1, remove=True)

    def _handle_update(self, request, response):
        self.val = (
            (ord(response[0])<<24) |
            (ord(response[1])<<16) |<commit_msg>Add continuous mode<commit_after>from .device import Device
from .. import config as c

class Encoder(Device):

    DEVICE_CODE =   c.devices.encoder.code
    WRITE_CODE =    c.devices.encoder.write_code
    READ_CODE  =    c.devices.encoder.read_code

    def __init__(self, tamproxy, pin_a, pin_b, continuous=True):
        self.pin_a = pin_a
        self.pin_b = pin_b
        self.val = 0
        super(Encoder, self).__init__(tamproxy)
        while self.id is None: pass
        if continuous: self.start_continuous()

    @property
    def add_payload(self):
        return self.DEVICE_CODE + chr(self.pin_a) + chr(self.pin_b)

    def write(self, value):
        value = int(value) & 0xFFFFFFFF
        self.tamp.send_request(self.id,
                               self.WRITE_CODE +
                               chr((int(value) >> 24) & 0xFF) +
                               chr((int(value) >> 16) & 0xFF) +
                               chr((int(value) >> 8) & 0xFF) +
                               chr(int(value) & 0xFF))

    def update(self):
        self.tamp.send_request(self.id, self.READ_CODE, self._handle_update)

    def start_continuous(self, weight=1):
        self.tamp.send_request(self.id, self.READ_CODE, self._handle_update, 
                             continuous=True, weight=weight)

    def stop_continuous(self):
        self.tamp.send_request(self.id, self.READ_CODE, self.tamp.empty_callback, 
                             continuous=True, weight=1, remove=True)

    def _handle_update(self, request, response):
        self.val = (
            (ord(response[0])<<24) |
            (ord(response[1])<<16) |
{'fraction_non_alphanumeric': 0.1134531928084315, 'fraction_numerical': 0.011779293242405457, 'mean_word_length': 1.88125, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1753729', 'n_tokens_mistral': 1039, 'n_tokens_neox': 981, 'n_words': 184}