Skip to content

Commit 3afd677

Browse files
committed
moved uncommon code into subclasses
1 parent b9d90ee commit 3afd677

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

adafruit_lsm6ds.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ class LSM6DS: #pylint: disable=too-many-instance-attributes
189189
_gyro_range_4000dps = RWBit(_LSM6DS_CTRL2_G, 0)
190190

191191
_sw_reset = RWBit(_LSM6DS_CTRL3_C, 0)
192-
_if_inc = RWBit(_LSM6DS_CTRL3_C, 2)
193192
_sim = RWBit(_LSM6DS_CTRL3_C, 3)
194193
_pp_od = RWBit(_LSM6DS_CTRL3_C, 4)
195194
_h_lactive = RWBit(_LSM6DS_CTRL3_C, 5)
@@ -223,18 +222,16 @@ def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
223222
self.reset()
224223

225224
self._bdu = True
226-
self._i3c_disable = True
227-
self._if_inc = True
228225

229-
self._accel_data_rate = Rate.RATE_104_HZ #pylint: disable=no-member
230-
self._gyro_data_rate = Rate.RATE_104_HZ #pylint: disable=no-member
226+
self.accel_data_rate = Rate.RATE_104_HZ #pylint: disable=no-member
227+
self.gyro_data_rate = Rate.RATE_104_HZ #pylint: disable=no-member
228+
229+
self.accel_range = AccelRange.RANGE_4G #pylint: disable=no-member
230+
self.gyro_range = GyroRange.RANGE_250_DPS #pylint: disable=no-member
231231

232-
self._accel_range = AccelRange.RANGE_4G #pylint: disable=no-member
233232
self._cached_accel_range = self._accel_range
234-
self._gyro_range = GyroRange.RANGE_250_DPS #pylint: disable=no-member
235233
self._cached_gyro_range = self._gyro_range
236234

237-
238235
def reset(self):
239236
"Resets the sensor's configuration into an initial state"
240237
self._sw_reset = True
@@ -244,12 +241,6 @@ def reset(self):
244241
while self._boot:
245242
sleep(0.001)
246243

247-
@property
248-
def is_lsm6dsox(self):
249-
"""Returns `True` if the connected sensor is an LSM6DSOX,
250-
`False` if not, it's an ICM330DHCT"""
251-
return self._chip_id is _LSM6DS_CHIP_ID
252-
253244
@property
254245
def acceleration(self):
255246
"""The x, y, z acceleration values returned in a 3-tuple and are in m / s ^ 2."""
@@ -358,6 +349,9 @@ class LSM6DSOX(LSM6DS): #pylint: disable=too-many-instance-attributes
358349
359350
"""
360351
CHIP_ID = _LSM6DS_CHIP_ID
352+
def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
353+
super().__init__(i2c_bus, address)
354+
self._i3c_disable = True
361355

362356
class LSM6DS33(LSM6DS): #pylint: disable=too-many-instance-attributes
363357

@@ -378,3 +372,8 @@ class ISM330DHCT(LSM6DS): #pylint: disable=too-many-instance-attributes
378372
379373
"""
380374
CHIP_ID = _ISM330DHCT_CHIP_ID
375+
def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
376+
super().__init__(i2c_bus, address)
377+
378+
# Called DEVICE_CONF in the datasheet, but it recommends setting it
379+
self._i3c_disable = True

0 commit comments

Comments
 (0)