All Projects → KaiseiYokoyama → joycon-rs

KaiseiYokoyama / joycon-rs

Licence: Apache-2.0 license
Joy-Con library for Rust 🦀 🎮

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to joycon-rs

BetterJoyForDolphin
Allows the Nintendo Switch Pro Controller and Joycons to be used with the Dolphin Emulator
Stars: ✭ 44 (-57.69%)
Mutual labels:  bluetooth, nintendo-switch, joycon, nintendo-switch-joycon
Nintendo-Switch-JoyCon-Hack
Hardwiring a push button in a JoyCon to grant bootloader access
Stars: ✭ 44 (-57.69%)
Mutual labels:  nintendo-switch, joycon, nintendo-switch-joycon
joycon
Device access library for Joycon(Nintendo Switch)
Stars: ✭ 59 (-43.27%)
Mutual labels:  bluetooth, nintendo-switch, joycon
nxbt
Control your Nintendo Switch through a website, terminal, or macro.
Stars: ✭ 340 (+226.92%)
Mutual labels:  bluetooth, nintendo-switch
Switch Remoteplay
NOT AN OFFICIAL NINTENDO PRODUCT - Control your Switch remotely (no hacking required)
Stars: ✭ 170 (+63.46%)
Mutual labels:  bluetooth, nintendo-switch
SwiTAS
A usable toolkit for creating Nintendo Switch TASes with homebrew
Stars: ✭ 54 (-48.08%)
Mutual labels:  nintendo-switch, joycon
joyconpi
An attempt at emulating a Nintendo Switch Joy-Con controller with a Raspberry Pi
Stars: ✭ 24 (-76.92%)
Mutual labels:  bluetooth, nintendo-switch
Joycontrol
Emulate Nintendo Switch Controllers over Bluetooth
Stars: ✭ 667 (+541.35%)
Mutual labels:  bluetooth, nintendo-switch
switch joy con as mouse for macos
Tool to use Nintendo Switch Joy-Con as a mouse for macOS
Stars: ✭ 19 (-81.73%)
Mutual labels:  bluetooth, nintendo-switch
Betterjoy
Allows the Nintendo Switch Pro Controller, Joycons and SNES controller to be used with CEMU, Citra, Dolphin, Yuzu and as generic XInput
Stars: ✭ 1,352 (+1200%)
Mutual labels:  bluetooth, nintendo-switch
Keymapper
📱 An Android app that maps any keys to actions.
Stars: ✭ 207 (+99.04%)
Mutual labels:  bluetooth, nintendo-switch
uberducky
Wireless USB Rubber Ducky triggered via BLE (make your Ubertooth quack!)
Stars: ✭ 80 (-23.08%)
Mutual labels:  bluetooth
RejsaRubberTrac
RejsaRubberTrac - A wireless thermal camera for monitoring tire temperatures
Stars: ✭ 77 (-25.96%)
Mutual labels:  bluetooth
ESP-WROOM-Breakout
Breakouts for ESP8266 and ESP32 WiFi/WLAN + Bluetooth modules from Espressif (ESP-WROOM-02, ESP-WROOM-32)
Stars: ✭ 32 (-69.23%)
Mutual labels:  bluetooth
py-bluetooth-utils
Python module containing bluetooth utility functions, in particular for easy BLE scanning and advertising
Stars: ✭ 60 (-42.31%)
Mutual labels:  bluetooth
rpi3-wifi-conf
A simple Python script to configure wifi over bluetooth for a Raspberry Pi 3
Stars: ✭ 112 (+7.69%)
Mutual labels:  bluetooth
AirPodsDesktop
☄️ AirPods desktop user experience enhancement program, for Windows and Linux (WIP)
Stars: ✭ 462 (+344.23%)
Mutual labels:  bluetooth
SARC-Tool
Tool for extracting and packing SARC files present in Nintendo EAD games.
Stars: ✭ 60 (-42.31%)
Mutual labels:  nintendo-switch
onewheel-bluetooth
A python bluetooth data reader for the Onewheel (supporting Gemini firmware, and later).
Stars: ✭ 28 (-73.08%)
Mutual labels:  bluetooth
bluetooth-terminal
ES6 class for serial communication with your own Bluetooth Low Energy (Smart) devices
Stars: ✭ 43 (-58.65%)
Mutual labels:  bluetooth


Joycon-rs

Documentation| Examples| Changelog| ドキュメント

A framework for dealing with Nintendo Switch Joy-Con on Rust easily and efficiently via Bluetooth.

Joycon-rs provides utility to find communicate with, and operate Joy-Con. Please see the documentation comments for detailed instructions on how to use it.

Joycon-rs is in development and is still incomplete. Please be aware the update will include breaking changes for the time being. Pardon out dust!

Setup

On macOS or Windows, there are no preparation.

On linux,

$ sudo apt-get install libudev-dev libusb-1.0-0-dev libfox-1.6-dev

Usage

First, add dependency to Cargo.toml

[dependencies]
joycon_rs = "*"

Then, use prelude on .rs file.

use joycon_rs::prelude::*;

Perfect! Now you have Joycon-rs available in code.

Receive reports

For starters, let's take a simple signal from JoyCon. If you use more than one JoyCon, mspc can be very helpful.

use joycon_rs::prelude::*;

let (tx, rx) = std::sync::mpsc::channel();

let _output = std::thread::spawn(move || {
    // Push buttons or tilt the stick please.
    // Stop with `Cmd + C` or `Ctrl + C`
    while let Ok(message) = rx.recv() {
        dbg!(message);
    }
});

let manager = JoyConManager::get_instance();
let (managed_devices, new_devices) = {
let lock = manager.lock();
    match lock {
        Ok(m) => (m.managed_devices(),m.new_devices()),
        Err(_) => unreachable!()
    }
};

managed_devices.into_iter()
    .chain(new_devices)
    .flat_map(|dev| SimpleJoyConDriver::new(&dev))
    .try_for_each::<_, JoyConResult<()>>(|driver| {
        // Change JoyCon to Simple hid mode.
        let simple_hid_mode = SimpleHIDMode::new(driver)?;

        let tx = tx.clone();

        // Spawn thread
        std::thread::spawn( move || {
            loop {
                // Forward the report to the main thread
                tx.send(simple_hid_mode.read_input_report()).unwrap();
            }
        });

        Ok(())
    })
    .unwrap();

Set player lights

Then, lets deal with player lights.

use joycon_rs::prelude::{*, lights::*};

let (tx, rx) = std::sync::mpsc::channel();

let _output = std::thread::spawn(move || {
    // Stop with `Cmd + C` or `Ctrl + C`
    while let Ok(message) = rx.recv() {
        dbg!(message);
    }
});

let manager = JoyConManager::get_instance();
let (managed_devices, new_devices) = {
let lock = manager.lock();
    match lock {
        Ok(m) => (m.managed_devices(),m.new_devices()),
        Err(_) => unreachable!()
    }
};

managed_devices.into_iter()
    .chain(new_devices)
    .flat_map(|dev| SimpleJoyConDriver::new(&dev))
    .try_for_each::<_, JoyConResult<()>>(|mut driver| {
        // Set player lights
        // [SL BUTTON] 📸💡📸💡 [SR BUTTON]
        driver.set_player_lights(&vec![LightUp::LED1, LightUp::LED3], &vec![Flash::LED0, Flash::LED2]).unwrap();
        tx.send(driver.get_player_lights()).unwrap();
        Ok(())
    })
    .unwrap();

Rumble

use joycon_rs::prelude::*;
use std::convert::TryInto;
use std::ops::Deref;
use joycon_rs::joycon::joycon_features::JoyConFeature;

fn main() -> JoyConResult<()> {
    // First, connect your Joy-Cons to your computer!

    let manager = JoyConManager::get_instance();
    let (managed_devices, new_devices) = {
        let lock = manager.lock();
        match lock {
            Ok(manager) =>
                (manager.managed_devices(), manager.new_devices()),
            Err(_) => unreachable!(),
        }
    };

    managed_devices.into_iter()
        .chain(new_devices)
        .inspect(|d| {
            let lock = d.lock();
            let device = match lock {
                Ok(device) => device,
                Err(e) => e.into_inner(),
            };
            let hid_device: JoyConResult<&HidDevice> = device.deref().try_into();
            if let Ok(hid_device) = hid_device {
                println!("{:?}", hid_device.get_product_string())
            }
        })
        .try_for_each::<_, JoyConResult<()>>(|d| {
            let mut driver = SimpleJoyConDriver::new(&d)?;

            driver.enable_feature(JoyConFeature::Vibration)?;

            // let rumble = Rumble::new(80.0,0.2);
            let rumble = Rumble::new(300.0,0.9);
            driver.rumble((Some(rumble), Some(rumble)))?;

            Ok(())
        })?;

    Ok(())
}

More Examples

Here.

Features

You can use Joycon-rs for...

Planning

  • Receive NFC/IR data
  • Deal with Pro Controller

License

Licensed under Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0)

Contribution

We gladly accept contributions via GitHub pull requests. If you find a bug in the library, it would be appreciated if you could report it in detail to Issues so that it can be reproduced.

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].