51
51
from struct import unpack_from
52
52
from time import sleep
53
53
from adafruit_register .i2c_bits import RWBits
54
+ from adafruit_register .i2c_bit import RWBit
54
55
from adafruit_register .i2c_struct import UnaryStruct , ROUnaryStruct
55
56
import adafruit_bus_device .i2c_device as i2c_device
56
57
@@ -214,6 +215,7 @@ class RateDivisor(CV):
214
215
215
216
216
217
class LIS331 :
218
+ # pylint:disable=too-many-instance-attributes
217
219
"""Base class for the LIS331 family of 3-axis accelerometers.
218
220
**Cannot be instantiated directly**
219
221
@@ -229,6 +231,12 @@ class LIS331:
229
231
_range_bits = RWBits (2 , _LIS331_REG_CTRL4 , 4 )
230
232
_raw_acceleration = ROByteArray ((_LIS331_REG_OUT_X_L | 0x80 ), "<hhh" , 6 )
231
233
_reference_value = UnaryStruct (_LIS331_REG_REFERENCE , "<b" )
234
+ _zero_hpf_reference = ROUnaryStruct (_LIS331_REG_HP_FILTER_RESET , "<b" )
235
+
236
+ _hpf_mode_bits = RWBit (_LIS331_REG_CTRL2 , 5 )
237
+ _hpf_enable_bit = RWBit (_LIS331_REG_CTRL2 , 4 )
238
+ _hpf_cutoff = RWBits (2 , _LIS331_REG_CTRL2 , 0 )
239
+
232
240
CHIP_ID = None
233
241
# Adafruit_BusIO_Register reference_reg = Adafruit_BusIO_Register(
234
242
# i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LIS331_REG_REFERENCE);
@@ -244,6 +252,7 @@ def __init__(self, i2c_bus, address=_LIS331_DEFAULT_ADDRESS):
244
252
"Failed to find %s - check your wiring!" % self .__class__ .__name__
245
253
)
246
254
self ._range_class = None
255
+ self .enable_hpf (False )
247
256
248
257
@property
249
258
def lpf_cutoff (self ):
@@ -293,12 +302,32 @@ def hpf_reference(self, reference_value):
293
302
raise AttributeError ("`hpf_reference` must be from -128 to 127" )
294
303
self ._reference_value = reference_value
295
304
296
- # void enableHighPassFilter(bool filter_enabled,
297
- # lis331_hpf_cutoff_t cutoff = LIS331_HPF_0_0025_ODR,
298
- # bool use_reference = false);
299
- # void setHPFReference(int8_t reference);
300
- # int8_t getHPFReference(void);
301
- # void HPFReset(void);
305
+ def zero_hpf (self ):
306
+ """When the high-pass filter is enabled with ``use_reference=False``, calling ``zero_hpf``
307
+ will set all measurements to zero immediately, avoiding the normal settling time seen when
308
+ using the high-pass filter without a ``hpf_reference``
309
+ """
310
+
311
+ def enable_hpf (
312
+ self , enabled = True , cutoff = RateDivisor .ODR_DIV_50 , use_reference = False
313
+ ): # pylint: disable=no-member
314
+ """Enable or disable the high-pass filter.
315
+
316
+ :param enabled: Enable or disable the filter. Default is `True` to enable
317
+ :param ~RateDivisor cutoff: A `RateDivisor` to set the high-pass cutoff frequency. Default\
318
+ is ``RateDivisor.ODR_DIV_50``. See ``RateDivisor`` for more information
319
+ :param use_reference: Determines if the filtered measurements are offset by a reference\
320
+ value. Default is false.
321
+
322
+ See section **4** of the LIS331DLH application note for more information `LIS331DLH application\
323
+ note for more information <https://www.st.com/content/ccc/resource/technical/document/\
324
+ application_note/b5/8e/58/69/cb/87/45/55/CD00215823.pdf/files/CD00215823.pdf/jcr:content/\
325
+ translations/en.CD00215823.pdf>`_
326
+
327
+ """
328
+ self ._hpf_mode_bits = use_reference
329
+ self ._hpf_cutoff = cutoff
330
+ self ._hpf_enable_bit = enabled
302
331
303
332
@property
304
333
def data_rate (self ):
0 commit comments