Skip to content

Commit a40dad3

Browse files
mrmcwethytannewt
authored andcommitted
changed to use struct module instead of ustruct (#6)
Changed to use struct module instead of ustruct. CircuitPython 3.0+ will have struct to match CPython.
1 parent c268264 commit a40dad3

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

adafruit_lis3dh/lis3dh.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
# https://github.com/adafruit/Adafruit_LIS3DH/
44
# Author: Tony DiCola
55
# License: MIT License (https://en.wikipedia.org/wiki/MIT_License)
6-
import ustruct
6+
try:
7+
import struct
8+
except:
9+
import ustruct as struct
710

811
from micropython import const
912

@@ -96,9 +99,9 @@ def acceleration(self):
9699
a 3-tuple and are in m / s ^ 2.
97100
"""
98101
data = self._read_register(REG_OUT_X_L | 0x80, 6)
99-
x = ustruct.unpack('<h', data[0:2])[0]
100-
y = ustruct.unpack('<h', data[2:4])[0]
101-
z = ustruct.unpack('<h', data[4:6])[0]
102+
x = struct.unpack('<h', data[0:2])[0]
103+
y = struct.unpack('<h', data[2:4])[0]
104+
z = struct.unpack('<h', data[4:6])[0]
102105
divider = 1
103106
accel_range = self.range
104107
if accel_range == RANGE_16_G:
@@ -118,7 +121,7 @@ def read_adc_raw(self, adc):
118121
if adc < 1 or adc > 3:
119122
raise ValueError('ADC must be a value 1 to 3!')
120123
data = self._read_register((REG_OUTADC1_L+((adc-1)*2)) | 0x80, 2)
121-
return ustruct.unpack('<h', data[0:2])[0]
124+
return struct.unpack('<h', data[0:2])[0]
122125

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

examples/spinner.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# License: MIT License (https://opensource.org/licenses/MIT)
99
import math
1010
import time
11-
import ustruct
1211

1312
import board
1413
import busio

examples/spinner_advanced.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# License: MIT License (https://opensource.org/licenses/MIT)
1515
import math
1616
import time
17-
import ustruct
1817

1918
import board
2019
import busio

0 commit comments

Comments
 (0)