Skip to content

Commit d57cf32

Browse files
committed
use single call for i2c transactions, to support linux
1 parent 07f8011 commit d57cf32

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

adafruit_fxas21002c.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def _read_u8(self, address):
122122
# Read an 8-bit unsigned value from the specified 8-bit address.
123123
with self._device as i2c:
124124
self._BUFFER[0] = address & 0xFF
125-
i2c.write(self._BUFFER, end=1, stop=False)
126-
i2c.readinto(self._BUFFER, end=1)
125+
self._device.write_then_readinto(self._BUFFER, self._BUFFER,
126+
out_end=1, in_end=1, stop=False)
127127
return self._BUFFER[0]
128128

129129
def _write_u8(self, address, val):
@@ -141,8 +141,8 @@ def read_raw(self):
141141
# Read gyro data from the sensor.
142142
with self._device:
143143
self._BUFFER[0] = _GYRO_REGISTER_OUT_X_MSB
144-
self._device.write(self._BUFFER, end=1, stop=False)
145-
self._device.readinto(self._BUFFER)
144+
self._device.write_then_readinto(self._BUFFER, self._BUFFER,
145+
out_end=1, stop=False)
146146
# Parse out the gyroscope data as 16-bit signed data.
147147
raw_x = struct.unpack_from('>h', self._BUFFER[0:2])[0]
148148
raw_y = struct.unpack_from('>h', self._BUFFER[2:4])[0]

0 commit comments

Comments
 (0)