Node.js module to read joystick data from Logitech Gamepad F710
UNLICENSE License
Node.js module to read joystick data from Logitech Gamepad F710.
npm install joystick-logitech-f710
var Joystick = require("joystick-logitech-f710");
Joystick.create("/dev/input/js0", function (err, joystick) {
if (err) {
throw err;
}
joystick.on("button:a:press", function () {
console.log("jump");
});
joystick.on("button:b:press", function () {
console.log("fire");
});
});
button:a:press
button:a:release
button:b:press
button:b:release
button:x:press
button:x:release
button:y:press
button:y:release
button:lb:press
button:lb:release
button:rb:press
button:rb:release
button:lt:press
button:lt:release
button:rt:press
button:rt:release
button:back:press
button:back:release
button:start:press
button:start:release
button:ls:press
button:ls:release
button:rs:press
button:rs:release
joystick.on("button:start:press", function () {
console.log("start button has been pressed");
});
stick:1:vertical:up
stick:1:vertical:down
stick:1:vertical:zero
stick:1:horizontal:right
stick:1:horizontal:left
stick:1:horizontal:zero
stick:2:vertical:up
stick:2:vertical:down
stick:2:vertical:zero
stick:2:horizontal:right
stick:2:horizontal:left
stick:2:horizontal:zero
stick:3:vertical:up
stick:3:vertical:down
stick:3:vertical:zero
stick:3:horizontal:right
stick:3:horizontal:left
stick:3:horizontal:zero
Each of these events will be emitted with the current stick position. Possible position values (unscaled):
*:up
= 1..32767*:down
= 1..32767*:right
= 1..32767*:left
= 1..32767*:zero
= 0This should help to understand what values you can expect:
32767
|
32767 -- 0 -- 32767
|
32767
You can scale the maximum axes position to a value between 1 and 32767:
joystick.setMaximumAxesPosition(100);
Now you can expect the following position values:
100
|
100 -- 0 -- 100
|
100
joystick.on("stick:1:vertical:up", function (position) {
console.log("current up position: " + position);
});