@@ -116,9 +116,29 @@ class PerformanceMode(CV):
116
116
('MODE_ULTRA' , 3 , 'Ultra-high Performance' , None )
117
117
))
118
118
class Rate (CV ):
119
- """Options for `data_rate`"""
119
+ """Options for `data_rate`
120
+
121
+ ============================= ============================================
122
+ Rate Meaning
123
+ ============================= ============================================
124
+ ``RATE_0_625_HZ`` 0.625 HZ
125
+ ``RATE_1_25_HZ`` 1.25 HZ
126
+ ``RATE_2_5_HZ`` 2.5 HZ
127
+ ``RATE_5_HZ`` 5 HZ
128
+ ``RATE_10_HZ`` 10 HZ
129
+ ``RATE_20_HZ`` 20 HZ
130
+ ``RATE_40_HZ`` 40 HZ
131
+ ``RATE_80_HZ`` 80 HZ
132
+ ``RATE_155_HZ`` 155 HZ ( Sets ``PerformanceMode`` to ``MODE_ULTRA``)
133
+ ``RATE_300_HZ`` 300 HZ ( Sets ``PerformanceMode`` to ``MODE_HIGH``)
134
+ ``RATE_560_HZ`` 560 HZ ( Sets ``PerformanceMode`` to ``MODE_MEDIUM``)
135
+ ``RATE_1000_HZ`` 1000 HZ ( Sets ``PerformanceMode`` to ``MODE_LOW_POWER``)
136
+ ============================= ============================================
137
+
138
+ """
120
139
pass #pylint: disable=unnecessary-pass
121
140
141
+ # The magnetometer data rate, includes FAST_ODR bit
122
142
Rate .add_values ((
123
143
('RATE_0_625_HZ' , 0b0000 , 0.625 , None ),
124
144
('RATE_1_25_HZ' , 0b0010 , 1.25 , None ),
@@ -133,19 +153,31 @@ class Rate(CV):
133
153
('RATE_560_HZ' , 0b0101 , 560.0 , None ),
134
154
('RATE_1000_HZ' , 0b0111 , 1000.0 , None ),
135
155
))
136
- # /** The magnetometer data rate, includes FAST_ODR bit */
137
156
138
- # = , ///< Hz (FAST_ODR + UHP)
139
- # = , ///< Hz (FAST_ODR + HP)
140
- # = , ///< Hz (FAST_ODR + MP)
141
- # = , ///< Hz (FAST_ODR + LP)
142
- # } lis3mdl_dataRate_t;
157
+ class OperationMode (CV ):
158
+ """Options for `operation_mode`
159
+
160
+ ============================= ============================================
161
+ Operation Mode Meaning
162
+ ============================= ============================================
163
+ ``OperationMode.CONTINUOUS`` Measurements are made continuously at the given `data_rate`
164
+ ``OperationMode.SINGLE`` Setting to ``SINGLE`` takes a single measurement.
165
+ ``OperationMode.POWER_DOWN`` Halts measurements. `magnetic` will return the last measurement
166
+ ============================= ============================================
167
+
168
+ """
169
+ pass #pylint: disable=unnecessary-pass
143
170
171
+ OperationMode .add_values ((
172
+ ('CONTINUOUS' , 0b00 , 'Continuous' , None ),
173
+ ('SINGLE' , 0b01 , 'Single' , None ),
174
+ ('POWER_DOWN' , 0b11 , 'Power Down' , None )
175
+ ))
144
176
# /** The magnetometer operation mode */
145
177
# typedef enum {
146
- # LIS3MDL_CONTINUOUSMODE = 0b00 , ///< Continuous conversion
147
- # LIS3MDL_SINGLEMODE = 0b01 , ///< Single-shot conversion
148
- # LIS3MDL_POWERDOWNMODE = 0b11 , ///< Powered-down mode
178
+ # LIS3MDL_CONTINUOUSMODE = , ///< Continuous conversion
179
+ # LIS3MDL_SINGLEMODE = , ///< Single-shot conversion
180
+ # LIS3MDL_POWERDOWNMODE = , ///< Powered-down mode
149
181
# } lis3mdl_operationmode_t;
150
182
151
183
class LIS3MDL :
@@ -172,12 +204,14 @@ def __init__(self, i2c_bus, address=_LIS3MDL_DEFAULT_ADDRESS):
172
204
self .i2c_device = i2c_device .I2CDevice (i2c_bus , address )
173
205
if self ._chip_id != _LIS3MDL_CHIP_ID :
174
206
raise RuntimeError ("Failed to find LIS3MDL - check your wiring!" )
207
+
175
208
self .reset ()
176
209
self .performance_mode = PerformanceMode .MODE_ULTRA
177
210
178
211
self .data_rate = Rate .RATE_155_HZ
179
212
self .range = Range .RANGE_4_GAUSS
180
- self ._operation_mode = 0 # continuous mode
213
+ self .operation_mode = OperationMode .CONTINUOUS
214
+
181
215
sleep (0.010 )
182
216
183
217
def reset (self ): #pylint: disable=no-self-use
@@ -187,7 +221,9 @@ def reset(self): #pylint: disable=no-self-use
187
221
188
222
@property
189
223
def magnetic (self ):
190
- """How do they even work?!"""
224
+ """The processed magnetometer sensor values.
225
+ A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.
226
+ """
191
227
192
228
raw_mag_data = self ._raw_mag_data
193
229
x = self ._scale_mag_data (raw_mag_data [0 ])
@@ -248,3 +284,16 @@ def performance_mode(self, value):
248
284
raise AttributeError ("`performance_mode` must be a `PerformanceMode`" )
249
285
self ._perf_mode = value
250
286
self ._z_perf_mode = value
287
+
288
+ @property
289
+ def operation_mode (self ):
290
+ """The operating mode for the sensor, controlling how measurements are taken.
291
+ Must be an `OperationMode`. See the the `OperationMode` document for additional details
292
+ """
293
+ return self ._operation_mode
294
+
295
+ @operation_mode .setter
296
+ def operation_mode (self , value ):
297
+ if not OperationMode .is_valid (value ):
298
+ raise AttributeError ("operation mode must be a OperationMode" )
299
+ self ._operation_mode = value
0 commit comments