Skip to content

use new write_then_readinto for repeated start #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 2 commits into from
Aug 19, 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
14 changes: 8 additions & 6 deletions adafruit_fxos8700.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def _read_u8(self, address):
# Read an 8-bit unsigned value from the specified 8-bit address.
with self._device as i2c:
self._BUFFER[0] = address & 0xFF
i2c.write(self._BUFFER, end=1, stop=False)
i2c.readinto(self._BUFFER, end=1)
i2c.write_then_readinto(self._BUFFER, self._BUFFER,
out_end=1, in_end=1, stop=False)
return self._BUFFER[0]

def _write_u8(self, address, val):
Expand All @@ -163,8 +163,9 @@ def read_raw_accel_mag(self):
# Read accelerometer data from sensor.
with self._device as i2c:
self._BUFFER[0] = _FXOS8700_REGISTER_OUT_X_MSB
i2c.write(self._BUFFER, end=1, stop=False)
i2c.readinto(self._BUFFER, end=6)
i2c.write_then_readinto(self._BUFFER, self._BUFFER,
out_end=1, in_end=6,
stop=False)
accel_raw_x = struct.unpack_from('>H', self._BUFFER[0:2])[0]
accel_raw_y = struct.unpack_from('>H', self._BUFFER[2:4])[0]
accel_raw_z = struct.unpack_from('>H', self._BUFFER[4:6])[0]
Expand All @@ -177,8 +178,9 @@ def read_raw_accel_mag(self):
# 16-bit signed data so struct parsing can handle it directly.
with self._device as i2c:
self._BUFFER[0] = _FXOS8700_REGISTER_MOUT_X_MSB
i2c.write(self._BUFFER, end=1, stop=False)
i2c.readinto(self._BUFFER, end=6)
i2c.write_then_readinto(self._BUFFER, self._BUFFER,
out_end=1, in_end=6,
stop=False)
mag_raw_x = struct.unpack_from('>h', self._BUFFER[0:2])[0]
mag_raw_y = struct.unpack_from('>h', self._BUFFER[2:4])[0]
mag_raw_z = struct.unpack_from('>h', self._BUFFER[4:6])[0]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Adafruit-Blinka
adafruit-circuitpython-busdevice
adafruit-circuitpython-busdevice>=2.2.5