From 638fbb2e344d44459b02c3135fb4eea420d5a62b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=9B=E5=A1=9A=E5=8F=B2=E9=AB=98?= Date: Thu, 2 Jul 2020 14:28:41 +0900 Subject: [PATCH 1/2] add pro-con --- index.js | 3 +++ pro-con.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 pro-con.js diff --git a/index.js b/index.js index 20612ed..79ce6ce 100644 --- a/index.js +++ b/index.js @@ -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(); @@ -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"); } diff --git a/pro-con.js b/pro-con.js new file mode 100644 index 0000000..c32021a --- /dev/null +++ b/pro-con.js @@ -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, // TODO: Need resarch. + analogStickR: 130, // TODO: Need resarch. + }; + } + + _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], // TODO: Need resarch. + analogStickR: bytes[9] // TODO: Need resarch. + }; + } +} + +module.exports = ProCon; \ No newline at end of file From afcd51a37ec7df05e1b82bedc32cc9b30fb3e623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=9B=E5=A1=9A=E5=8F=B2=E9=AB=98?= Date: Mon, 6 Jul 2020 10:36:19 +0900 Subject: [PATCH 2/2] fixed analogStick value --- pro-con.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pro-con.js b/pro-con.js index c32021a..c008d64 100644 --- a/pro-con.js +++ b/pro-con.js @@ -25,8 +25,8 @@ class ProCon extends JoyCon { zr: false, analogStickLPress: false, analogStickRPress: false, - analogStickL: 130, // TODO: Need resarch. - analogStickR: 130, // TODO: Need resarch. + analogStickL: 130, + analogStickR: 130 }; } @@ -55,8 +55,8 @@ class ProCon extends JoyCon { analogStickLPress: Boolean(bytes[2] & 0x04), analogStickRPress: Boolean(bytes[2] & 0x08), - analogStickL: bytes[5], // TODO: Need resarch. - analogStickR: bytes[9] // TODO: Need resarch. + analogStickL: [bytes[5], bytes[7]], + analogStickR: [bytes[9], bytes[11]] }; } }