# `LIS3DH.Click`

Encoding and decoding for the LIS3DH's click / double-click / tap
detection engine.

Six per-axis enable bits in `CLICK_CFG` select which axes and click types
(single vs double) are armed. Timing is configured by three registers:

  * `TIME_LIMIT` — maximum pulse width for a click (must rise above the
    threshold and fall back within this window).
  * `TIME_LATENCY` — dead time after a click during which another pulse
    is ignored.
  * `TIME_WINDOW` — the additional window after the latency in which a
    second click is allowed (for double-click detection).

All three timing values are in `1/ODR` units.

References: *LIS3DH Datasheet DocID17530 Rev 2* §8.29 – §8.34.

# `click_event`

```elixir
@type click_event() ::
  :single_click_x
  | :double_click_x
  | :single_click_y
  | :double_click_y
  | :single_click_z
  | :double_click_z
```

Per-axis / click-type enables for `CLICK_CFG`.

# `source_flags`

```elixir
@type source_flags() :: %{
  active: boolean(),
  double_click: boolean(),
  single_click: boolean(),
  sign: :positive | :negative,
  x: boolean(),
  y: boolean(),
  z: boolean()
}
```

Decoded `CLICK_SRC` flags.

# `decode_click_cfg`

```elixir
@spec decode_click_cfg(&lt;&lt;_::8&gt;&gt;) :: [click_event()]
```

Decode a `CLICK_CFG` byte into a list of enabled `t:click_event/0`.

# `decode_click_src`

```elixir
@spec decode_click_src(&lt;&lt;_::8&gt;&gt;) :: source_flags()
```

Decode a `CLICK_SRC` byte into a map of its fields.

# `encode_click_cfg`

```elixir
@spec encode_click_cfg([click_event()]) :: &lt;&lt;_::8&gt;&gt;
```

Encode a `CLICK_CFG` byte from a list of `t:click_event/0` to enable.

# `encode_click_ths!`

```elixir
@spec encode_click_ths!(non_neg_integer(), LIS3DH.Config.range(), boolean()) ::
  &lt;&lt;_::8&gt;&gt;
```

Encode a `CLICK_THS` byte from a threshold in milli-g (using the same LSB
table as the inertial interrupt thresholds) and a latch-request flag.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
