elm-gamepad: experimental API for discussion

516 views
Skip to first unread message

Conrad Parker

unread,
May 2, 2017, 8:23:21 PM5/2/17
to elm-dev
Hi,

I've recently updated elm-gamepad for Elm 0.18. I forked this from @zimbatm back in Elm 0.15 and have been updating it for the past few years as part of dreambuggy. I've now split it back out into its own repo:


The API is still a fairly raw wrapper around the W3C Gamepad spec, which is not exactly a delightful interface. For example, button and axis(joystick) values are represented as long lists of floats.

Nevertheless you should be able to plug in a game controller and try this out in your app. There's many possible ways to improve the API and I'd love some suggestions or pull requests / forks.

I'm willing to continue maintaining this (I'm actively using it) and shepherding it towards eventual inclusion in elm.

Conrad.


Martin Janiczek

unread,
May 6, 2017, 5:23:26 PM5/6/17
to elm-dev
Kudos for your work on this :)
Have you thought about `Sub` interface similar to http://package.elm-lang.org/packages/elm-lang/keyboard/1.0.1/Keyboard ? It seems more declarative than asking for Cmds repeatedly, although that's maybe more suited for games?

Conrad Parker

unread,
May 7, 2017, 6:20:08 PM5/7/17
to elm-dev
Hi,

thanks, yes it'd be more natural to have a subscription, I'm just not quite sure how to go about it using the underlying polling API.

Conrad.

Conrad Parker

unread,
May 11, 2017, 9:05:04 PM5/11/17
to elm-dev
Just an update on kfish/elm-gamepad, I've added named fields for the StandardGamepad mapping, which browsers convert most gamepads into.


type alias Button =
 
{ pressed : Bool
 
, value : Float
 
}


type
alias Stick =
   
{ x : Float
   
, y : Float
   
, button : Button
   
}

type
alias StandardGamepad_ =
   
{ id : String

   
, buttonBack   : Button
   
, buttonStart  : Button
   
, buttonLogo   : Button

   
, buttonA : Button
   
, buttonB : Button
   
, buttonX : Button
   
, buttonY : Button

   
, leftTrigger    : Button
   
, leftBumper     : Button
   
, leftStick      : Stick

   
, rightTrigger    : Button
   
, rightBumper     : Button
   
, rightStick      : Stick

   
, dPadUp    : Button
   
, dPadDown  : Button
   
, dPadLeft  : Button
   
, dPadRight : Button
   
}


Visually:


Conrad.

john....@gmail.com

unread,
Jun 1, 2017, 7:13:40 AM6/1/17
to elm-dev
You could record the state of the pad, poll it n times per second, and send a subscription message anytime a change is detected. Doesn't JavaScript do the same thing deep down for key(board) up/down events?
Reply all
Reply to author
Forward
0 new messages