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,9 @@ class CV:
59
65
"""struct helper"""
60
66
61
67
@classmethod
62
- def add_values (cls , value_tuples ):
68
+ def add_values (
69
+ cls , value_tuples : Iterable [Tuple [str , int , Union [int , str ], Optional [int ]]]
70
+ ):
63
71
"creates CV entires"
64
72
cls .string = {}
65
73
cls .lsb = {}
@@ -71,16 +79,14 @@ def add_values(cls, value_tuples):
71
79
cls .lsb [value ] = lsb
72
80
73
81
@classmethod
74
- def is_valid (cls , value ) :
82
+ def is_valid (cls , value : int ) -> bool :
75
83
"Returns true if the given value is a member of the CV"
76
84
return value in cls .string
77
85
78
86
79
87
class Range (CV ):
80
88
"""Options for ``accelerometer_range``"""
81
89
82
- pass # pylint: disable=unnecessary-pass
83
-
84
90
85
91
Range .add_values (
86
92
(
@@ -95,8 +101,6 @@ class Range(CV):
95
101
class PerformanceMode (CV ):
96
102
"""Options for `performance_mode`"""
97
103
98
- pass # pylint: disable=unnecessary-pass
99
-
100
104
101
105
PerformanceMode .add_values (
102
106
(
@@ -130,8 +134,6 @@ class Rate(CV):
130
134
131
135
"""
132
136
133
- pass # pylint: disable=unnecessary-pass
134
-
135
137
136
138
# The magnetometer data rate, includes FAST_ODR bit
137
139
Rate .add_values (
@@ -164,8 +166,6 @@ class OperationMode(CV):
164
166
============================= ============================================
165
167
"""
166
168
167
- pass # pylint: disable=unnecessary-pass
168
-
169
169
170
170
OperationMode .add_values (
171
171
(
@@ -186,7 +186,7 @@ class LIS3MDL:
186
186
"""Driver for the LIS3MDL 3-axis magnetometer.
187
187
188
188
:param ~busio.I2C i2c_bus: The I2C bus the LIS3MDL is connected to.
189
- :param address: The I2C device address. Defaults to :const:`0x1C`
189
+ :param int address: The I2C device address. Defaults to :const:`0x1C`
190
190
191
191
**Quickstart: Importing and using the device**
192
192
@@ -228,7 +228,7 @@ class LIS3MDL:
228
228
_range = RWBits (2 , _LIS3MDL_CTRL_REG2 , 5 )
229
229
_reset = RWBit (_LIS3MDL_CTRL_REG2 , 2 )
230
230
231
- def __init__ (self , i2c_bus , address = _LIS3MDL_DEFAULT_ADDRESS ):
231
+ def __init__ (self , i2c_bus : I2C , address : int = _LIS3MDL_DEFAULT_ADDRESS ) -> None :
232
232
# pylint: disable=no-member
233
233
self .i2c_device = i2c_device .I2CDevice (i2c_bus , address )
234
234
if self ._chip_id != _LIS3MDL_CHIP_ID :
@@ -243,13 +243,13 @@ def __init__(self, i2c_bus, address=_LIS3MDL_DEFAULT_ADDRESS):
243
243
244
244
sleep (0.010 )
245
245
246
- def reset (self ): # pylint: disable=no-self-use
246
+ def reset (self ) -> None :
247
247
"""Reset the sensor to the default state set by the library"""
248
248
self ._reset = True
249
249
sleep (0.010 )
250
250
251
251
@property
252
- def magnetic (self ):
252
+ def magnetic (self ) -> Tuple [ float , float , float ] :
253
253
"""The processed magnetometer sensor values.
254
254
A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.
255
255
"""
@@ -261,16 +261,16 @@ def magnetic(self):
261
261
262
262
return (x , y , z )
263
263
264
- def _scale_mag_data (self , raw_measurement ): # pylint: disable=no-self-use
264
+ def _scale_mag_data (self , raw_measurement : int ) -> float :
265
265
return (raw_measurement / Range .lsb [self .range ]) * _GAUSS_TO_UT
266
266
267
267
@property
268
- def range (self ):
268
+ def range (self ) -> int :
269
269
"""The measurement range for the magnetic sensor. Must be a ``Range``"""
270
270
return self ._range
271
271
272
272
@range .setter
273
- def range (self , value ) :
273
+ def range (self , value : int ) -> None :
274
274
if not Range .is_valid (value ):
275
275
raise AttributeError ("``range`` must be a ``Range``" )
276
276
@@ -279,12 +279,12 @@ def range(self, value):
279
279
sleep (0.010 )
280
280
281
281
@property
282
- def data_rate (self ):
282
+ def data_rate (self ) -> int :
283
283
"""The rate at which the sensor takes measurements. Must be a ``Rate``"""
284
284
return self ._data_rate
285
285
286
286
@data_rate .setter
287
- def data_rate (self , value ) :
287
+ def data_rate (self , value : int ) -> None :
288
288
# pylint: disable=no-member
289
289
if value is Rate .RATE_155_HZ :
290
290
self .performance_mode = PerformanceMode .MODE_ULTRA
@@ -300,29 +300,29 @@ def data_rate(self, value):
300
300
self ._data_rate = value
301
301
302
302
@property
303
- def performance_mode (self ):
303
+ def performance_mode (self ) -> int :
304
304
"""Sets the 'performance mode' of the sensor. Must be a ``PerformanceMode``.
305
305
Note that `performance_mode` affects the available data rate and will be
306
306
automatically changed by setting ``data_rate`` to certain values."""
307
307
308
308
return self ._perf_mode
309
309
310
310
@performance_mode .setter
311
- def performance_mode (self , value ) :
311
+ def performance_mode (self , value : int ) -> None :
312
312
if not PerformanceMode .is_valid (value ):
313
313
raise AttributeError ("`performance_mode` must be a `PerformanceMode`" )
314
314
self ._perf_mode = value
315
315
self ._z_perf_mode = value
316
316
317
317
@property
318
- def operation_mode (self ):
318
+ def operation_mode (self ) -> int :
319
319
"""The operating mode for the sensor, controlling how measurements are taken.
320
320
Must be an `OperationMode`. See the the `OperationMode` document for additional details
321
321
"""
322
322
return self ._operation_mode
323
323
324
324
@operation_mode .setter
325
- def operation_mode (self , value ) :
325
+ def operation_mode (self , value : int ) -> None :
326
326
if not OperationMode .is_valid (value ):
327
327
raise AttributeError ("operation mode must be a OperationMode" )
328
328
self ._operation_mode = value
0 commit comments