Skip to content

fix for ustruct/struct import error in Issue #1 #2

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 1 commit into from
Feb 22, 2018
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
9 changes: 6 additions & 3 deletions adafruit_mpl3115a2.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
import time

from micropython import const
import ustruct
try:
import ustruct as struct
except ImportError:
import struct

import adafruit_bus_device.i2c_device as i2c_device

Expand Down Expand Up @@ -214,7 +217,7 @@ def altitude(self):
# Reconstruct signed 32-bit altitude value (actually 24 bits shifted up
# and then scaled down).
self._BUFFER[3] = 0 # Top 3 bytes of buffer were read from the chip.
altitude = ustruct.unpack('>i', self._BUFFER[0:4])[0]
altitude = struct.unpack('>i', self._BUFFER[0:4])[0]
# Scale down to meters.
return altitude / 65535.0

Expand All @@ -228,7 +231,7 @@ def temperature(self):
# Read 2 bytes of data from temp register.
self._read_into(_MPL3115A2_REGISTER_TEMP_MSB, self._BUFFER, count=2)
# Reconstruct signed 12-bit value.
temperature = ustruct.unpack('>h', self._BUFFER[0:2])[0]
temperature = struct.unpack('>h', self._BUFFER[0:2])[0]
temperature >>= 4
# Scale down to degrees Celsius.
return temperature / 16.0
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Uncomment the below if you use native CircuitPython modules such as
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
autodoc_mock_imports = ["micropython", "adafruit_bus_device", "adafruit_bus_device.i2c_device", "ustruct"]
autodoc_mock_imports = ["micropython", "adafruit_bus_device", "adafruit_bus_device.i2c_device", "struct"]

intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/bus_device/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}

Expand Down