Make a logitech gamepad do something useful
Provides an EventEmitter with events for the buttons, dpad and analog sticks on the Logitech Dual Action Controller.
Heavily inspired by andrew/node-xbox-controller
npm install logitech-dual-action-controller
Step 1. Plug in the controller
Step 2. Add some event listeners
// Create a new one
var controller = new require('logitech-dual-action-controller')()
controller.on('1:release', console.log)
controller.on('left:move', function (data) {
// horizontal positon of left analog stick -100 to 100 and 0 at the center.
var rotateSpeed = data.x
rotateRobot(rotateSpeed)
})
The dual action has 12 numbered buttons, 1 to 12, a dpad and 2 analog sticks.
Buttons: There are :press
and :release
events for buttons 1
to 12
like so: 1:press
1:release
Dpad: There are :press
and :release
events for the dpad directions like so: dup:press
, dleft:release
.
There is a dcenter:press
event if you just want to know when they stop pressing the dpad.
Analog sticks: There are left:move
and right:move
events for the analog sticks,
with a data
parameter object like { x: 0, y: 0 }
representing the position of the stick from -100 to 100 with 0 at the center.
100
|
-100 - o - 100
|
-100
Source | Events | Description |
---|---|---|
1,2,3,4 |
#:press #:release
|
arcade buttons (replace # with button number) |
5,6,7,8 |
#:press #:release
|
shoulder button |
9,10 |
#:press #:release
|
start(ish), select(ish) |
11,12 |
#:press #:release
|
left stick press, right stick press |
dup,dright,ddown,dleft |
#:press #:release
|
dpad digital directions |
left,right |
left:move , right:move
|
analog stick movement with x,y position in data param |
{
vendorId: 1133,
productId: 49686,
path: 'USB_046d_c216_14300000',
serialNumber: '',
manufacturer: 'Logitech',
product: 'Logitech Dual Action',
release: 768,
interface: -1
}
We get an 8 byte Buffer from each data
event.
See: http://www.autohotkey.com/board/topic/64178-hid-template-and-example-for-logitech-dual-action/