65
65
_CMD_REG_CONF2 = const (0x01 ) # Burst, comm mode, temperature compensation
66
66
_CMD_REG_CONF3 = const (0x02 ) # Oversampling, Filter, Resolution
67
67
_CMD_REG_CONF4 = const (0x03 ) # Sensitivity drift
68
+ _CMD_REG_CONF5 = const (0x04 ) # X-axis Offset Correction
69
+ _CMD_REG_CONF6 = const (0x05 ) # Y-axis Offset Correction
70
+ _CMD_REG_CONF7 = const (0x06 ) # Z-axis Offset Correction
68
71
69
72
# Gain settings
70
73
GAIN_5X = 0x0
@@ -212,6 +215,7 @@ def __init__( # pylint: disable=too-many-arguments
212
215
filt : int = FILTER_7 ,
213
216
oversampling : int = OSR_3 ,
214
217
temperature_compensation : bool = False ,
218
+ offset : int = 0 ,
215
219
debug : bool = False ,
216
220
) -> None :
217
221
self .i2c_device = I2CDevice (i2c_bus , address )
@@ -222,6 +226,7 @@ def __init__( # pylint: disable=too-many-arguments
222
226
self ._osr = oversampling
223
227
self ._gain_current = gain
224
228
self ._temperature_compensation = temperature_compensation
229
+ self ._off_x = self ._off_y = self ._off_z = offset
225
230
226
231
# Put the device in a known state to start
227
232
self .reset ()
@@ -241,6 +246,11 @@ def __init__( # pylint: disable=too-many-arguments
241
246
self .gain = self ._gain_current
242
247
self .temperature_compensation = self ._temperature_compensation
243
248
249
+ # Set offsets to supplied level
250
+ self .offset_x = self ._off_x
251
+ self .offset_y = self ._off_y
252
+ self .offset_z = self ._off_z
253
+
244
254
def _transceive (self , payload : ReadableBuffer , rxlen : int = 0 ) -> bytearray :
245
255
"""
246
256
Writes the specified 'payload' to the sensor
@@ -402,6 +412,48 @@ def temperature_compensation(self, temperature_compensation: bool) -> None:
402
412
self .write_reg (_CMD_REG_CONF2 , reg )
403
413
self ._temperature_compensation = temperature_compensation
404
414
415
+ @property
416
+ def offset_x (self ) -> int :
417
+ """The X axis offset."""
418
+ return self ._off_x
419
+
420
+ @offset_x .setter
421
+ def offset_x (self , offset : int ) -> None :
422
+ self ._set_offset (0 , offset )
423
+ self ._off_x = offset
424
+
425
+ @property
426
+ def offset_y (self ) -> int :
427
+ """The Y axis offset."""
428
+ return self ._off_y
429
+
430
+ @offset_y .setter
431
+ def offset_y (self , offset : int ) -> None :
432
+ self ._set_offset (1 , offset )
433
+ self ._off_y = offset
434
+
435
+ @property
436
+ def offset_z (self ) -> int :
437
+ """The Z axis offset."""
438
+ return self ._off_z
439
+
440
+ @offset_z .setter
441
+ def offset_z (self , offset : int ) -> None :
442
+ self ._set_offset (2 , offset )
443
+ self ._off_z = offset
444
+
445
+ def _set_offset (self , axis : int , offset : int ) -> None :
446
+ if offset < 0x0000 or offset > 0xFFFF :
447
+ raise ValueError ("Incorrect offset setting." )
448
+ if axis == 0 :
449
+ self .write_reg (_CMD_REG_CONF5 , offset )
450
+ elif axis == 1 :
451
+ self .write_reg (_CMD_REG_CONF6 , offset )
452
+ elif axis == 2 :
453
+ self .write_reg (_CMD_REG_CONF7 , offset )
454
+ else :
455
+ raise ValueError ("Incorrect axis setting." )
456
+
405
457
def display_status (self ) -> None :
406
458
"""
407
459
Prints out the content of the last status byte in a human-readable
0 commit comments