cylon-joystick
v0.22.0
Published
Cylon module for any HID joystick
Downloads
65
Readme
Cylon.js for Joysticks and Controllers
Cylon.js (http://cylonjs.com) is a JavaScript framework for robotics, physical computing, and the Internet of Things (IoT).
This repository contains the adaptor/driver for communicating with joysticks and game controllers. It can be used with any [SDL][http://www.libsdl.org/]-compatible controller.
Default bindings are provided for the Xbox 360, DualShock 3, DualShock 4, and Logitech F310 controllers.
The cylon-gamepad implementation is made possible by the gamepad module https://github.com/creationix/node-gamepad created by @creationix thank you!
Want to use Ruby on robots? Check out our sister project Artoo (http://artoo.io)
Want to use the Go programming language to power your robots? Check out our sister project Gobot (http://gobot.io).
How to Install
Installing Cylon.js with Joystick support is pretty easy.
$ npm install cylon cylon-joystick
Note
- OS X does not provide native support for Xbox 360 controllers. As such, a third-party driver is required.
- If you're using a PS3 controller and want to communicate with it over USB, plug it in and then press the PlayStation button to make sure it's connected.
How to Use
var Cylon = require('cylon');
Cylon.robot({
connections: {
joystick: { adaptor: 'joystick' }
},
devices: {
controller: { driver: 'dualshock-3' }
},
work: function(my) {
["square", "circle", "x", "triangle"].forEach(function(button) {
my.controller.on(button + ":press", function() {
console.log("Button " + button + " pressed.");
});
my.controller.on(button + ":release", function() {
console.log("Button " + button + " released.");
});
});
my.controller.on("left_x:move", function(pos) {
console.log("Left Stick - X:", pos);
});
my.controller.on("right_x:move", function(pos) {
console.log("Right Stick - X:", pos);
});
my.controller.on("left_y:move", function(pos) {
console.log("Left Stick - Y:", pos);
});
my.controller.on("right_y:move", function(pos) {
console.log("Right Stick - Y:", pos);
});
}
}).start();
How to Connect
Plug your USB joystick or game controller into your USB port. If your device is supported by SDL, you are now ready.
Custom joysticks
If you don't have one of the joysticks we support natively, or want to make changes to the configuration, cylon-joystick
supports custom bindings.
To use a custom joystick with Cylon, simply supply the joystick bindings file when you're describing the device:
var Cylon = require('cylon');
var config = __dirname + "/controller.json"
Cylon.robot({
connections: {
joystick: { adaptor: 'joystick' }
},
devices: {
controller: { driver: "joystick", config: config }
},
work: function(my) {
// your custom mappings will be reflected here as events
}
}).start();
A joystick bindings file needs to contain the device's productID
, vendorID
, and description
, as this is how cylon-joystick will find the appropriate device.
For an example of what a bindings file should look like, here is the Xbox 360 controller bindings file we use.
If you are using a "white-label" version of a particular gamepad, you can override the productID
, vendorID
, and/or description
so you can use an existing mapping. For example, a PS3 compatible gamepad that uses the same vendorID
& productID
, but a different name, you could use the existing Dualshock 3 mapping as follows:
devices: {
controller: { driver: 'dualshock-3', description: 'Coolstick 5000' }
},
cylon-joystick-explorer
cylon-joystick
includes the cylon-joystick-explorer
binary.
It's useful for figuring out what compatible gamepads you have connected, as well as making it easier to generate custom bindings JSON files.
For best use, install cylon-joystick
globally:
$ npm install -g cylon-joystick
Then just run the command:
$ cylon-joystick-explorer
Documentation
We're busy adding documentation to our web site at http://cylonjs.com/ please check there as we continue to work on Cylon.js
Thank you!
Contributing
For our contribution guidelines, please go to https://github.com/hybridgroup/cylon/blob/master/CONTRIBUTING.md .
Release History
For the release history, please go to https://github.com/hybridgroup/cylon-joystick/blob/master/RELEASES.md .
License
Copyright (c) 2013-2016 The Hybrid Group. Licensed under the Apache 2.0 license.