33
33
from adafruit_register .i2c_bits import RWBits
34
34
from adafruit_register .i2c_bit import RWBit
35
35
36
+ try :
37
+ from typing import Iterable , Tuple , Union , Optional
38
+ from busio import I2C
39
+ except ImportError :
40
+ pass
41
+
36
42
__version__ = "0.0.0-auto.0"
37
43
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LIS3MDL.git"
38
44
@@ -59,7 +65,7 @@ class CV:
59
65
"""struct helper"""
60
66
61
67
@classmethod
62
- def add_values (cls , value_tuples ):
68
+ def add_values (cls , value_tuples : Iterable [ Tuple [ str , int , Union [ int , str ], Optional [ int ]]] ):
63
69
"creates CV entires"
64
70
cls .string = {}
65
71
cls .lsb = {}
@@ -71,7 +77,7 @@ def add_values(cls, value_tuples):
71
77
cls .lsb [value ] = lsb
72
78
73
79
@classmethod
74
- def is_valid (cls , value ) :
80
+ def is_valid (cls , value : int ) -> bool :
75
81
"Returns true if the given value is a member of the CV"
76
82
return value in cls .string
77
83
@@ -178,7 +184,7 @@ class LIS3MDL:
178
184
"""Driver for the LIS3MDL 3-axis magnetometer.
179
185
180
186
:param ~busio.I2C i2c_bus: The I2C bus the LIS3MDL is connected to.
181
- :param address: The I2C device address. Defaults to :const:`0x1C`
187
+ :param int address: The I2C device address. Defaults to :const:`0x1C`
182
188
183
189
**Quickstart: Importing and using the device**
184
190
@@ -220,7 +226,7 @@ class LIS3MDL:
220
226
_range = RWBits (2 , _LIS3MDL_CTRL_REG2 , 5 )
221
227
_reset = RWBit (_LIS3MDL_CTRL_REG2 , 2 )
222
228
223
- def __init__ (self , i2c_bus , address = _LIS3MDL_DEFAULT_ADDRESS ):
229
+ def __init__ (self , i2c_bus : I2C , address : int = _LIS3MDL_DEFAULT_ADDRESS ) -> None :
224
230
# pylint: disable=no-member
225
231
self .i2c_device = i2c_device .I2CDevice (i2c_bus , address )
226
232
if self ._chip_id != _LIS3MDL_CHIP_ID :
@@ -235,13 +241,13 @@ def __init__(self, i2c_bus, address=_LIS3MDL_DEFAULT_ADDRESS):
235
241
236
242
sleep (0.010 )
237
243
238
- def reset (self ): # pylint: disable=no-self-use
244
+ def reset (self ) -> None :
239
245
"""Reset the sensor to the default state set by the library"""
240
246
self ._reset = True
241
247
sleep (0.010 )
242
248
243
249
@property
244
- def magnetic (self ):
250
+ def magnetic (self ) -> Tuple [ float , float , float ] :
245
251
"""The processed magnetometer sensor values.
246
252
A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.
247
253
"""
@@ -253,16 +259,16 @@ def magnetic(self):
253
259
254
260
return (x , y , z )
255
261
256
- def _scale_mag_data (self , raw_measurement ): # pylint: disable=no-self-use
262
+ def _scale_mag_data (self , raw_measurement : int ) -> float :
257
263
return (raw_measurement / Range .lsb [self .range ]) * _GAUSS_TO_UT
258
264
259
265
@property
260
- def range (self ):
266
+ def range (self ) -> int :
261
267
"""The measurement range for the magnetic sensor. Must be a ``Range``"""
262
268
return self ._range
263
269
264
270
@range .setter
265
- def range (self , value ) :
271
+ def range (self , value : int ) -> None :
266
272
if not Range .is_valid (value ):
267
273
raise AttributeError ("``range`` must be a ``Range``" )
268
274
@@ -271,12 +277,12 @@ def range(self, value):
271
277
sleep (0.010 )
272
278
273
279
@property
274
- def data_rate (self ):
280
+ def data_rate (self ) -> int :
275
281
"""The rate at which the sensor takes measurements. Must be a ``Rate``"""
276
282
return self ._data_rate
277
283
278
284
@data_rate .setter
279
- def data_rate (self , value ) :
285
+ def data_rate (self , value : int ) -> None :
280
286
# pylint: disable=no-member
281
287
if value is Rate .RATE_155_HZ :
282
288
self .performance_mode = PerformanceMode .MODE_ULTRA
@@ -292,29 +298,29 @@ def data_rate(self, value):
292
298
self ._data_rate = value
293
299
294
300
@property
295
- def performance_mode (self ):
301
+ def performance_mode (self ) -> int :
296
302
"""Sets the 'performance mode' of the sensor. Must be a ``PerformanceMode``.
297
303
Note that `performance_mode` affects the available data rate and will be
298
304
automatically changed by setting ``data_rate`` to certain values."""
299
305
300
306
return self ._perf_mode
301
307
302
308
@performance_mode .setter
303
- def performance_mode (self , value ) :
309
+ def performance_mode (self , value : int ) -> None :
304
310
if not PerformanceMode .is_valid (value ):
305
311
raise AttributeError ("`performance_mode` must be a `PerformanceMode`" )
306
312
self ._perf_mode = value
307
313
self ._z_perf_mode = value
308
314
309
315
@property
310
- def operation_mode (self ):
316
+ def operation_mode (self ) -> int :
311
317
"""The operating mode for the sensor, controlling how measurements are taken.
312
318
Must be an `OperationMode`. See the the `OperationMode` document for additional details
313
319
"""
314
320
return self ._operation_mode
315
321
316
322
@operation_mode .setter
317
- def operation_mode (self , value ) :
323
+ def operation_mode (self , value : int ) -> None :
318
324
if not OperationMode .is_valid (value ):
319
325
raise AttributeError ("operation mode must be a OperationMode" )
320
326
self ._operation_mode = value
0 commit comments