Joystick (joystick v0.2.2) View Source

Simple wrapper to get Linux Joystick events.

Usage

iex()> {:ok, js} = Joystick.start_link(0, self())
iex()> flush()
{:joystick, %Joystick.Event{number: 1, timestamp: 1441087318, type: :axis, value: -60}}
{:joystick, %Joystick.Event{number: 4, timestamp: 1441087318, type: :axis, value: -5}}
iex()> Joystick.info(js)
%{axes: 8, buttons: 11, name: 'Microsoft X-Box One pad', version: 131328}

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Get information about a joystick

Start listening to joystick events.

Stop a running joystick instance.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Get information about a joystick

Link to this function

start_link(device, listener, callback \\ nil)

View Source

Start listening to joystick events.

  • device - a number pointing to the js file.
    • for example 0 would evaluate to "/dev/input/js0"
  • listener - pid to receive events
  • callback - a message will be sent to listener with the form {callback, joystick}, where joystick is be the pid of the Joystick GenServer. Default value of callback is nil, which means the Joystick pid will be returned immediately, but the GenServer will crash if a joystick connection cannot be opened.
Link to this function

stop(joystick, reason \\ :normal)

View Source

Stop a running joystick instance.