Skip to content

changed to use struct module instead of ustruct #6

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 2, 2017
Merged
Show file tree
Hide file tree
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
13 changes: 8 additions & 5 deletions adafruit_lis3dh/lis3dh.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
# https://github.com/adafruit/Adafruit_LIS3DH/
# Author: Tony DiCola
# License: MIT License (https://en.wikipedia.org/wiki/MIT_License)
import ustruct
try:
import struct
except:
import ustruct as struct

from micropython import const

Expand Down Expand Up @@ -96,9 +99,9 @@ def acceleration(self):
a 3-tuple and are in m / s ^ 2.
"""
data = self._read_register(REG_OUT_X_L | 0x80, 6)
x = ustruct.unpack('<h', data[0:2])[0]
y = ustruct.unpack('<h', data[2:4])[0]
z = ustruct.unpack('<h', data[4:6])[0]
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 @@ -118,7 +121,7 @@ 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 ustruct.unpack('<h', data[0:2])[0]
return struct.unpack('<h', data[0:2])[0]

def read_adc_mV(self, adc):
"""Read the specified analog to digital converter value in millivolts.
Expand Down
1 change: 0 additions & 1 deletion examples/spinner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# License: MIT License (https://opensource.org/licenses/MIT)
import math
import time
import ustruct

import board
import busio
Expand Down
1 change: 0 additions & 1 deletion examples/spinner_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# License: MIT License (https://opensource.org/licenses/MIT)
import math
import time
import ustruct

import board
import busio
Expand Down