Skip to content

add high pass filter support #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions adafruit_lsm6ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
_LSM6DS_CTRL3_C = const(0x12)
_LSM6DS_CTRL_5_C = const(0x14)
_LSM6DS_MASTER_CONFIG = const(0x14)
_LSM6DS_CTRL8_XL = const(0x17)
_LSM6DS_CTRL9_XL = const(0x18)
_LSM6DS_CTRL10_C = const(0x19)
_LSM6DS_OUT_TEMP_L = const(0x20)
Expand Down Expand Up @@ -157,6 +158,17 @@ class Rate(CV):
('RATE_1_6_HZ', 11, 1.6, None)
))

class AccelHPF(CV):
"""Options for the accelerometer high pass filter"""
pass #pylint: disable=unnecessary-pass

AccelHPF.add_values((
('SLOPE', 0, 0, None),
('HPF_DIV100', 1, 0, None),
('HPF_DIV9', 2, 0, None),
('HPF_DIV400', 3, 0, None),
))


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

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

high_pass_filter_enabled = RWBit(_LSM6DS_CTRL8_XL, 2)
_pass_filter = RWBits(2, _LSM6DS_CTRL8_XL, 5)

CHIP_ID = None

def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
Expand Down Expand Up @@ -360,6 +375,18 @@ def pedometer_enable(self, enable):
self._func_enable = enable
self.pedometer_reset = enable

@property
def high_pass_filter(self):
"""The high pass filter applied to accelerometer data"""
return self._pass_filter

@high_pass_filter.setter
def high_pass_filter(self, value):
if not AccelHPF.is_valid(value):
raise AttributeError("range must be an `AccelHPF`")
self._pass_filter = value


class LSM6DSOX(LSM6DS): #pylint: disable=too-many-instance-attributes

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