Skip to content

changes the way data in unpacked #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions adafruit_lis3dh/lis3dh.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ def acceleration(self):
"""Read the x, y, z acceleration values. These values are returned in
a 3-tuple and are in m / s ^ 2.
"""
data = self._read_register(REG_OUT_X_L | 0x80, 6)
x = struct.unpack('<h', data[0:2])[0]
y = struct.unpack('<h', data[2:4])[0]
z = struct.unpack('<h', data[4:6])[0]
divider = 1
accel_range = self.range
if accel_range == RANGE_16_G:
Expand All @@ -112,6 +108,9 @@ def acceleration(self):
divider = 8190
elif accel_range == RANGE_2_G:
divider = 16380

x, y, z = struct.unpack('<hhh', self._read_register(REG_OUT_X_L | 0x80, 6))

return (x / divider * 9.806, y / divider * 9.806, z / divider * 9.806)

def read_adc_raw(self, adc):
Expand All @@ -120,8 +119,8 @@ def read_adc_raw(self, adc):
"""
if adc < 1 or adc > 3:
raise ValueError('ADC must be a value 1 to 3!')
data = self._read_register((REG_OUTADC1_L+((adc-1)*2)) | 0x80, 2)
return struct.unpack('<h', data[0:2])[0]

return struct.unpack('<h', self._read_register((REG_OUTADC1_L+((adc-1)*2)) | 0x80, 2))[0]

def read_adc_mV(self, adc):
"""Read the specified analog to digital converter value in millivolts.
Expand Down