Skip to content

Commit f9f906b

Browse files
authored
Add ability to set custom click register configuration.
Add optional click_cfg parameter to set_click which allows overriding click generation config with an explicit 8-bit CLICK_CFG register value. This allows more advanced click detection like from a single or specific axis. See datasheet for CLICK_CFG bit values.
1 parent 26b1821 commit f9f906b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

adafruit_lis3dh/lis3dh.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def read_click(self):
150150
raw = self.read_click_raw()
151151
return (raw & 0x10 > 0, raw & 0x20 > 0)
152152

153-
def set_click(self, click, threshold, time_limit=10, time_latency=20, time_window=255):
153+
def set_click(self, click, threshold, time_limit=10, time_latency=20, time_window=255, click_cfg=None):
154154
"""Set the click detection parameters. Must specify at least:
155155
click - Set to 0 to disable click detection, 1 to detect only single
156156
clicks, and 2 to detect single & double clicks.
@@ -163,9 +163,9 @@ def set_click(self, click, threshold, time_limit=10, time_latency=20, time_windo
163163
time_latency - Time latency register value (default 20).
164164
time_window - Time window register value (default 255).
165165
"""
166-
if click < 0 or click > 2:
166+
if (click < 0 or click > 2) and click_cfg is None:
167167
raise ValueError('Click must be 0 (disabled), 1 (single click), or 2 (double click)!')
168-
if click == 0:
168+
if click == 0 and click_cfg is None:
169169
# Disable click interrupt.
170170
r = self._read_register_byte(REG_CTRL3)
171171
r &= ~(0x80) # Turn off I1_CLICK.
@@ -175,7 +175,10 @@ def set_click(self, click, threshold, time_limit=10, time_latency=20, time_windo
175175
# Else enable click with specified parameters.
176176
self._write_register_byte(REG_CTRL3, 0x80) # Turn on int1 click.
177177
self._write_register_byte(REG_CTRL5, 0x08) # Latch interrupt on int1.
178-
if click == 1:
178+
if click_cfg is not None:
179+
# Custom click configuration register value specified, use it.
180+
self._write_register_byte(REG_CLICKCFG, click_cfg)
181+
elif click == 1:
179182
self._write_register_byte(REG_CLICKCFG, 0x15) # Turn on all axes & singletap.
180183
elif click == 2:
181184
self._write_register_byte(REG_CLICKCFG, 0x2A) # Turn on all axes & doubletap.

0 commit comments

Comments
 (0)