@@ -126,10 +126,12 @@ class GyroRange(CV):
126126 pass #pylint: disable=unnecessary-pass
127127
128128GyroRange .add_values ((
129+ ('RANGE_125_DPS' , 125 , 125 , 4.375 ),
129130 ('RANGE_250_DPS' , 0 , 250 , 8.75 ),
130131 ('RANGE_500_DPS' , 1 , 500 , 17.50 ),
131132 ('RANGE_1000_DPS' , 2 , 1000 , 35.0 ),
132- ('RANGE_2000_DPS' , 3 , 2000 , 70.0 )
133+ ('RANGE_2000_DPS' , 3 , 2000 , 70.0 ),
134+ ('RANGE_4000_DPS' , 4000 , 4000 , 140.0 )
133135))
134136
135137class Rate (CV ):
@@ -181,6 +183,7 @@ class LSM6DSOX: #pylint: disable=too-many-instance-attributes
181183
182184 _gyro_data_rate = RWBits (4 , _LSM6DSOX_CTRL2_G , 4 )
183185 _gyro_range = RWBits (2 , _LSM6DSOX_CTRL2_G , 2 )
186+ _gyro_range_125dps = RWBit (_LSM6DSOX_CTRL2_G , 1 )
184187
185188 _sw_reset = RWBit (_LSM6DSOX_CTRL3_C , 0 )
186189 _if_inc = RWBit (_LSM6DSOX_CTRL3_C , 2 )
@@ -237,6 +240,12 @@ def reset(self):
237240 while self ._boot :
238241 sleep (0.001 )
239242
243+ @property
244+ def is_lsm6dsox (self ):
245+ """Returns `True` if the connected sensor is an LSM6DSOX,
246+ `False` if not, it's an ICM330DHCX"""
247+ return self ._chip_id is _LSM6DSOX_CHIP_ID
248+
240249 @property
241250 def acceleration (self ):
242251 """The x, y, z acceleration values returned in a 3-tuple and are in m / s ^ 2."""
@@ -269,8 +278,9 @@ def accelerometer_range(self):
269278 Note that larger ranges will be less accurate. Must be an `AccelRange`"""
270279 return self ._cached_accel_range
271280
281+ #pylint: disable=no-member
272282 @accelerometer_range .setter
273- def accelerometer_range (self , value ): #pylint: disable=no-member
283+ def accelerometer_range (self , value ):
274284 if not AccelRange .is_valid (value ):
275285 raise AttributeError ("range must be an `AccelRange`" )
276286 self ._accel_range = value
@@ -279,18 +289,34 @@ def accelerometer_range(self, value): #pylint: disable=no-member
279289
280290 @property
281291 def gyro_range (self ):
282- """Adjusts the range of values that the sensor can measure, from 250 Degrees/second to 2000
283- degrees/s. Note that larger ranges will be less accurate. Must be a `GyroRange`"""
292+ """Adjusts the range of values that the sensor can measure, from 125 Degrees/second to 4000
293+ degrees/s. Note that larger ranges will be less accurate. Must be a `GyroRange`. 4000 DPS
294+ is only available for the ISM330DHCX"""
284295 return self ._cached_gyro_range
285296
286297 @gyro_range .setter
287298 def gyro_range (self , value ):
288299 if not GyroRange .is_valid (value ):
289300 raise AttributeError ("range must be a `GyroRange`" )
290- self ._gyro_range = value
301+ if value is GyroRange .RANGE_4000_DPS and self .is_lsm6dsox :
302+ raise AttributeError ("4000 DPS is only available for ISM330DHCX" )
303+
304+ if value is GyroRange .RANGE_125_DPS :
305+ self ._gyro_range_125dps = True
306+ self ._gyro_range_4000dps = False
307+ elif value is GyroRange .RANGE_4000_DPS :
308+ self ._gyro_range_125dps = False
309+ self ._gyro_range_4000dps = True
310+ else :
311+ self ._gyro_range_125dps = False
312+ self ._gyro_range_4000dps = True
313+ self ._gyro_range = value
314+
291315 self ._cached_gyro_range = value
292316 sleep (.2 ) # needed to let new range settle
293317
318+ #pylint: enable=no-member
319+
294320 @property
295321 def accelerometer_data_rate (self ):
296322 """Select the rate at which the accelerometer takes measurements. Must be a `Rate`"""
0 commit comments