ns-joycon controls buffer stream by HID, and extracts the data from accelerometer, gyroscope and HD Rumble.
This project is an implementation from dekuNukem/Nintendo_Switch_Reverse_Engineering by Node.js.
npm install ns-joycon
# If you encounter some problems when `npm install ns-joycon`.
npm install ns-joycon --unsafe-perm
Checkout the demo project at wazho/ns-joycon-showcases.
Connect your Joy-Con(s) using bluetooth with PC (currently Linux only).
And then execute program by administrator below (root can access hardware).
const JoyCon = require('ns-joycon'); // JavaScript
// import * as JoyCon from 'ns-joycon'; // TypeScript or Babel
JoyCon.findControllers((devices) => {
// When found any device.
devices.forEach(async (device) => {
console.log(`Found a device (${device.meta.serialNumber})`);
// Add a handler for new device.
device.manageHandler('add', (packet) => {
console.log(device.meta.product, packet);
});
await device.enableIMU();
});
});
npm test
Find controllers that are detected.
-
Arguments
callback
is of the formcallback(devices)
Add a handler to process packet data.
-
Arguments
action
isadd | remove
callback
is of the formcallback(data)
Request Joy-Con to provide its device info.
-
Return value
Promise<DeviceInfo>
is{ firmwareVersion, type, macAddress, spiColorInUsed }
Enable inertial measurement unit (IMU).
After this script, controller will send Input Report 0x30 per 15 ms.
-
Return value
Promise<void>
Disable inertial measurement unit (IMU).
-
Return value
Promise<void>
Enable vibration for a while.
-
Return value
Promise<void>
Disable vibration in immediately.
-
Return value
Promise<void>
Real data from Joy-Con (R) below.
<Buffer 30, 3e, 4e, 0a, 10, 00, 00, 00,
00, c7, 18, 76, 09, 1a, 00, f1,
09, d5, f3, b4, ff, 5b, ff, 90,
ff, 17, 00, de, 09, c7, f3, af,
ff, 5e, ff, 8f, ff, 0a, 00, cd,
09, c7, f3, b8, ff, 65, ff, 89,
ff>
// inputReportID
{
"_raw": "<Buffer 30>",
"_hex": ["30"]
}
// Timer
{
"_raw": "<Buffer 2c>",
"_hex": ["2c"]
}
// batteryLevel
{
"_raw": "<Buffer 4e>",
"_hex": ["4"],
"level": "medium"
}
// connectionInfo
{
"_raw": "<Buffer 4e>",
"_hex": ["e"]
}
// buttonStatus
{
"_raw": "<Buffer 00 00 00>",
"_hex": [ "00", "00", "00" ],
"y": false,
"x": false,
"b": false,
"a": false,
"r": false,
"zr": false,
"down": false,
"up": false,
"right": false,
"left": false,
"l": false,
"zl": false,
"sr": false,
"sl": false,
"minus": false,
"plus": false,
"rightStick": false,
"leftStick": false,
"home": false,
"caputure": false,
"chargingGrip": false
}
// analogStickLeft
{
"_raw": "<Buffer 00 00 00>",
"_hex": [ "00", "00", "00" ],
"horizontal": 0,
"vertical": 0
}
// analogStickRight
{
"_raw": "<Buffer 70 c8 75>",
"_hex": [ "70", "c8", "75" ],
"horizontal": 2160,
"vertical": 1884
}
// vibrator
{
"_raw": "<Buffer 0a>",
"_hex": [ "0a" ]
}
// accelerometers
[
{
"x": {
"_raw": "<Buffer 67 01>",
"_hex": [ "67", "01" ],
"acc": 0.087596
},
"y": {
"_raw": "<Buffer 23 00>",
"_hex": [ "23", "00" ],
"acc": 0.00854
},
"z": {
"_raw": "<Buffer 61 f0>",
"_hex": [ "61", "f0" ],
"acc": -0.975756
}
},
// Repeat two more, totally collected three times.
]
// gyroscopes
[
[
{
"_raw": "<Buffer 17 00>",
"_hex": [ "17", "00" ],
"dps": 1.40369,
"rps": 0.003896
},
{
"_raw": "<Buffer ca ff>",
"_hex": [ "ca", "ff" ],
"dps": -3.29562,
"rps": -0.009148
},
{
"_raw": "<Buffer d8 ff>",
"_hex": [ "d8", "ff" ],
"dps": -2.4412,
"rps": -0.006776
}
],
// Repeat two more, totally collected three times.
]
Average of 3 times accelerometers.
// actualAccelerometer
{
"acc": {
"x": 0.001305,
"y": 0.000137,
"z": -0.014623
}
}
Average of 3 times gyroscopes.
// actualGyroscope
{
"dps": [ 0.02014, -0.049129, -0.035703 ],
"rps": [ 0.000056, -0.000136, -0.000099 ]
}