@@ -139,8 +139,8 @@ def _read_u8(self, address):
139
139
# Read an 8-bit unsigned value from the specified 8-bit address.
140
140
with self ._device as i2c :
141
141
self ._BUFFER [0 ] = address & 0xFF
142
- i2c .write (self ._BUFFER , end = 1 , stop = False )
143
- i2c . readinto ( self . _BUFFER , end = 1 )
142
+ i2c .write_then_readinto (self ._BUFFER , self . _BUFFER ,
143
+ out_end = 1 , in_end = 1 , stop = False )
144
144
return self ._BUFFER [0 ]
145
145
146
146
def _write_u8 (self , address , val ):
@@ -163,8 +163,9 @@ def read_raw_accel_mag(self):
163
163
# Read accelerometer data from sensor.
164
164
with self ._device as i2c :
165
165
self ._BUFFER [0 ] = _FXOS8700_REGISTER_OUT_X_MSB
166
- i2c .write (self ._BUFFER , end = 1 , stop = False )
167
- i2c .readinto (self ._BUFFER , end = 6 )
166
+ i2c .write_then_readinto (self ._BUFFER , self ._BUFFER ,
167
+ out_end = 1 , in_end = 6 ,
168
+ stop = False )
168
169
accel_raw_x = struct .unpack_from ('>H' , self ._BUFFER [0 :2 ])[0 ]
169
170
accel_raw_y = struct .unpack_from ('>H' , self ._BUFFER [2 :4 ])[0 ]
170
171
accel_raw_z = struct .unpack_from ('>H' , self ._BUFFER [4 :6 ])[0 ]
@@ -177,8 +178,9 @@ def read_raw_accel_mag(self):
177
178
# 16-bit signed data so struct parsing can handle it directly.
178
179
with self ._device as i2c :
179
180
self ._BUFFER [0 ] = _FXOS8700_REGISTER_MOUT_X_MSB
180
- i2c .write (self ._BUFFER , end = 1 , stop = False )
181
- i2c .readinto (self ._BUFFER , end = 6 )
181
+ i2c .write_then_readinto (self ._BUFFER , self ._BUFFER ,
182
+ out_end = 1 , in_end = 6 ,
183
+ stop = False )
182
184
mag_raw_x = struct .unpack_from ('>h' , self ._BUFFER [0 :2 ])[0 ]
183
185
mag_raw_y = struct .unpack_from ('>h' , self ._BUFFER [2 :4 ])[0 ]
184
186
mag_raw_z = struct .unpack_from ('>h' , self ._BUFFER [4 :6 ])[0 ]
0 commit comments