<commit_before># ADXL345 Python library for Raspberry Pi 
#
# author:  <NAME>
# license: BSD, see LICENSE.txt included in this package
# 
# This is a Raspberry Pi Python implementation to help you get started with
# the Adafruit Triple Axis ADXL345 breakout board:
# http://shop.pimoroni.com/products/adafruit-triple-axis-accelerometer

import smbus
from time import sleep

import RPi.GPIO as GPIO
import time


GPIO.setmode(GPIO.BCM)
GPIO_OUT = [5, 6, 13, 19, 26, 12, 16 ,20]
for i in range(8):
	GPIO.setup(GPIO_OUT[i],GPIO.OUT)




# select the correct i2c bus for this revision of Raspberry Pi
revision = ([l[12:-1] for l in open('/proc/cpuinfo','r').readlines() if l[:8]=="Revision"]+['0000'])[0]
bus = smbus.SMBus(1 if int(revision, 16) >= 4 else 0)

# ADXL345 constants
EARTH_GRAVITY_MS2   = 9.80665
SCALE_MULTIPLIER    = 0.004

DATA_FORMAT         = 0x31
BW_RATE             = 0x2C
POWER_CTL           = 0x2D

BW_RATE_1600HZ      = 0x0F
BW_RATE_800HZ       = 0x0E
BW_RATE_400HZ       = 0x0D
BW_RATE_200HZ       = 0x0C
BW_RATE_100HZ       = 0x0B
BW_RATE_50HZ        = 0x0A
BW_RATE_25HZ        = 0x09

RANGE_2G            = 0x00
RANGE_4G            = 0x01
RANGE_8G            = 0x02
RANGE_16G           = 0x03

MEASURE             = 0x08
AXES_DATA           = 0x32

class ADXL345:
	
	#LSB to MSB
		
	address = None

	def __init__(self, address = 0x53):        
		self.address = address
		self.setBandwidthRate(BW_RATE_100HZ)
	        self.setRange(RANGE_2G)
	        self.enableMeasurement()
	
	def enableMeasurement(self):
	        bus.write_byte_data(self.address, POWER_CTL, MEASURE)
	
	def setBandwidthRate(self, rate_flag):
	        bus.write_byte_data(self.address, BW_RATE, rate_flag)
	
	    # set the measurement range for 10-bit readings
	def setRange(self, range_flag):
	        value = bus.read_byte_data(self.address, DATA_FORMAT)
	
	        value &= ~0x0F;
	        value |= range_flag;  
	        value |= 0x08;
	
	        bus.write_byte_data(self.address, DATA_FORMAT, value)
	    
	    # returns the current reading from the sensor for each axis
	    #
	    # parameter gforce:
	    #    False (default): result is returned in m/s^2
	    #    True           : result is returned in gs
	def getAxes(self, gforce = False):
	        bytes = bus.read_i2c_block_data(self.address, AXES_DATA, 6)
	        GPIO.setmode(GPIO.BCM)
	        
	        x = bytes[0] | (bytes[1] << 8)
	        if(x & (1 << 16 - 1)):
	            x = x - (1<<16)
	
	        y = bytes[2] | (bytes[3] << 8)
	        if(y & (1 << 16 - 1)):
	            y = y - (1<<16)
	
	        z = bytes[4] | (bytes[5] << 8)
	        if(z & (1 << 16 - 1)):
	            z = z - (1<<16)
		
		x1 = x + 512
		y1 = y + 512
		z1 = z + 512
		
		#TODO: truncate the bits to 8
		x1 = x1 >> 2
		y1 = y1 >> 2
		z1 = z1 >> 2
		
		bits = []
		#suppose we output x axix acceleration via GPIO_OUT0~8
		for i in range(8):
			bits.append((x1 & (0b1 << i))>>i)
			GPIO.output(GPIO_OUT[i], bits[i]) 
	
		
		
	        x = x * SCALE_MULTIPLIER 
	        y = y * SCALE_MULTIPLIER
	        z = z * SCALE_MULTIPLIER
	
	        if gforce == False:
	            x = x * EARTH_GRAVITY_MS2
	            y = y * EARTH_GRAVITY_MS2
	            z = z * EARTH_GRAVITY_MS2
		
	        x = round(x, 4)
	        y = round(y, 4)
	        z = round(z, 4)
		
		GPIO.cleanup()
	        return {"x": x, "y": y, "z": z}

if __name__ == "__main__":
    # if run directly we'll just create an instance of the class and output 
    # the current readings
    adxl345 = ADXL345()
    
    axes = adxl345.getAxes(True)
    print "ADXL345 on address 0x%x:" % (adxl345.address)
    print "   x = %.3fG" % ( axes['x'] )
    print "   y = %.3fG" % ( axes['y'] )
    print "   z = %.3fG" % ( axes['z'] )<commit_msg>change a fucntion<commit_after># ADXL345 Python library for Raspberry Pi 
#
# author:  <NAME>
# license: BSD, see LICENSE.txt included in this package
# 
# This is a Raspberry Pi Python implementation to help you get started with
# the Adafruit Triple Axis ADXL345 breakout board:
# http://shop.pimoroni.com/products/adafruit-triple-axis-accelerometer

import smbus
from time import sleep

import RPi.GPIO as GPIO
import time


GPIO.setmode(GPIO.BCM)
GPIO_OUT = [5, 6, 13, 19, 26, 12, 16 ,20]
for i in range(8):
	GPIO.setup(GPIO_OUT[i],GPIO.OUT)


# select the correct i2c bus for this revision of Raspberry Pi
revision = ([l[12:-1] for l in open('/proc/cpuinfo','r').readlines() if l[:8]=="Revision"]+['0000'])[0]
bus = smbus.SMBus(1 if int(revision, 16) >= 4 else 0)

# ADXL345 constants
EARTH_GRAVITY_MS2   = 9.80665
SCALE_MULTIPLIER    = 0.004

DATA_FORMAT         = 0x31
BW_RATE             = 0x2C
POWER_CTL           = 0x2D

BW_RATE_1600HZ      = 0x0F
BW_RATE_800HZ       = 0x0E
BW_RATE_400HZ       = 0x0D
BW_RATE_200HZ       = 0x0C
BW_RATE_100HZ       = 0x0B
BW_RATE_50HZ        = 0x0A
BW_RATE_25HZ        = 0x09

RANGE_2G            = 0x00
RANGE_4G            = 0x01
RANGE_8G            = 0x02
RANGE_16G           = 0x03

MEASURE             = 0x08
AXES_DATA           = 0x32

class ADXL345:
	
	#LSB to MSB
		
	address = None

	def __init__(self, address = 0x53):        
		self.address = address
		self.setBandwidthRate(BW_RATE_100HZ)
	    self.setRange(RANGE_2G)
	    self.enableMeasurement()
	
	def enableMeasurement(self):
	    bus.write_byte_data(self.address, POWER_CTL, MEASURE)
	
	def setBandwidthRate(self, rate_flag):
	    bus.write_byte_data(self.address, BW_RATE, rate_flag)
	
	    # set the measurement range for 10-bit readings
	def setRange(self, range_flag):
	    value = bus.read_byte_data(self.address, DATA_FORMAT)
	
	    value &= ~0x0F;
	    value |= range_flag;  
	    value |= 0x08;
	
	    bus.write_byte_data(self.address, DATA_FORMAT, value)
	    
	    # returns the current reading from the sensor for each axis
	    #
	    # parameter gforce:
	    #    False (default): result is returned in m/s^2
	    #    True           : result is returned in gs
	def getAxes(self, gforce = False):
		bytes = bus.read_i2c_block_data(self.address, AXES_DATA, 6)
	    GPIO.setmode(GPIO.BCM)
	        
	    x = bytes[0] | (bytes[1] << 8)
	    if(x & (1 << 16 - 1)):
	        x = x - (1<<16)
	
	    y = bytes[2] | (bytes[3] << 8)
	    if(y & (1 << 16 - 1)):
	        y = y - (1<<16)
	
	    z = bytes[4] | (bytes[5] << 8)
	    if(z & (1 << 16 - 1)):
	        z = z - (1<<16)
		
		x1 = x + 512
		y1 = y + 512
		z1 = z + 512
		
		#TODO: truncate the bits to 8
		x1 = x1 >> 2
		y1 = y1 >> 2
		z1 = z1 >> 2
		
		#bits = []
		#suppose we output x axix acceleration via GPIO_OUT0~8
		# for i in range(8):
		# 	bits.append((x1 & (0b1 << i))>>i)
		# 	GPIO.output(GPIO_OUT[i], bits[i]) 
		
	    x = x * SCALE_MULTIPLIER 
	    y = y * SCALE_MULTIPLIER
	    z = z * SCALE_MULTIPLIER
	
	    if gforce == False:
	        x = x * EARTH_GRAVITY_MS2
	        y = y * EARTH_GRAVITY_MS2
	        z = z * EARTH_GRAVITY_MS2
		
	    x = round(x, 4)
        y = round(y, 4)
	    z = round(z, 4)
		
		GPIO.cleanup()
	    return {"x": x, "y": y, "z": z}

if __name__ == "__main__":
    # if run directly we'll just create an instance of the class and output 
    # the current readings
    adxl345 = ADXL345()
    
    axes = adxl345.getAxes(True)
    print "ADXL345 on address 0x%x:" % (adxl345.address)
    print "   x = %.3fG" % ( axes['x'] )
    print "   y = %.3fG" % ( axes['y'] )
    print "   z = %.3fG" % ( axes['z'] )
{'fraction_non_alphanumeric': 0.1187822777928785, 'fraction_numerical': 0.05925523240010872, 'mean_word_length': 2.2037440139312148, 'pattern_counts': {'":': 8, '<': 45, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6142720', 'n_tokens_mistral': 3318, 'n_tokens_neox': 2814, 'n_words': 736}