54
54
from adafruit_register .i2c_struct import ROUnaryStruct , Struct
55
55
from adafruit_register .i2c_bits import RWBits
56
56
from adafruit_register .i2c_bit import RWBit
57
+
57
58
__version__ = "0.0.0-auto.0"
58
59
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DSOX.git"
59
60
60
61
61
- _LSM6DS_DEFAULT_ADDRESS = const (0x6a )
62
+ _LSM6DS_DEFAULT_ADDRESS = const (0x6A )
62
63
63
64
_LSM6DS_CHIP_ID = const (0x6C )
64
65
_ISM330DHCT_CHIP_ID = const (0x6B )
95
96
96
97
_MILLI_G_TO_ACCEL = 0.00980665
97
98
99
+
98
100
class CV :
99
101
"""struct helper"""
100
102
@@ -115,62 +117,82 @@ def is_valid(cls, value):
115
117
"Returns true if the given value is a member of the CV"
116
118
return value in cls .string
117
119
120
+
118
121
class AccelRange (CV ):
119
122
"""Options for ``accelerometer_range``"""
120
- pass #pylint: disable=unnecessary-pass
121
123
122
- AccelRange .add_values ((
123
- ('RANGE_2G' , 0 , 2 , 0.061 ),
124
- ('RANGE_16G' , 1 , 16 , 0.488 ),
125
- ('RANGE_4G' , 2 , 4 , 0.122 ),
126
- ('RANGE_8G' , 3 , 8 , 0.244 )
127
- ))
124
+ pass # pylint: disable=unnecessary-pass
125
+
126
+
127
+ AccelRange .add_values (
128
+ (
129
+ ("RANGE_2G" , 0 , 2 , 0.061 ),
130
+ ("RANGE_16G" , 1 , 16 , 0.488 ),
131
+ ("RANGE_4G" , 2 , 4 , 0.122 ),
132
+ ("RANGE_8G" , 3 , 8 , 0.244 ),
133
+ )
134
+ )
135
+
128
136
129
137
class GyroRange (CV ):
130
138
"""Options for ``gyro_data_range``"""
131
- pass #pylint: disable=unnecessary-pass
132
139
133
- GyroRange .add_values ((
134
- ('RANGE_125_DPS' , 125 , 125 , 4.375 ),
135
- ('RANGE_250_DPS' , 0 , 250 , 8.75 ),
136
- ('RANGE_500_DPS' , 1 , 500 , 17.50 ),
137
- ('RANGE_1000_DPS' , 2 , 1000 , 35.0 ),
138
- ('RANGE_2000_DPS' , 3 , 2000 , 70.0 ),
139
- ('RANGE_4000_DPS' , 4000 , 4000 , 140.0 )
140
- ))
140
+ pass # pylint: disable=unnecessary-pass
141
+
142
+
143
+ GyroRange .add_values (
144
+ (
145
+ ("RANGE_125_DPS" , 125 , 125 , 4.375 ),
146
+ ("RANGE_250_DPS" , 0 , 250 , 8.75 ),
147
+ ("RANGE_500_DPS" , 1 , 500 , 17.50 ),
148
+ ("RANGE_1000_DPS" , 2 , 1000 , 35.0 ),
149
+ ("RANGE_2000_DPS" , 3 , 2000 , 70.0 ),
150
+ ("RANGE_4000_DPS" , 4000 , 4000 , 140.0 ),
151
+ )
152
+ )
153
+
141
154
142
155
class Rate (CV ):
143
156
"""Options for ``accelerometer_data_rate`` and ``gyro_data_rate``"""
144
- pass #pylint: disable=unnecessary-pass
145
-
146
- Rate .add_values ((
147
- ('RATE_SHUTDOWN' , 0 , 0 , None ),
148
- ('RATE_12_5_HZ' , 1 , 12.5 , None ),
149
- ('RATE_26_HZ' , 2 , 26.0 , None ),
150
- ('RATE_52_HZ' , 3 , 52.0 , None ),
151
- ('RATE_104_HZ' , 4 , 104.0 , None ),
152
- ('RATE_208_HZ' , 5 , 208.0 , None ),
153
- ('RATE_416_HZ' , 6 , 416.0 , None ),
154
- ('RATE_833_HZ' , 7 , 833.0 , None ),
155
- ('RATE_1_66K_HZ' , 8 , 1066.0 , None ),
156
- ('RATE_3_33K_HZ' , 9 , 3033.0 , None ),
157
- ('RATE_6_66K_HZ' , 10 , 6066.0 , None ),
158
- ('RATE_1_6_HZ' , 11 , 1.6 , None )
159
- ))
157
+
158
+ pass # pylint: disable=unnecessary-pass
159
+
160
+
161
+ Rate .add_values (
162
+ (
163
+ ("RATE_SHUTDOWN" , 0 , 0 , None ),
164
+ ("RATE_12_5_HZ" , 1 , 12.5 , None ),
165
+ ("RATE_26_HZ" , 2 , 26.0 , None ),
166
+ ("RATE_52_HZ" , 3 , 52.0 , None ),
167
+ ("RATE_104_HZ" , 4 , 104.0 , None ),
168
+ ("RATE_208_HZ" , 5 , 208.0 , None ),
169
+ ("RATE_416_HZ" , 6 , 416.0 , None ),
170
+ ("RATE_833_HZ" , 7 , 833.0 , None ),
171
+ ("RATE_1_66K_HZ" , 8 , 1066.0 , None ),
172
+ ("RATE_3_33K_HZ" , 9 , 3033.0 , None ),
173
+ ("RATE_6_66K_HZ" , 10 , 6066.0 , None ),
174
+ ("RATE_1_6_HZ" , 11 , 1.6 , None ),
175
+ )
176
+ )
177
+
160
178
161
179
class AccelHPF (CV ):
162
180
"""Options for the accelerometer high pass filter"""
163
- pass #pylint: disable=unnecessary-pass
164
181
165
- AccelHPF .add_values ((
166
- ('SLOPE' , 0 , 0 , None ),
167
- ('HPF_DIV100' , 1 , 0 , None ),
168
- ('HPF_DIV9' , 2 , 0 , None ),
169
- ('HPF_DIV400' , 3 , 0 , None ),
170
- ))
182
+ pass # pylint: disable=unnecessary-pass
183
+
184
+
185
+ AccelHPF .add_values (
186
+ (
187
+ ("SLOPE" , 0 , 0 , None ),
188
+ ("HPF_DIV100" , 1 , 0 , None ),
189
+ ("HPF_DIV9" , 2 , 0 , None ),
190
+ ("HPF_DIV400" , 3 , 0 , None ),
191
+ )
192
+ )
171
193
172
194
173
- class LSM6DS : # pylint: disable=too-many-instance-attributes
195
+ class LSM6DS : # pylint: disable=too-many-instance-attributes
174
196
175
197
"""Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.
176
198
@@ -179,11 +201,11 @@ class LSM6DS: #pylint: disable=too-many-instance-attributes
179
201
180
202
"""
181
203
182
- # ROUnaryStructs:
204
+ # ROUnaryStructs:
183
205
_chip_id = ROUnaryStruct (_LSM6DS_WHOAMI , "<b" )
184
206
_temperature = ROUnaryStruct (_LSM6DS_OUT_TEMP_L , "<h" )
185
207
186
- # RWBits:
208
+ # RWBits:
187
209
_ois_ctrl_from_ui = RWBit (_LSM6DS_FUNC_CFG_ACCESS , 0 )
188
210
_shub_reg_access = RWBit (_LSM6DS_FUNC_CFG_ACCESS , 6 )
189
211
_func_cfg_access = RWBit (_LSM6DS_FUNC_CFG_ACCESS , 7 )
@@ -245,16 +267,18 @@ def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
245
267
if self .CHIP_ID is None :
246
268
raise AttributeError ("LSM6DS Parent Class cannot be directly instantiated" )
247
269
if self ._chip_id != self .CHIP_ID :
248
- raise RuntimeError ("Failed to find %s - check your wiring!" % self .__class__ .__name__ )
270
+ raise RuntimeError (
271
+ "Failed to find %s - check your wiring!" % self .__class__ .__name__
272
+ )
249
273
self .reset ()
250
274
251
275
self ._bdu = True
252
276
253
- self .accelerometer_data_rate = Rate .RATE_104_HZ # pylint: disable=no-member
254
- self .gyro_data_rate = Rate .RATE_104_HZ # pylint: disable=no-member
277
+ self .accelerometer_data_rate = Rate .RATE_104_HZ # pylint: disable=no-member
278
+ self .gyro_data_rate = Rate .RATE_104_HZ # pylint: disable=no-member
255
279
256
- self .accelerometer_range = AccelRange .RANGE_4G # pylint: disable=no-member
257
- self .gyro_range = GyroRange .RANGE_250_DPS # pylint: disable=no-member
280
+ self .accelerometer_range = AccelRange .RANGE_4G # pylint: disable=no-member
281
+ self .gyro_range = GyroRange .RANGE_250_DPS # pylint: disable=no-member
258
282
259
283
def reset (self ):
260
284
"Resets the sensor's configuration into an initial state"
@@ -273,7 +297,7 @@ def acceleration(self):
273
297
y = self ._scale_xl_data (raw_accel_data [1 ])
274
298
z = self ._scale_xl_data (raw_accel_data [2 ])
275
299
276
- return (x , y , z )
300
+ return (x , y , z )
277
301
278
302
@property
279
303
def gyro (self ):
@@ -286,7 +310,11 @@ def gyro(self):
286
310
return (x , y , z )
287
311
288
312
def _scale_xl_data (self , raw_measurement ):
289
- return raw_measurement * AccelRange .lsb [self ._cached_accel_range ] * _MILLI_G_TO_ACCEL
313
+ return (
314
+ raw_measurement
315
+ * AccelRange .lsb [self ._cached_accel_range ]
316
+ * _MILLI_G_TO_ACCEL
317
+ )
290
318
291
319
def _scale_gyro_data (self , raw_measurement ):
292
320
return raw_measurement * GyroRange .lsb [self ._cached_gyro_range ] / 1000
@@ -297,14 +325,14 @@ def accelerometer_range(self):
297
325
Note that larger ranges will be less accurate. Must be an `AccelRange`"""
298
326
return self ._cached_accel_range
299
327
300
- #pylint: disable=no-member
328
+ # pylint: disable=no-member
301
329
@accelerometer_range .setter
302
330
def accelerometer_range (self , value ):
303
331
if not AccelRange .is_valid (value ):
304
332
raise AttributeError ("range must be an `AccelRange`" )
305
333
self ._accel_range = value
306
334
self ._cached_accel_range = value
307
- sleep (.2 ) # needed to let new range settle
335
+ sleep (0 .2 ) # needed to let new range settle
308
336
309
337
@property
310
338
def gyro_range (self ):
@@ -332,9 +360,9 @@ def gyro_range(self, value):
332
360
self ._gyro_range = value
333
361
334
362
self ._cached_gyro_range = value
335
- sleep (.2 ) # needed to let new range settle
363
+ sleep (0 .2 ) # needed to let new range settle
336
364
337
- #pylint: enable=no-member
365
+ # pylint: enable=no-member
338
366
339
367
@property
340
368
def accelerometer_data_rate (self ):
@@ -350,7 +378,6 @@ def accelerometer_data_rate(self, value):
350
378
self ._accel_data_rate = value
351
379
# sleep(.2) # needed to let new range settle
352
380
353
-
354
381
@property
355
382
def gyro_data_rate (self ):
356
383
"""Select the rate at which the gyro takes measurements. Must be a `Rate`"""
@@ -387,38 +414,45 @@ def high_pass_filter(self, value):
387
414
self ._pass_filter = value
388
415
389
416
390
- class LSM6DSOX (LSM6DS ): # pylint: disable=too-many-instance-attributes
417
+ class LSM6DSOX (LSM6DS ): # pylint: disable=too-many-instance-attributes
391
418
392
419
"""Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.
393
420
394
421
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DSOX is connected to.
395
422
:param address: The I2C slave address of the sensor
396
423
397
424
"""
425
+
398
426
CHIP_ID = _LSM6DS_CHIP_ID
427
+
399
428
def __init__ (self , i2c_bus , address = _LSM6DS_DEFAULT_ADDRESS ):
400
429
super ().__init__ (i2c_bus , address )
401
430
self ._i3c_disable = True
402
431
403
- class LSM6DS33 (LSM6DS ): #pylint: disable=too-many-instance-attributes
432
+
433
+ class LSM6DS33 (LSM6DS ): # pylint: disable=too-many-instance-attributes
404
434
405
435
"""Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
406
436
407
437
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DS33 is connected to.
408
438
:param address: The I2C slave address of the sensor
409
439
410
440
"""
441
+
411
442
CHIP_ID = _LSM6DS33_CHIP_ID
412
443
413
- class ISM330DHCT (LSM6DS ): #pylint: disable=too-many-instance-attributes
444
+
445
+ class ISM330DHCT (LSM6DS ): # pylint: disable=too-many-instance-attributes
414
446
415
447
"""Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
416
448
417
449
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DS33 is connected to.
418
450
:param address: The I2C slave address of the sensor
419
451
420
452
"""
453
+
421
454
CHIP_ID = _ISM330DHCT_CHIP_ID
455
+
422
456
def __init__ (self , i2c_bus , address = _LSM6DS_DEFAULT_ADDRESS ):
423
457
super ().__init__ (i2c_bus , address )
424
458
0 commit comments