noordstar/elm-gamepad/1.0.0

NOTE: the latest version is 1.0.2

Gamepad.Joystick

This module is about showing joysticks.

type alias Joystick =
Joystick

A joystick is a representation of a stick that can move in all directions.

left : Gamepad -> Joystick

Get the joystick that usually resides on the left of the controller. This is considered the primary joystick on the controller.

The joystick's value can be read in multiple ways that might suit your needs.

abs : Joystick -> Float

On a scale from 0 to 1, return how intensely the button is being pushed.

Keep in mind that this is not always 0, especially for older devices who might have a tiny drift.

direction : Joystick -> Int

Starting from the top, get a direction in terms of degress, starting at 0 from the top and going to 360 clockwise.

directionRad : Joystick -> Float

Same as direction, except the value is now a number between 0 and 1.

Joystick
-> { x : Float
, y : Float
}

Convert a joystick's direction to an x and y value. The coordinates are defined as is starting from the top left, so:

  • Top means negative y
  • Left means negative x
  • Right means positive x
  • Bottom means positive y

Both values go from -1 to 1, so (-1, -1) and (1, 1) are the top left and bottom right respectively.