All Projects → tomayac → joy-con-webhid

tomayac / joy-con-webhid

Licence: Apache-2.0 license
Use the Nintendo Switch Joy-Cons via the WebHID API

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to joy-con-webhid

XJoy
Use Nintendo Switch JoyCons as a virtual Xbox 360 controller in Windows
Stars: ✭ 309 (+406.56%)
Mutual labels:  joycon, joy-cons
Nintendo-Switch-JoyCon-Hack
Hardwiring a push button in a JoyCon to grant bootloader access
Stars: ✭ 44 (-27.87%)
Mutual labels:  joy-con, joycon
joycon-toolweb
Joy-Con and Pro Controller color modification tool
Stars: ✭ 23 (-62.3%)
Mutual labels:  joy-con, webhid
proscene
Processing library for the creation of interactive scenes
Stars: ✭ 45 (-26.23%)
Mutual labels:  hid
pi400kb
Raw HID keyboard forwarder to turn the Pi 400 into a USB keyboard
Stars: ✭ 182 (+198.36%)
Mutual labels:  hid
BlueRetro
Multiplayer Bluetooth controllers adapter for retro video game consoles
Stars: ✭ 520 (+752.46%)
Mutual labels:  hid
joycon
Device access library for Joycon(Nintendo Switch)
Stars: ✭ 59 (-3.28%)
Mutual labels:  joycon
joyconpi
An attempt at emulating a Nintendo Switch Joy-Con controller with a Raspberry Pi
Stars: ✭ 24 (-60.66%)
Mutual labels:  hid
veikk-linux-driver
Linux driver for VEIKK-brand digitizers
Stars: ✭ 130 (+113.11%)
Mutual labels:  hid
BetterJoyForDolphin
Allows the Nintendo Switch Pro Controller and Joycons to be used with the Dolphin Emulator
Stars: ✭ 44 (-27.87%)
Mutual labels:  joycon
authenticator-rs
Rust library to interact with Security Keys, used by Firefox
Stars: ✭ 209 (+242.62%)
Mutual labels:  hid
awesome-webhid
Curated list of resources relating to the WebHID (Human Interface Device) API
Stars: ✭ 126 (+106.56%)
Mutual labels:  webhid
windows-touchpad
Make use of touchpad for handwriting in Windows
Stars: ✭ 30 (-50.82%)
Mutual labels:  hid
hidstream
Streaming HID events in Node.js
Stars: ✭ 52 (-14.75%)
Mutual labels:  hid
gods4
Golang library to interact with Sony DualShock4
Stars: ✭ 26 (-57.38%)
Mutual labels:  hid
mx3000control
Perixx MX-3000 mouse unofficial configuration tool for Linux
Stars: ✭ 20 (-67.21%)
Mutual labels:  hid
nxbt
Control your Nintendo Switch through a website, terminal, or macro.
Stars: ✭ 340 (+457.38%)
Mutual labels:  hid
wiimote-webhid
A Wiimote implementation using WebHID - AKA: Wiimote for the Web
Stars: ✭ 31 (-49.18%)
Mutual labels:  webhid
stadiacontroller
Command line application that emulates an Xbox 360 controller from a wired Stadia controller on Windows.
Stars: ✭ 142 (+132.79%)
Mutual labels:  hid
Trezor.Net
Cross platform C# library for talking to the Trezor hardwarewallet
Stars: ✭ 38 (-37.7%)
Mutual labels:  hid

Joy-Con WebHID

A WebHID driver for Nintendo Joy-Cons with support for all buttons, analog sticks, and the device's gyroscope and accelerometer sensors.

Demo

See the live demo of the driver.

Joy-Con WebHID demo showing two Joy-Cons slightly tilted with one of the analog sticks moved to the right on one Joy-Con and the 'A' button pressed on the other.

Another demo is Chrome Dino WebHID, where you can play the Chrome dino game 🦖 over WebHID by jumping with a Joy-Con controller in your pocket.

Joy-Con WebHID Chrome dino demo

Installation

npm install --save joy-con-webhid

(For Linux, see this comment on Issue #3 for required pre-steps.)

Usage

Make sure you have a pairing button on your page.

<button class="connect" type="button">Connect Joy-Con</button>

Import the script and hook up the pairing button. Then create an interval that waits for Joy-Cons to appear, which can happen after pairing, on page load when previously paired Joy-Cons are reconnected, and when Joy-Cons wake up again after being idle.

import * as JoyCon from './node_modules/dist/index.js';

// For the initial pairing of the Joy-Cons. They need to be paired one by one.
// Once paired, Joy-Cons will be reconnected to on future page loads.
document.querySelector('.connect').addEventListener('click', async () => {
  // `JoyCon.connectJoyCon()` handles the initial HID pairing.
  // It keeps track of connected Joy-Cons in the `JoyCon.connectedJoyCons` Map.
  await JoyCon.connectJoyCon();
});

// Joy-Cons may sleep until touched and fall asleep again if idle, so attach
// the listener dynamically, but only once.
setInterval(async () => {
  for (const joyCon of JoyCon.connectedJoyCons.values()) {
    if (joyCon.eventListenerAttached) {
      continue;
    }
    // Open the device and enable standard full mode and inertial measurement
    // unit mode, so the Joy-Con activates the gyroscope and accelerometers.
    await joyCon.open();
    await joyCon.enableStandardFullMode();
    await joyCon.enableIMUMode();
    await joyCon.enableVibration();
    // Get information about the connected Joy-Con.
    console.log(await joyCon.getDeviceInfo());
    // Rumble.
    await joyCon.rumble(600, 600, 0.5);
    // Listen for HID input reports.
    joyCon.addEventListener('hidinput', ({ detail }) => {
      // Careful, this fires at ~60fps.
      console.log(`Input report from ${joyCon.device.productName}:`, detail);
    });
    joyCon.eventListenerAttached = true;
  }
}, 2000);

Why not use the Gamepad API?

The Gamepad API supports Joy-Con controllers out-of-the-box, but since the API (currently) does not have a concept of orientation, the Joy-Cons' accelerometer and gyroscope data cannot be accessed. The buttons and analog sticks are fully exposed, though. If all you need is this, then by all means go for the Gamepad API.

Acknowledgements

This project takes heavy inspiration from @wazho's ns-joycon, which in turn is based on @dekuNukem's Nintendo_Switch_Reverse_Engineering. The rumble code was contributed by @baku89.

License

Apache 2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].