Home

Awesome

gamepad

This is a pet project, a module for reading the input from an old PS3 like controller, which I will then be using to control my quadcopter.

Introduction

This module provides the following basic mechanisms:

Usage

Check examples/ for more detailed usage examples.

Here's a very simple example of how you could get the data out of the gamepad:

var Gamepad = require('node-gamepad');

Gamepad.device(function (err, gamepad) {
    if (err) {
        return console.error('Unable to get pad:', err);
    }

    gamepad.on('data', function (data) {
        console.log(data);
    });
    gamepad.on('error', function (err) {
        console.error(err);
    });
});

This will output something like this on every data event:

{
    rawData: <Buffer 80 80 82 80 80 0f 00 40>,
    leftStick: { h: 128, v: 128, pressed: false },
    rightStick: { h: 128, v: 128, pressed: false },
    directional: { up: false, right: false, down: false, left: false },
    triangle: false,
    circle: false,
    cross: false,
    square: false,
    start: false,
    select: false,
    analog: true,
    l1: false,
    r1: false,
    l2: false,
    r2: false
}

The rawData property is the raw data read from the HID, while all the other properties are convenience properties already parsed from the raw data. Note that the stick h and v values range from 0 to 255.

TODO

License

Released under the MIT License.