[Unreleased]
Added
Gamepad.start_link/1: starts a reader that sends each controller event to a:sink, either a pid (sent{:gamepad, event}) or a one-argument function.:sourceoverrides the detected reader:{:helper, path}runs any program that writesGamepad.Wirelines, and{:linux, glob}reads the joystick device files matchingglob. Returns:ignorewhen the machine has no reader.Gamepad.available?/0andGamepad.source/0: whether a reader exists and which one (:linux,{:helper, path}ornil).Gamepad.Wire: the line protocol (device,gone,button,axis) andparse/1, which turns a line into an event map —:connected,:disconnected,:buttonwithpressed,:axiswithvalue— ornil. Buttons and axes use Xbox layout names, listed bybuttons/0andaxes/0. Sticks run-1.0..1.0, triggers0.0..1.0.- Linux reader:
/dev/input/js*read directly and decoded byGamepad.Linux(devices/0,1, which takes the glob to list, anddecode/2); new device files are picked up every two seconds. The device files must be readable by the user. - macOS reader:
priv/gamepad_helper, built fromc_src/gamepad_helper.swifton GameController.framework bymix compilewhenswiftcis onPATH. Withoutswiftcthe build skips it andstart_link/1returns:ignore. - Windows reader:
priv/gamepad_helper.exe, built fromc_src/gamepad_helper_win.con XInput bymix compilethroughMakefile.win. Requires the Visual Studio Build Tools (clandnmake). - Browser reader:
priv/static/gamepad.js, whoseGamepad.watch(sink, options)polls a page's Gamepad API and callssinkwith oneGamepad.Wireline per change.options.everypolls on a millisecond timer instead of every animation frame,stop()on the returned handle ends it, andGamepad.available()reports whether the page has the API.Gamepad.browser_script/0returns the file's path for serving.
Fixed
- The macOS and Windows helpers exit when the program reading them closes their input, as it does on exiting or crashing. They kept running, one more for every run of the program.
- On Linux the device readers run inside the VM and end with it.