Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const HID = require("node-hid");
const JoyConLeft = require("./joy-con-left");
const JoyConRight = require("./joy-con-right");
const ProCon = require("./pro-con");

function listConnectedJoyCons() {
const devices = HID.devices();
Expand All @@ -13,6 +14,8 @@ function listConnectedJoyCons() {
return new JoyConLeft(device.path);
} else if (device.productId === 8199) {
return new JoyConRight(device.path);
} else if (device.productId === 8201) {
return new ProCon(device.path);
} else {
throw new Error("Unknown Joy-Con model");
}
Expand Down
64 changes: 64 additions & 0 deletions pro-con.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const JoyCon = require("./joy-con");

class ProCon extends JoyCon {
constructor(path = null) {
super(path);

this.side = null;

this.buttons = {
dpadUp: false,
dpadDown: false,
dpadLeft: false,
dpadRight: false,
a: false,
x: false,
b: false,
y: false,
minus: false,
plus: false,
screenshot: false,
home: false,
l: false,
r: false,
zl: false,
zr: false,
analogStickLPress: false,
analogStickRPress: false,
analogStickL: 130,
analogStickR: 130
};
}

_buttonsFromInputReport3F(bytes) {
return {
dpadLeft: bytes[3] === 5 || bytes[3] === 6 || bytes[3] === 7,
dpadDown: bytes[3] === 3 || bytes[3] === 4 || bytes[3] === 5,
dpadUp: bytes[3] === 0 || bytes[3] === 1 || bytes[3] === 7,
dpadRight: bytes[3] === 1 || bytes[3] === 2 || bytes[3] === 3,

a: Boolean(bytes[1] & 0x02),
x: Boolean(bytes[1] & 0x08),
b: Boolean(bytes[1] & 0x01),
y: Boolean(bytes[1] & 0x04),

minus: Boolean(bytes[2] & 0x01),
plus: Boolean(bytes[2] & 0x02),
screenshot: Boolean(bytes[2] & 0x20),
home: Boolean(bytes[2] & 0x10),

l: Boolean(bytes[1] & 0x10),
zl: Boolean(bytes[1] & 0x40),
r: Boolean(bytes[1] & 0x20),
zr: Boolean(bytes[1] & 0x80),

analogStickLPress: Boolean(bytes[2] & 0x04),
analogStickRPress: Boolean(bytes[2] & 0x08),

analogStickL: [bytes[5], bytes[7]],
analogStickR: [bytes[9], bytes[11]]
};
}
}

module.exports = ProCon;