54
54
from adafruit_register .i2c_bit import RWBit
55
55
from adafruit_register .i2c_bits import RWBits
56
56
57
- #pylint: disable=bad-whitespace
58
- _ICM20649_DEFAULT_ADDRESS = 0x68 # icm20649 default i2c address
59
- _ICM20649_DEVICE_ID = 0xE1 # Correct context of WHO_AM_I register
57
+ # pylint: disable=bad-whitespace
58
+ _ICM20649_DEFAULT_ADDRESS = 0x68 # icm20649 default i2c address
59
+ _ICM20649_DEVICE_ID = 0xE1 # Correct context of WHO_AM_I register
60
60
61
61
# Bank 0
62
62
_ICM20649_WHO_AM_I = 0x00 # device_id register
63
- _ICM20649_REG_BANK_SEL = 0x7F # register bank selection register
64
- _ICM20649_PWR_MGMT_1 = 0x06 # primary power management register
65
- _ICM20649_ACCEL_XOUT_H = 0x2D # first byte of accel data
66
- _ICM20649_GYRO_XOUT_H = 0x33 # first byte of accel data
63
+ _ICM20649_REG_BANK_SEL = 0x7F # register bank selection register
64
+ _ICM20649_PWR_MGMT_1 = 0x06 # primary power management register
65
+ _ICM20649_ACCEL_XOUT_H = 0x2D # first byte of accel data
66
+ _ICM20649_GYRO_XOUT_H = 0x33 # first byte of accel data
67
67
68
68
# Bank 2
69
69
_ICM20649_GYRO_SMPLRT_DIV = 0x00
70
- _ICM20649_GYRO_CONFIG_1 = 0x01
70
+ _ICM20649_GYRO_CONFIG_1 = 0x01
71
71
_ICM20649_ACCEL_SMPLRT_DIV_1 = 0x10
72
72
_ICM20649_ACCEL_SMPLRT_DIV_2 = 0x11
73
- _ICM20649_ACCEL_CONFIG_1 = 0x14
73
+ _ICM20649_ACCEL_CONFIG_1 = 0x14
74
74
75
75
76
- G_TO_ACCEL = 9.80665
77
- #pylint: enable=bad-whitespace
76
+ G_TO_ACCEL = 9.80665
77
+ # pylint: enable=bad-whitespace
78
78
class CV :
79
79
"""struct helper"""
80
80
@@ -96,31 +96,39 @@ def is_valid(cls, value):
96
96
return value in cls .string
97
97
98
98
99
-
100
99
class AccelRange (CV ):
101
100
"""Options for ``accelerometer_range``"""
102
- pass #pylint: disable=unnecessary-pass
103
101
104
- AccelRange .add_values ((
105
- ('RANGE_4G' , 0 , 4 , 8192 ),
106
- ('RANGE_8G' , 1 , 8 , 4096.0 ),
107
- ('RANGE_16G' , 2 , 16 , 2048 ),
108
- ('RANGE_30G' , 3 , 30 , 1024 ),
109
- ))
102
+ pass # pylint: disable=unnecessary-pass
103
+
104
+
105
+ AccelRange .add_values (
106
+ (
107
+ ("RANGE_4G" , 0 , 4 , 8192 ),
108
+ ("RANGE_8G" , 1 , 8 , 4096.0 ),
109
+ ("RANGE_16G" , 2 , 16 , 2048 ),
110
+ ("RANGE_30G" , 3 , 30 , 1024 ),
111
+ )
112
+ )
113
+
110
114
111
115
class GyroRange (CV ):
112
116
"""Options for ``gyro_data_range``"""
113
- pass #pylint: disable=unnecessary-pass
114
117
115
- GyroRange .add_values ((
116
- ('RANGE_500_DPS' , 0 , 500 , 65.5 ),
117
- ('RANGE_1000_DPS' , 1 , 1000 , 32.8 ),
118
- ('RANGE_2000_DPS' , 2 , 2000 , 16.4 ),
119
- ('RANGE_4000_DPS' , 3 , 4000 , 8.2 )
120
- ))
118
+ pass # pylint: disable=unnecessary-pass
121
119
122
120
123
- class ICM20649 : #pylint:disable=too-many-instance-attributes
121
+ GyroRange .add_values (
122
+ (
123
+ ("RANGE_500_DPS" , 0 , 500 , 65.5 ),
124
+ ("RANGE_1000_DPS" , 1 , 1000 , 32.8 ),
125
+ ("RANGE_2000_DPS" , 2 , 2000 , 16.4 ),
126
+ ("RANGE_4000_DPS" , 3 , 4000 , 8.2 ),
127
+ )
128
+ )
129
+
130
+
131
+ class ICM20649 : # pylint:disable=too-many-instance-attributes
124
132
"""Library for the ST ICM-20649 Wide-Range 6-DoF Accelerometer and Gyro.
125
133
126
134
:param ~busio.I2C i2c_bus: The I2C bus the ICM20649 is connected to.
@@ -159,19 +167,18 @@ def __init__(self, i2c_bus, address=_ICM20649_DEFAULT_ADDRESS):
159
167
self ._sleep = False
160
168
161
169
self ._bank = 2
162
- self ._accel_range = AccelRange .RANGE_8G # pylint: disable=no-member
170
+ self ._accel_range = AccelRange .RANGE_8G # pylint: disable=no-member
163
171
self ._cached_accel_range = self ._accel_range
164
172
165
- #TODO: CV-ify
173
+ # TODO: CV-ify
166
174
self ._accel_dlpf_config = 3
167
175
168
-
169
176
# 1.125 kHz/(1+ACCEL_SMPLRT_DIV[11:0]),
170
177
# 1125Hz/(1+20) = 53.57Hz
171
178
self ._accel_rate_divisor = 20
172
179
173
180
# writeByte(ICM20649_ADDR,GYRO_CONFIG_1, gyroConfig);
174
- self ._gyro_range = GyroRange .RANGE_500_DPS # pylint: disable=no-member
181
+ self ._gyro_range = GyroRange .RANGE_500_DPS # pylint: disable=no-member
175
182
sleep (0.100 )
176
183
self ._cached_gyro_range = self ._gyro_range
177
184
@@ -196,7 +203,7 @@ def acceleration(self):
196
203
y = self ._scale_xl_data (raw_accel_data [1 ])
197
204
z = self ._scale_xl_data (raw_accel_data [2 ])
198
205
199
- return (x , y , z )
206
+ return (x , y , z )
200
207
201
208
@property
202
209
def gyro (self ):
@@ -221,7 +228,7 @@ def accelerometer_range(self):
221
228
return self ._cached_accel_range
222
229
223
230
@accelerometer_range .setter
224
- def accelerometer_range (self , value ): # pylint: disable=no-member
231
+ def accelerometer_range (self , value ): # pylint: disable=no-member
225
232
if not AccelRange .is_valid (value ):
226
233
raise AttributeError ("range must be an `AccelRange`" )
227
234
self ._bank = 2
@@ -244,7 +251,7 @@ def gyro_range(self, value):
244
251
self ._gyro_range = value
245
252
self ._cached_gyro_range = value
246
253
self ._bank = 0
247
- sleep (.100 ) # needed to let new range settle
254
+ sleep (0 .100 ) # needed to let new range settle
248
255
249
256
@property
250
257
def accelerometer_data_rate_divisor (self ):
@@ -258,7 +265,7 @@ def accelerometer_data_rate_divisor(self):
258
265
self ._bank = 2
259
266
raw_rate_divisor = self ._accel_rate_divisor
260
267
self ._bank = 0
261
- #rate_hz = 1125/(1+raw_rate_divisor)
268
+ # rate_hz = 1125/(1+raw_rate_divisor)
262
269
return raw_rate_divisor
263
270
264
271
@accelerometer_data_rate_divisor .setter
@@ -291,11 +298,11 @@ def gyro_data_rate_divisor(self, value):
291
298
self ._gyro_rate_divisor = value
292
299
self ._bank = 0
293
300
294
- def _accel_rate_calc (self , divisor ):# pylint:disable=no-self-use
295
- return 1125 / ( 1 + divisor )
301
+ def _accel_rate_calc (self , divisor ): # pylint:disable=no-self-use
302
+ return 1125 / ( 1 + divisor )
296
303
297
- def _gyro_rate_calc (self , divisor ):# pylint:disable=no-self-use
298
- return 1100 / ( 1 + divisor )
304
+ def _gyro_rate_calc (self , divisor ): # pylint:disable=no-self-use
305
+ return 1100 / ( 1 + divisor )
299
306
300
307
@property
301
308
def accelerometer_data_rate (self ):
@@ -312,7 +319,9 @@ def accelerometer_data_rate(self):
312
319
@accelerometer_data_rate .setter
313
320
def accelerometer_data_rate (self , value ):
314
321
if value < self ._accel_rate_calc (4095 ) or value > self ._accel_rate_calc (0 ):
315
- raise AttributeError ("Accelerometer data rate must be between 0.27 and 1125.0" )
322
+ raise AttributeError (
323
+ "Accelerometer data rate must be between 0.27 and 1125.0"
324
+ )
316
325
self .accelerometer_data_rate_divisor = value
317
326
318
327
@property
@@ -332,5 +341,5 @@ def gyro_data_rate(self, value):
332
341
if value < self ._gyro_rate_calc (4095 ) or value > self ._gyro_rate_calc (0 ):
333
342
raise AttributeError ("Gyro data rate must be between 4.30 and 1100.0" )
334
343
335
- divisor = round (((1125.0 - value )/ value ))
344
+ divisor = round (((1125.0 - value ) / value ))
336
345
self .gyro_data_rate_divisor = divisor
0 commit comments