<commit_before>from time import sleep

from bus import ACCEL_ADDR
from eventbus import EventBus
from utils import twos_comp


class Accel:
    @staticmethod
    def initialize():
        #Set the PD flag to 1 to go from power-down mode to normal mode
        EventBus.bus.bus.write_byte_data(ACCEL_ADDR, 0x20, 0x57)
        EventBus.bus.bus.write_byte_data(ACCEL_ADDR, 0x23, 0x30)

    @staticmethod
    def read_data():
        try:
            x_hi = EventBus.bus.bus.read_byte_data(ACCEL_ADDR, 0x29)
            x_lo = EventBus.bus.bus.read_byte_data(ACCEL_ADDR, 0x28)
            x_data = ((x_hi << 8) | x_lo ) >> 4

            y_hi = EventBus.bus.bus.read_byte_data(ACCEL_ADDR, 0x2b)
            y_lo = EventBus.bus.bus.read_byte_data(ACCEL_ADDR, 0x2a)
            y_data = ((y_hi << 8) | y_lo) >> 4

            x_two_comp_data = twos_comp(x_data, 16)
            y_two_comp_data = twos_comp(y_data, 16)

            #Multiplied by earths gravity and 0.001<commit_msg>Managed initialization for accelerometer<commit_after>from time import sleep

from bus import ACCEL_ADDR
from eventbus import EventBus
from utils import twos_comp


class Accel:
    @staticmethod
    def initialize():
        #Set the PD flag to 1 to go from power-down mode to normal mode
        EventBus.bus.bus.write_byte_data(ACCEL_ADDR, 0x20, 0x57)

    @staticmethod
    def read_data():
        try:
            x_hi = EventBus.bus.bus.read_byte_data(ACCEL_ADDR, 0x29)
            x_lo = EventBus.bus.bus.read_byte_data(ACCEL_ADDR, 0x28)
            x_data = ((x_hi << 8) | x_lo ) >> 4

            y_hi = EventBus.bus.bus.read_byte_data(ACCEL_ADDR, 0x2b)
            y_lo = EventBus.bus.bus.read_byte_data(ACCEL_ADDR, 0x2a)
            y_data = ((y_hi << 8) | y_lo) >> 4

            x_two_comp_data = twos_comp(x_data, 16)
            y_two_comp_data = twos_comp(y_data, 16)

            #Multiplied by earths gravity and 0.001
{'fraction_non_alphanumeric': 0.08734309623430962, 'fraction_numerical': 0.03347280334728033, 'mean_word_length': 2.529520295202952, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4245903', 'n_tokens_mistral': 752, 'n_tokens_neox': 684, 'n_words': 157}