<commit_before>import sys

import smbus

from Adafruit_I2C import Adafruit_I2C

i2c_address = 0x1e
write_reg = 0x3c
read_reg = 0x3d

# < Arduino Vars > 
HMC5883L_Address = 0x1E
ConfigurationRegisterA = 0x00
ConfigurationRegisterB = 0x01
ModeRegister = 0x02
DataRegisterBegin = 0x03

# </Arduino Vars >

_mode_register = 0x02
_mode_map = {    'continuous' : 0x00,
                'single' : 0x01,
                'idle' : 0x03}
_configuration_reg_b = 0x01



class HMC5883L(object):
    
    def __init__(self, i2c_bus=0, i2c_address=0x1e, debug=False):
                
        self.debug = debug
        self.gauss = 0.88
        self.scale = 0x00
        self._multiplication_factor = 0.73
        # Create our i2c connection
        self._bus = smbus.SMBus(i2c_bus) 
        self.i2c = Adafruit_I2C(i2c_address, bus=self._bus, debug=self.debug)
        
        # set our compass to continuous mode.
        self.set_mode('continuous')

    def set_mode(self, mode):
        if mode.lower() in _mode_map:
            self.i2c.write8(_mode_register, _mode_map[mode.lower()])
        else:
            raise Exception('Invalid mode requested, valid modes are continuous, single and idle.')
        
    def get_value(self):
        result = { 'x' : None, 'y' : None, 'z' : None }
        # clear the buffer
        read_buffer = self.i2c.readList(DataRegisterBegin, 6)
        
        result['x'] = round(((read_buffer[0] << 8) | read_buffer[1]) * self._multiplication_factor , 3)
        result['z'] = round(((read_buffer[2] << 8) | read_buffer[3]) * self._multiplication_factor , 3)
        result['y'] = round(((read_buffer[4] << 8) | read_buffer[5]) * self._multiplication_factor , 3)
        
        self.last_result = result
        return result

    def set_scale(self, gauss):
        if gauss == 0.88:
            self.gauss = gauss
            self.scale = 0x00
            self._multiplication_factor = 0.73
        elif gauss == 1.3:
            self.gauss = gauss
            self.scale = 0x01
            self._multiplication_factor = 0.92
        elif gauss == 1.9:
            self.gauss = gauss
            self.scale = 0x02
            self._multiplication_factor = 1.22
        elif gauss == 2.5:
            self.gauss = gauss
            self.scale = 0x03
            self._multiplication_factor = 1.52
        elif gauss == 4.0:
            self.gauss = gauss
            self.scale = 0x04<commit_msg>Variables tidy up for the hmc5883l<commit_after>import sys

import smbus

from Adafruit_I2C import Adafruit_I2C

_hmc5883l_address = 0x1e
_mode_register = 0x02
_mode_map = {    'continuous' : 0x00,
                'single' : 0x01,
                'idle' : 0x03}
_configuration_reg_a = 0x00
_configuration_reg_b = 0x01
_read_register = 0x03


class HMC5883L(object):
    
    def __init__(self, i2c_bus=0, i2c_address=_hmc5883l_address, debug=False):
                
        self.debug = debug
        self.gauss = 0.88
        self.scale = 0x00
        self._multiplication_factor = 0.73
        # Create our i2c connection
        self._bus = smbus.SMBus(i2c_bus) 
        self.i2c = Adafruit_I2C(i2c_address, bus=self._bus, debug=self.debug)
        
        # set our compass to continuous mode.
        self.set_mode('continuous')

    def set_mode(self, mode):
        if mode.lower() in _mode_map:
            self.i2c.write8(_mode_register, _mode_map[mode.lower()])
        else:
            raise Exception('Invalid mode requested, valid modes are continuous, single and idle.')
        
    def get_value(self):
        result = { 'x' : None, 'y' : None, 'z' : None }
        # clear the buffer
        read_buffer = self.i2c.readList(_read_register, 6)
        
        result['x'] = round(((read_buffer[0] << 8) | read_buffer[1]) * self._multiplication_factor , 3)
        result['z'] = round(((read_buffer[2] << 8) | read_buffer[3]) * self._multiplication_factor , 3)
        result['y'] = round(((read_buffer[4] << 8) | read_buffer[5]) * self._multiplication_factor , 3)
        
        self.last_result = result
        return result

    def set_scale(self, gauss):
        if gauss == 0.88:
            self.gauss = gauss
            self.scale = 0x00
            self._multiplication_factor = 0.73
        elif gauss == 1.3:
            self.gauss = gauss
            self.scale = 0x01
            self._multiplication_factor = 0.92
        elif gauss == 1.9:
            self.gauss = gauss
            self.scale = 0x02
            self._multiplication_factor = 1.22
        elif gauss == 2.5:
            self.gauss = gauss
            self.scale = 0x03
            self._multiplication_factor = 1.52
        elif gauss == 4.0:
            self.gauss = gauss
            self.scale = 0x04
{'fraction_non_alphanumeric': 0.10304054054054054, 'fraction_numerical': 0.048775337837837836, 'mean_word_length': 2.009529860228717, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 5, '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': '6837638', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1560, 'n_words': 340}