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,74 @@ 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
+
125
+ AccelRange .add_values (
126
+ (
127
+ ("RANGE_2G" , 0 , 2 , 0.061 ),
128
+ ("RANGE_16G" , 1 , 16 , 0.488 ),
129
+ ("RANGE_4G" , 2 , 4 , 0.122 ),
130
+ ("RANGE_8G" , 3 , 8 , 0.244 ),
131
+ )
132
+ )
133
+
128
134
129
135
class GyroRange (CV ):
130
136
"""Options for ``gyro_data_range``"""
131
- pass #pylint: disable=unnecessary-pass
132
137
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
- ))
138
+
139
+ GyroRange .add_values (
140
+ (
141
+ ("RANGE_125_DPS" , 125 , 125 , 4.375 ),
142
+ ("RANGE_250_DPS" , 0 , 250 , 8.75 ),
143
+ ("RANGE_500_DPS" , 1 , 500 , 17.50 ),
144
+ ("RANGE_1000_DPS" , 2 , 1000 , 35.0 ),
145
+ ("RANGE_2000_DPS" , 3 , 2000 , 70.0 ),
146
+ ("RANGE_4000_DPS" , 4000 , 4000 , 140.0 ),
147
+ )
148
+ )
149
+
141
150
142
151
class Rate (CV ):
143
152
"""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
- ))
153
+
154
+
155
+ Rate .add_values (
156
+ (
157
+ ("RATE_SHUTDOWN" , 0 , 0 , None ),
158
+ ("RATE_12_5_HZ" , 1 , 12.5 , None ),
159
+ ("RATE_26_HZ" , 2 , 26.0 , None ),
160
+ ("RATE_52_HZ" , 3 , 52.0 , None ),
161
+ ("RATE_104_HZ" , 4 , 104.0 , None ),
162
+ ("RATE_208_HZ" , 5 , 208.0 , None ),
163
+ ("RATE_416_HZ" , 6 , 416.0 , None ),
164
+ ("RATE_833_HZ" , 7 , 833.0 , None ),
165
+ ("RATE_1_66K_HZ" , 8 , 1066.0 , None ),
166
+ ("RATE_3_33K_HZ" , 9 , 3033.0 , None ),
167
+ ("RATE_6_66K_HZ" , 10 , 6066.0 , None ),
168
+ ("RATE_1_6_HZ" , 11 , 1.6 , None ),
169
+ )
170
+ )
171
+
160
172
161
173
class AccelHPF (CV ):
162
174
"""Options for the accelerometer high pass filter"""
163
- pass #pylint: disable=unnecessary-pass
164
175
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
- ))
171
176
177
+ AccelHPF .add_values (
178
+ (
179
+ ("SLOPE" , 0 , 0 , None ),
180
+ ("HPF_DIV100" , 1 , 0 , None ),
181
+ ("HPF_DIV9" , 2 , 0 , None ),
182
+ ("HPF_DIV400" , 3 , 0 , None ),
183
+ )
184
+ )
172
185
173
- class LSM6DS : #pylint: disable=too-many-instance-attributes
186
+
187
+ class LSM6DS : # pylint: disable=too-many-instance-attributes
174
188
175
189
"""Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.
176
190
@@ -179,11 +193,11 @@ class LSM6DS: #pylint: disable=too-many-instance-attributes
179
193
180
194
"""
181
195
182
- # ROUnaryStructs:
196
+ # ROUnaryStructs:
183
197
_chip_id = ROUnaryStruct (_LSM6DS_WHOAMI , "<b" )
184
198
_temperature = ROUnaryStruct (_LSM6DS_OUT_TEMP_L , "<h" )
185
199
186
- # RWBits:
200
+ # RWBits:
187
201
_ois_ctrl_from_ui = RWBit (_LSM6DS_FUNC_CFG_ACCESS , 0 )
188
202
_shub_reg_access = RWBit (_LSM6DS_FUNC_CFG_ACCESS , 6 )
189
203
_func_cfg_access = RWBit (_LSM6DS_FUNC_CFG_ACCESS , 7 )
@@ -245,16 +259,18 @@ def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
245
259
if self .CHIP_ID is None :
246
260
raise AttributeError ("LSM6DS Parent Class cannot be directly instantiated" )
247
261
if self ._chip_id != self .CHIP_ID :
248
- raise RuntimeError ("Failed to find %s - check your wiring!" % self .__class__ .__name__ )
262
+ raise RuntimeError (
263
+ "Failed to find %s - check your wiring!" % self .__class__ .__name__
264
+ )
249
265
self .reset ()
250
266
251
267
self ._bdu = True
252
268
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
269
+ self .accelerometer_data_rate = Rate .RATE_104_HZ # pylint: disable=no-member
270
+ self .gyro_data_rate = Rate .RATE_104_HZ # pylint: disable=no-member
255
271
256
- self .accelerometer_range = AccelRange .RANGE_4G # pylint: disable=no-member
257
- self .gyro_range = GyroRange .RANGE_250_DPS # pylint: disable=no-member
272
+ self .accelerometer_range = AccelRange .RANGE_4G # pylint: disable=no-member
273
+ self .gyro_range = GyroRange .RANGE_250_DPS # pylint: disable=no-member
258
274
259
275
def reset (self ):
260
276
"Resets the sensor's configuration into an initial state"
@@ -273,7 +289,7 @@ def acceleration(self):
273
289
y = self ._scale_xl_data (raw_accel_data [1 ])
274
290
z = self ._scale_xl_data (raw_accel_data [2 ])
275
291
276
- return (x , y , z )
292
+ return (x , y , z )
277
293
278
294
@property
279
295
def gyro (self ):
@@ -286,7 +302,11 @@ def gyro(self):
286
302
return (x , y , z )
287
303
288
304
def _scale_xl_data (self , raw_measurement ):
289
- return raw_measurement * AccelRange .lsb [self ._cached_accel_range ] * _MILLI_G_TO_ACCEL
305
+ return (
306
+ raw_measurement
307
+ * AccelRange .lsb [self ._cached_accel_range ]
308
+ * _MILLI_G_TO_ACCEL
309
+ )
290
310
291
311
def _scale_gyro_data (self , raw_measurement ):
292
312
return raw_measurement * GyroRange .lsb [self ._cached_gyro_range ] / 1000
@@ -297,14 +317,14 @@ def accelerometer_range(self):
297
317
Note that larger ranges will be less accurate. Must be an `AccelRange`"""
298
318
return self ._cached_accel_range
299
319
300
- #pylint: disable=no-member
320
+ # pylint: disable=no-member
301
321
@accelerometer_range .setter
302
322
def accelerometer_range (self , value ):
303
323
if not AccelRange .is_valid (value ):
304
324
raise AttributeError ("range must be an `AccelRange`" )
305
325
self ._accel_range = value
306
326
self ._cached_accel_range = value
307
- sleep (.2 ) # needed to let new range settle
327
+ sleep (0 .2 ) # needed to let new range settle
308
328
309
329
@property
310
330
def gyro_range (self ):
@@ -332,9 +352,9 @@ def gyro_range(self, value):
332
352
self ._gyro_range = value
333
353
334
354
self ._cached_gyro_range = value
335
- sleep (.2 ) # needed to let new range settle
355
+ sleep (0 .2 ) # needed to let new range settle
336
356
337
- #pylint: enable=no-member
357
+ # pylint: enable=no-member
338
358
339
359
@property
340
360
def accelerometer_data_rate (self ):
@@ -350,7 +370,6 @@ def accelerometer_data_rate(self, value):
350
370
self ._accel_data_rate = value
351
371
# sleep(.2) # needed to let new range settle
352
372
353
-
354
373
@property
355
374
def gyro_data_rate (self ):
356
375
"""Select the rate at which the gyro takes measurements. Must be a `Rate`"""
@@ -387,38 +406,45 @@ def high_pass_filter(self, value):
387
406
self ._pass_filter = value
388
407
389
408
390
- class LSM6DSOX (LSM6DS ): # pylint: disable=too-many-instance-attributes
409
+ class LSM6DSOX (LSM6DS ): # pylint: disable=too-many-instance-attributes
391
410
392
411
"""Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.
393
412
394
413
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DSOX is connected to.
395
414
:param address: The I2C slave address of the sensor
396
415
397
416
"""
417
+
398
418
CHIP_ID = _LSM6DS_CHIP_ID
419
+
399
420
def __init__ (self , i2c_bus , address = _LSM6DS_DEFAULT_ADDRESS ):
400
421
super ().__init__ (i2c_bus , address )
401
422
self ._i3c_disable = True
402
423
403
- class LSM6DS33 (LSM6DS ): #pylint: disable=too-many-instance-attributes
424
+
425
+ class LSM6DS33 (LSM6DS ): # pylint: disable=too-many-instance-attributes
404
426
405
427
"""Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
406
428
407
429
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DS33 is connected to.
408
430
:param address: The I2C slave address of the sensor
409
431
410
432
"""
433
+
411
434
CHIP_ID = _LSM6DS33_CHIP_ID
412
435
413
- class ISM330DHCT (LSM6DS ): #pylint: disable=too-many-instance-attributes
436
+
437
+ class ISM330DHCT (LSM6DS ): # pylint: disable=too-many-instance-attributes
414
438
415
439
"""Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
416
440
417
441
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DS33 is connected to.
418
442
:param address: The I2C slave address of the sensor
419
443
420
444
"""
445
+
421
446
CHIP_ID = _ISM330DHCT_CHIP_ID
447
+
422
448
def __init__ (self , i2c_bus , address = _LSM6DS_DEFAULT_ADDRESS ):
423
449
super ().__init__ (i2c_bus , address )
424
450
0 commit comments