@@ -266,29 +266,23 @@ def _write_8(self, address, data):
266
266
def _write_16 (self , address , data ):
267
267
# Write a 16-bit big endian value to the specified 16-bit register
268
268
# address.
269
- with self ._device :
270
- self . _device .write (bytes ([(address >> 8 ) & 0xFF ,
271
- address & 0xFF ,
272
- (data >> 8 ) & 0xFF ,
273
- data & 0xFF ]))
269
+ with self ._device as i2c :
270
+ i2c .write (bytes ([(address >> 8 ) & 0xFF ,
271
+ address & 0xFF ,
272
+ (data >> 8 ) & 0xFF ,
273
+ data & 0xFF ]))
274
274
275
275
def _read_8 (self , address ):
276
276
# Read and return a byte from the specified 16-bit register address.
277
- with self ._device :
278
- self ._device .write (bytes ([(address >> 8 ) & 0xFF ,
279
- address & 0xFF ]),
280
- stop = False )
277
+ with self ._device as i2c :
281
278
result = bytearray (1 )
282
- self . _device . readinto ( result )
279
+ i2c . write_then_readinto ( bytes ([( address >> 8 ) & 0xFF , address & 0xFF ]), result )
283
280
return result [0 ]
284
281
285
282
def _read_16 (self , address ):
286
283
# Read and return a 16-bit unsigned big endian value read from the
287
284
# specified 16-bit register address.
288
- with self ._device :
289
- self ._device .write (bytes ([(address >> 8 ) & 0xFF ,
290
- address & 0xFF ]),
291
- stop = False )
285
+ with self ._device as i2c :
292
286
result = bytearray (2 )
293
- self . _device . readinto ( result )
287
+ i2c . write_then_readinto ( bytes ([( address >> 8 ) & 0xFF , address & 0xFF ]), result )
294
288
return (result [0 ] << 8 ) | result [1 ]
0 commit comments