Skip to content

Commit effd1ba

Browse files
authored
Merge pull request #8 from ladyada/master
add high pass filter support
2 parents edac0b2 + 6b051ef commit effd1ba

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

adafruit_lsm6ds.py

+27
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
_LSM6DS_CTRL3_C = const(0x12)
7474
_LSM6DS_CTRL_5_C = const(0x14)
7575
_LSM6DS_MASTER_CONFIG = const(0x14)
76+
_LSM6DS_CTRL8_XL = const(0x17)
7677
_LSM6DS_CTRL9_XL = const(0x18)
7778
_LSM6DS_CTRL10_C = const(0x19)
7879
_LSM6DS_OUT_TEMP_L = const(0x20)
@@ -157,6 +158,17 @@ class Rate(CV):
157158
('RATE_1_6_HZ', 11, 1.6, None)
158159
))
159160

161+
class AccelHPF(CV):
162+
"""Options for the accelerometer high pass filter"""
163+
pass #pylint: disable=unnecessary-pass
164+
165+
AccelHPF.add_values((
166+
('SLOPE', 0, 0, None),
167+
('HPF_DIV100', 1, 0, None),
168+
('HPF_DIV9', 2, 0, None),
169+
('HPF_DIV400', 3, 0, None),
170+
))
171+
160172

161173
class LSM6DS: #pylint: disable=too-many-instance-attributes
162174

@@ -220,6 +232,9 @@ class LSM6DS: #pylint: disable=too-many-instance-attributes
220232
_ped_enable = RWBit(_LSM6DS_TAP_CFG, 6)
221233
_func_enable = RWBit(_LSM6DS_CTRL10_C, 2)
222234

235+
high_pass_filter_enabled = RWBit(_LSM6DS_CTRL8_XL, 2)
236+
_pass_filter = RWBits(2, _LSM6DS_CTRL8_XL, 5)
237+
223238
CHIP_ID = None
224239

225240
def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
@@ -360,6 +375,18 @@ def pedometer_enable(self, enable):
360375
self._func_enable = enable
361376
self.pedometer_reset = enable
362377

378+
@property
379+
def high_pass_filter(self):
380+
"""The high pass filter applied to accelerometer data"""
381+
return self._pass_filter
382+
383+
@high_pass_filter.setter
384+
def high_pass_filter(self, value):
385+
if not AccelHPF.is_valid(value):
386+
raise AttributeError("range must be an `AccelHPF`")
387+
self._pass_filter = value
388+
389+
363390
class LSM6DSOX(LSM6DS): #pylint: disable=too-many-instance-attributes
364391

365392
"""Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.

0 commit comments

Comments
 (0)