7878
7979
8080_STANDARD_GRAVITY = 9.806
81- class Mode : # pylint: disable=too-few-public-methods
81+
82+
83+ class Mode : # pylint: disable=too-few-public-methods
8284 """An enum-like class representing the different modes that the MSA301 can
8385 use. The values can be referenced like ``Mode.NORMAL`` or ``Mode.SUSPEND``
8486 Possible values are
@@ -87,12 +89,14 @@ class Mode: # pylint: disable=too-few-public-methods
8789 - ``Mode.LOW_POWER``
8890 - ``Mode.SUSPEND``
8991 """
92+
9093 # pylint: disable=invalid-name
9194 NORMAL = 0b00
9295 LOWPOWER = 0b01
9396 SUSPEND = 0b010
9497
95- class DataRate : # pylint: disable=too-few-public-methods
98+
99+ class DataRate : # pylint: disable=too-few-public-methods
96100 """An enum-like class representing the different data rates that the MSA301 can
97101 use. The values can be referenced like ``DataRate.RATE_1_HZ`` or ``DataRate.RATE_1000_HZ``
98102 Possible values are
@@ -109,19 +113,21 @@ class DataRate: # pylint: disable=too-few-public-methods
109113 - ``DataRate.RATE_500_HZ``
110114 - ``DataRate.RATE_1000_HZ``
111115 """
112- RATE_1_HZ = 0b0000 # 1 Hz
116+
117+ RATE_1_HZ = 0b0000 # 1 Hz
113118 RATE_1_95_HZ = 0b0001 # 1.95 Hz
114- RATE_3_9_HZ = 0b0010 # 3.9 Hz
119+ RATE_3_9_HZ = 0b0010 # 3.9 Hz
115120 RATE_7_81_HZ = 0b0011 # 7.81 Hz
116- RATE_15_63_HZ = 0b0100 # 15.63 Hz
117- RATE_31_25_HZ = 0b0101 # 31.25 Hz
121+ RATE_15_63_HZ = 0b0100 # 15.63 Hz
122+ RATE_31_25_HZ = 0b0101 # 31.25 Hz
118123 RATE_62_5_HZ = 0b0110 # 62.5 Hz
119- RATE_125_HZ = 0b0111 # 125 Hz
120- RATE_250_HZ = 0b1000 # 250 Hz
121- RATE_500_HZ = 0b1001 # 500 Hz
124+ RATE_125_HZ = 0b0111 # 125 Hz
125+ RATE_250_HZ = 0b1000 # 250 Hz
126+ RATE_500_HZ = 0b1001 # 500 Hz
122127 RATE_1000_HZ = 0b1010 # 1000 Hz
123128
124- class BandWidth : # pylint: disable=too-few-public-methods
129+
130+ class BandWidth : # pylint: disable=too-few-public-methods
125131 """An enum-like class representing the different bandwidths that the MSA301 can
126132 use. The values can be referenced like ``BandWidth.WIDTH_1_HZ`` or ``BandWidth.RATE_500_HZ``
127133 Possible values are
@@ -138,17 +144,19 @@ class BandWidth: # pylint: disable=too-few-public-methods
138144 - ``BandWidth.RATE_500_HZ``
139145 - ``BandWidth.RATE_1000_HZ``
140146 """
147+
141148 WIDTH_1_95_HZ = 0b0000 # 1.95 Hz
142- WIDTH_3_9_HZ = 0b0011 # 3.9 Hz
149+ WIDTH_3_9_HZ = 0b0011 # 3.9 Hz
143150 WIDTH_7_81_HZ = 0b0100 # 7.81 Hz
144- WIDTH_15_63_HZ = 0b0101 # 15.63 Hz
145- WIDTH_31_25_HZ = 0b0110 # 31.25 Hz
151+ WIDTH_15_63_HZ = 0b0101 # 15.63 Hz
152+ WIDTH_31_25_HZ = 0b0110 # 31.25 Hz
146153 WIDTH_62_5_HZ = 0b0111 # 62.5 Hz
147- WIDTH_125_HZ = 0b1000 # 125 Hz
148- WIDTH_250_HZ = 0b1001 # 250 Hz
149- WIDTH_500_HZ = 0b1010 # 500 Hz
154+ WIDTH_125_HZ = 0b1000 # 125 Hz
155+ WIDTH_250_HZ = 0b1001 # 250 Hz
156+ WIDTH_500_HZ = 0b1010 # 500 Hz
157+
150158
151- class Range : # pylint: disable=too-few-public-methods
159+ class Range : # pylint: disable=too-few-public-methods
152160 """An enum-like class representing the different acceleration measurement ranges that the
153161 MSA301 can use. The values can be referenced like ``Range.RANGE_2_G`` or ``Range.RANGE_16_G``
154162 Possible values are
@@ -158,12 +166,14 @@ class Range: # pylint: disable=too-few-public-methods
158166 - ``Range.RANGE_8_G``
159167 - ``Range.RANGE_16_G``
160168 """
169+
161170 RANGE_2_G = 0b00 # +/- 2g (default value)
162171 RANGE_4_G = 0b01 # +/- 4g
163172 RANGE_8_G = 0b10 # +/- 8g
164- RANGE_16_G = 0b11 # +/- 16g
173+ RANGE_16_G = 0b11 # +/- 16g
174+
165175
166- class Resolution : # pylint: disable=too-few-public-methods
176+ class Resolution : # pylint: disable=too-few-public-methods
167177 """An enum-like class representing the different measurement ranges that the MSA301 can
168178 use. The values can be referenced like ``Range.RANGE_2_G`` or ``Range.RANGE_16_G``
169179 Possible values are
@@ -173,29 +183,33 @@ class Resolution: # pylint: disable=too-few-public-methods
173183 - ``Resolution.RESOLUTION_10_BIT``
174184 - ``Resolution.RESOLUTION_8_BIT``
175185 """
186+
176187 RESOLUTION_14_BIT = 0b00
177188 RESOLUTION_12_BIT = 0b01
178189 RESOLUTION_10_BIT = 0b10
179190 RESOLUTION_8_BIT = 0b11
180191
181- class TapDuration : #pylint: disable=too-few-public-methods,too-many-instance-attributes
192+
193+ class TapDuration : # pylint: disable=too-few-public-methods,too-many-instance-attributes
182194 """An enum-like class representing the options for the "double_tap_window" parameter of
183195 `enable_tap_detection`"""
184- DURATION_50_MS = 0b000 #< 50 millis
185- DURATION_100_MS = 0b001 #< 100 millis
186- DURATION_150_MS = 0b010 #< 150 millis
187- DURATION_200_MS = 0b011 #< 200 millis
188- DURATION_250_MS = 0b100 #< 250 millis
189- DURATION_375_MS = 0b101 #< 375 millis
190- DURATION_500_MS = 0b110 #< 500 millis
191- DURATION_700_MS = 0b111 #< 50 millis700 millis
192196
197+ DURATION_50_MS = 0b000 # < 50 millis
198+ DURATION_100_MS = 0b001 # < 100 millis
199+ DURATION_150_MS = 0b010 # < 150 millis
200+ DURATION_200_MS = 0b011 # < 200 millis
201+ DURATION_250_MS = 0b100 # < 250 millis
202+ DURATION_375_MS = 0b101 # < 375 millis
203+ DURATION_500_MS = 0b110 # < 500 millis
204+ DURATION_700_MS = 0b111 # < 50 millis700 millis
193205
194- class MSA301 :#pylint: disable=too-many-instance-attributes
206+
207+ class MSA301 : # pylint: disable=too-many-instance-attributes
195208 """Driver for the MSA301 Accelerometer.
196209
197210 :param ~busio.I2C i2c_bus: The I2C bus the MSA is connected to.
198211 """
212+
199213 _part_id = ROUnaryStruct (_MSA301_REG_PARTID , "<B" )
200214
201215 def __init__ (self , i2c_bus ):
@@ -204,7 +218,6 @@ def __init__(self, i2c_bus):
204218 if self ._part_id != 0x13 :
205219 raise AttributeError ("Cannot find a MSA301" )
206220
207-
208221 self ._disable_x = self ._disable_y = self ._disable_z = False
209222 self .power_mode = Mode .NORMAL
210223 self .data_rate = DataRate .RATE_500_HZ
@@ -247,7 +260,7 @@ def acceleration(self):
247260 acc_bytes = bytearray ()
248261 # shift out bytes, reversing the order
249262 for shift in range (6 ):
250- bottom_byte = ( raw_data >> ( 8 * shift ) & 0xFF )
263+ bottom_byte = raw_data >> ( 8 * shift ) & 0xFF
251264 acc_bytes .append (bottom_byte )
252265
253266 # unpack three LE, signed shorts
@@ -265,18 +278,21 @@ def acceleration(self):
265278 scale = 4096.0
266279
267280 # shift down to the actual 14 bits and scale based on the range
268- x_acc = ((x >> 2 ) / scale ) * _STANDARD_GRAVITY
269- y_acc = ((y >> 2 ) / scale ) * _STANDARD_GRAVITY
270- z_acc = ((z >> 2 ) / scale ) * _STANDARD_GRAVITY
281+ x_acc = ((x >> 2 ) / scale ) * _STANDARD_GRAVITY
282+ y_acc = ((y >> 2 ) / scale ) * _STANDARD_GRAVITY
283+ z_acc = ((z >> 2 ) / scale ) * _STANDARD_GRAVITY
271284
272285 return (x_acc , y_acc , z_acc )
273286
274- def enable_tap_detection (self , * ,
275- tap_count = 1 ,
276- threshold = 25 ,
277- long_initial_window = True ,
278- long_quiet_window = True ,
279- double_tap_window = TapDuration .DURATION_250_MS ):
287+ def enable_tap_detection ( # pylint: disable=bad-continuation
288+ self ,
289+ * ,
290+ tap_count = 1 ,
291+ threshold = 25 ,
292+ long_initial_window = True ,
293+ long_quiet_window = True ,
294+ double_tap_window = TapDuration .DURATION_250_MS
295+ ):
280296 """
281297 Enables tap detection with configurable parameters.
282298
@@ -332,12 +348,12 @@ def tapped(self):
332348
333349 motion_int_status = self ._motion_int_status
334350
335- if motion_int_status == 0 : # no interrupts triggered
351+ if motion_int_status == 0 : # no interrupts triggered
336352 return False
337353
338- if self ._tap_count == 1 and motion_int_status & 1 << 5 :
354+ if self ._tap_count == 1 and motion_int_status & 1 << 5 :
339355 return True
340- if self ._tap_count == 2 and motion_int_status & 1 << 4 :
356+ if self ._tap_count == 2 and motion_int_status & 1 << 4 :
341357 return True
342358
343359 return False
0 commit comments