# `Gamepad.Linux`
[🔗](https://github.com/jaman/gamepad/blob/v0.1.0/lib/gamepad/linux.ex#L1)

Decodes the Linux joystick interface, `/dev/input/js*`, into controller events.

Each device file yields 8-byte `js_event` records — time, value, type, number — which
`decode/2` turns into `Gamepad.Wire` event maps. Buttons and axes are named by
the layout the kernel's `xpad` driver reports for Xbox-style controllers, which most
gamepads follow: buttons 0–10 are A, B, X, Y, the bumpers, Back, Start, Guide and the
stick clicks; axes 0–5 are the sticks and triggers, and axes 6 and 7 are the d-pad,
which comes out as d-pad button presses.

`devices/1` lists the device files present; `Gamepad` reads each one and
watches for new ones.

# `decode`

```elixir
@spec decode(binary(), non_neg_integer()) :: {[Gamepad.Wire.event()], binary()}
```

The events in `binary` for controller `device`, and the bytes left over from an
incomplete record.

    iex> Gamepad.Linux.decode(<<0, 0, 0, 0, 1, 0, 1, 0>>, 0)
    {[%{type: :button, device: 0, button: :a, pressed: true}], ""}

    iex> Gamepad.Linux.decode(<<0, 0, 0, 0, 255, 127, 2, 1>>, 0)
    {[%{type: :axis, device: 0, axis: :left_y, value: 1.0}], ""}

    iex> Gamepad.Linux.decode(<<0, 0, 0, 0, 1, 128, 2, 6>>, 3)
    {[%{type: :button, device: 3, button: :dpad_left, pressed: true}, %{type: :button, device: 3, button: :dpad_right, pressed: false}], ""}

    iex> Gamepad.Linux.decode(<<0, 0, 0, 0, 0, 0, 1>>, 0)
    {[], <<0, 0, 0, 0, 0, 0, 1>>}

# `devices`

```elixir
@spec devices(String.t()) :: [Path.t()]
```

The device files matching `glob` (default the joystick devices, `/dev/input/js*`), sorted.

---

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