hybridgroup/cylon-joystick — pull request #10 by stewart (2014-06-24 19:38:52+00:00)
Title: Refactor - Use LibSDL

This refactors Cylon-Joystick to use the SDL library. By default it supports the Xbox 360 and DualShock 3 controllers, but a custom controller can easily be used by supplying a JSON file with the mappings.

Examples:

## Xbox 360:

```javascript
Cylon.robot({
connection: { name: 'joystick', adaptor: 'joystick' },
device: { name: 'controller', driver: 'xbox-360' },

work: function(my) {
["a", "b", "x", "y"].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("left_y:move", function(pos) {
console.log("Left Stick - Y:", pos);
});

my.controller.on("right_x:move", function(pos) {
console.log("Right Stick - X:", pos);
});

my.controller.on("right_y:move", function(pos) {
console.log("Right Stick - Y:", pos);
});

my.controller.on("lt:move", function(pos) {
console.log("Left Trigger: ", pos);
});

my.controller.on("rt:move", function(pos) {
console.log("Right Trigger: ", pos);
});
}
}).start();
```

## DualShock 3:

```javascript
Cylon.robot({
connection: { name: 'joystick', adaptor: 'joystick' },
device: { name: '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();
```

## Custom:

```javascript
Cylon.robot({
connection: { name: 'joystick', adaptor: 'joystick' },

device: {
name: 'controller',
driver: 'custom-joystick',
config: __dirname + "/controller_bindings.json"
},

work: function(my) {
// etc, you get the idea
}
}).start();
```