This started a few months ago when I wanted to use a PS3 DualShock for my Node Bots projects, I needed a library that was simple to use and easy to include in any project.
After a few hours of searching and playing with existing implementations I decided to write my own.
Getting Started:
Before you can start you will need the following:
Node 0.8 although I recommend 0.10
In Linux you will need libudev-dev
Pair with the controller via bluetooth
Create your project folder and run the following npm command:
$ npm install dualshock
Show me the code:
var dualShockLib = require('dualshock-controller');
var dualShock3 = dualShockLib();
//make sure you add an error event handler
dualShock3.on('error', function(data) {
//Some stuff did not work.
});
//add event handlers:
dualShock3.on('left:move', function(data) {
//...doStuff();
});
dualShock3.on('right:move', function(data) {
//...doStuff();
});
dualShock3.on('square:press', function (data) {
//...doStuff();
});
dualShock3.on('square:release', function (data) {
//...doStuff();
});
//connect the controller
dualShock3.connect();
Events documentation
As you could tell by the code above, the library exposes events that you can subscribe to. I am currently working on better documentation but for more information on what events are available you can review the following json fileto see what buttons are mapped. Each button will have a "pressed", "released" and "analog" event.
Code is in github (pull requests appreciated) Below is a bit of a teaser video.