@@ -126,10 +126,12 @@ class GyroRange(CV):
126
126
pass #pylint: disable=unnecessary-pass
127
127
128
128
GyroRange .add_values ((
129
+ ('RANGE_125_DPS' , 125 , 125 , 4.375 ),
129
130
('RANGE_250_DPS' , 0 , 250 , 8.75 ),
130
131
('RANGE_500_DPS' , 1 , 500 , 17.50 ),
131
132
('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 )
133
135
))
134
136
135
137
class Rate (CV ):
@@ -181,6 +183,7 @@ class LSM6DSOX: #pylint: disable=too-many-instance-attributes
181
183
182
184
_gyro_data_rate = RWBits (4 , _LSM6DSOX_CTRL2_G , 4 )
183
185
_gyro_range = RWBits (2 , _LSM6DSOX_CTRL2_G , 2 )
186
+ _gyro_range_125dps = RWBit (_LSM6DSOX_CTRL2_G , 1 )
184
187
185
188
_sw_reset = RWBit (_LSM6DSOX_CTRL3_C , 0 )
186
189
_if_inc = RWBit (_LSM6DSOX_CTRL3_C , 2 )
@@ -237,6 +240,12 @@ def reset(self):
237
240
while self ._boot :
238
241
sleep (0.001 )
239
242
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
+
240
249
@property
241
250
def acceleration (self ):
242
251
"""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):
269
278
Note that larger ranges will be less accurate. Must be an `AccelRange`"""
270
279
return self ._cached_accel_range
271
280
281
+ #pylint: disable=no-member
272
282
@accelerometer_range .setter
273
- def accelerometer_range (self , value ): #pylint: disable=no-member
283
+ def accelerometer_range (self , value ):
274
284
if not AccelRange .is_valid (value ):
275
285
raise AttributeError ("range must be an `AccelRange`" )
276
286
self ._accel_range = value
@@ -279,18 +289,34 @@ def accelerometer_range(self, value): #pylint: disable=no-member
279
289
280
290
@property
281
291
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"""
284
295
return self ._cached_gyro_range
285
296
286
297
@gyro_range .setter
287
298
def gyro_range (self , value ):
288
299
if not GyroRange .is_valid (value ):
289
300
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
+
291
315
self ._cached_gyro_range = value
292
316
sleep (.2 ) # needed to let new range settle
293
317
318
+ #pylint: enable=no-member
319
+
294
320
@property
295
321
def accelerometer_data_rate (self ):
296
322
"""Select the rate at which the accelerometer takes measurements. Must be a `Rate`"""
0 commit comments