Giter Club home page Giter Club logo

joyconlib's Introduction

JoyconLib

Imgur

Nintendo Switch Joy-Con library for Unity. Featuring: button/stick polling, HD rumble, and accelerometer data processing.

To use, add an empty GameObject to your scene and attach JoyconManager.cs. Look at JoyconDemo.cs for sample code to get you up and running.

With thanks/apologies to CTCaer, dekuNukem, shinyquagsire23, mfosse, and riking.

Uses C# glue code and HIDAPI binaries from Unity-Wiimote

GetVector method (attempt at sensor fusion implementation) is still unreliable! Enable in JoyconManager at your own risk. Sensor fusion code is in Joycon.ProcessIMU. Feel free to submit pull requests; sensor fusion code based on this guide.

joyconlib's People

Contributors

jethac avatar playfulbacon avatar wormyrocks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

joyconlib's Issues

Relative Rotation

Sorry, it was a noob question that I finally solved myself. Now I don't see how to delete that Issue so I just canceled it.

Mirror an axis of rotation?

Hi,
Is it possible to mirror the way an object rotates when you rotate the joycon, i.e. make the cube roll right when you roll the joycon left?
I find that when you look at the cube in the default scene from below, the motion of the joycon lines up just fine, but when you move the camera to be on the horizon with the cube, one of the axes are wrong.
By the way I think this library is super cool!
Thanks.

HIDapi.hid_open_path unable to open path

When attempting to start JoyconManager, Visual Studio throws me an error:
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

Open investigating, it turns out that the handle passed by
IntPtr handle = HIDapi.hid_open_path(enumerate.path);
Gives an all-zeroed out value. Is this a known problem and can it be resolved?

EDIT: Solved by taking care with 32/64-bit .dlls and build properties.

wrong orientation

game object rotate wrong
im read all issues to this theme, no one help
how to fix?

Both joycons detected, but all data is 0

I created an empty object and added the manager to it

I have two visual controllers, each have a demo script attached.
One with Jc_ind1=0 and one with Jc_ind=1

Both joycons are detected, but all data is always zeros. (Gyro, acceleration, orientation, etc.)

Edit: After restarting my computer, I now get the buttons and joystick, but no gyro
Edit 2: Had to toggle IMU back on as well oops.
Turns out it was a "turn off an on again" Windows issue -.-

Y and Z rotations switched

Hello,

When I turn the JoyCon, the y and z rotations seem to be switched, is there a way to fix this?

Thanks!

Joycons Not Being Found

When I run the sample scene in Unity, I get a Debug.Log that says "No Joy-Cons found", even though I've already paired the JoyCon to my computer using BlueTooth. Am I missing a step? Do I need to use an external tool to connect to the JoyCon, like BetterJoy?

I am using a 2020 version of Unity if that could be the source of the problem. I know this project was originally made with an older version.

Messing around with LEDs

I see that if you have multiple joycons connected to your PC the LEDs on the joycons change. Is there a way where I can manipulate the LEDs during runtime? Can you have multiple on at once?

Are you planning to import IR support ?

Hi
I wanted to do a "pointer" with the right joycon and tried it with acceleremoter but i can't find a way to do it
I guess it would be better with IR but i don't know if you're planning to implement it ?

Best regards

Example Scene broken

MacOS Catalina 10.15.3
Unity 2019.3.5

The example scene is broken. It is missing scripts and missing textures.

  • John

Getting hidapi.dll to work with Hololens

Hello!

I tried using this library with Unity editor with holographic emulation for Hololens. Works as it should with 64-bit version of hidapi.dll (as Unity editor only supports 64-bit plugins as far as I know), taken from Unity-Wiimote-Master package (followed this tutorial : http://baba-s.hatenablog.com/entry/2017/11/12/090000).
I'm having trouble getting the thing to build and work on Hololens. The issue is with hidapi.dll. 64-bit version doesn't work, since Hololens only supports 32-bit binaries. And building the project with a 32-bit version of hidapi.dll makes the application crash upon startup on Hololens. The code crashes on hidapi's hid_init() method.

On a related matter, is there any way to test input from controller on hololens ? I can pair Joycon in Settings without an issue and it says its connected, but haven't found a way to test it.

Tried on Unity version 2018.4.10f1.

Any help would be appreciated !

Linux Support?

Hi! I'm looking to add linux support to this library. I've downloaded and built HIDAPI from this GitHub repo but I was left with multiple files, none of which were simply named "hidapi" like the windows and mac versions in this repo's plugins folder.

The files created are:
libhidapi-hidraw.a
libhidapi-hidraw.la
libhidapi-hidraw.so
libhidapi-hidraw.so.0
libhidapi-hidraw.so.0.0.0
libhidapi-libusb.a
libhidapi-libusb.la
libhidapi-libusb.so
libhidapi-libusb.so.0
libhidapi-libusb.so.0.0.0

Also, I'd like some help knowing what to do once I've selected the right file.

Thank you! :)

Way to get single Axis orientation with GetVector()?

Hi, I'm having a fantastic time using this package! However, I'm having an issue where I want to create a Quaternion that only uses one Axis of the joycon's orientation (the X axis for example), and so far it hasn't been working. It either doesn't with any of the joycon's Axes or all of them. I saw someone had the same problem as me last November, but it was closed with no followup. Thanks!

Connecting Joycon to android

After much annoyance with Unity complaining about various things, and after digging through other issues, I managed to get a simple scene working, with two cuboids representing Joycon that rotate to match my two Joycon connected to my laptop. I then built the scene for android and ran it on my phone, with my two Joycon already connected and working, and... nothing. Just two lifeless cuboids staring back at me. Tried disconnecting and reconnecting the Joycon, tried restarting the app... nothing. I noticed someone else already raised an issue about android support, but it got no response. Is there some other plugin needed to be able to use this on android? (like a BLE plugin) Or is there some other way to get Unity to recognise them when they are connected to Android? (when connected to my phone the names are the exact same as on my Laptop (Joy-Con (L) and Joy-Con (R)) and they show the same controller icon)

Problem with GetButtonDown executing more than one time

Hello! I am using this library and everything is working great, except when I had to get the values for the buttons. If I execute the method"GetButtonDown" for whatever button in the Update part of a class, it's invoked more than one time (for me is between 4 and 6 times) meaning is detecting the button pressed during 4 updates. I think this is not the intended behaviour, someone knows how to fix this?
I am using unity 2019.3.15f1

Pairing Issue After Turning Controller Off

Hey there,

started working with this lib for a project, great stuff btw, really helpful.

Getting a trouble when the Demo Project is launched (Unity editor or Standalone build), I was wondering if any of you have had the same issue and how you handled it:

  • When turning off the controller with the SYNC button between SL,SR, the controller will loose its pairing with Windows and not reconnect anymore. The only way is to close Unity/Build, remove the device and re-pair it.

Some Info:

  • Win 10 64bit
  • Unity 2019.2.17f1

Issue present on Mac also.
Tried already different hidapi.dll versions, bluetooth drivers too.

Ty

Switch ringcon compatibility.

Any ideas on how we might be able to get ring con compatibility to work. I am a bit new to this, but I took some time to read through JoyCon.cs and some of info on github (excuse my ignorance if anything I write sounds off).

I ran the demo with my switch joy con and attached the ring con. I hopped that the ring con tension sensor might report it as one of the exiting analog inputs. But that doesn't seem to be the case after checking the unity inspector.

Perhaps the ring con tension data is available on the HIDapi, if so we might be able to process those bytes coming into the report_buff that JoyCon.cc. We may need to request a longer buffer from HIDapi? Or issue some other request to it? If possible, any idea where we might find some details on how to decode that new data off the buffer?

Maybe its not possible to do this without updating the HIDapi as well? Perhaps HIDapi needs an update as well to even pull in this new data?

I do recall my switch issuing a "controller update" when I setup Ring fit. So perhaps something new is going on and HIDapi also needs an update?

Otherwise, perhaps the library you use to get the report_buffer needs to be updated as well.

Is there any homebrew software elsewhere that anyone knows of using the ring con yet?

Thanks for taking a look. Any pointers would be helpful :).

Having only certain Orientation Axis function

Hia,

I have been testing out the JoyconLib and it honestly is amazing, but I assume I am real thick, I have been trying to mess with the joycon demo code and try to figure out different ways I could use it.

I do not seem to have a concrete way of having only a certain Axis rotate. For example the orientation will rotate in a full 360 on the X,Y,Z. But is there a way to have it only rotate on the X for example. I dont know if I am too thick, but if someone could help me out! You'd be a life saver.

I will still be trying to mess with it and see if I can figure something out in the meantime if anyone knows anything.

Cheers,
Mo

Analog values for stick

Hey there, looks like an awesome library you provided here! Love the fact that you're able to read the gyros and use the HD rumble.

Quick question though: Are you able to read analog values from the stick using the library? I currently use the InputSystem from Unity (Input System V1.0.0) and can only read (-1,0,1) as values. I'd love to get values in between like 0.5 for example but can't seem to get it working. :/

Gyro or accelerometer

The demo video showcases 3D rotation which is usually done using gyro data.
I was wondering if this lib actually outputs accelerometer data or has it been mistaken for gyro?

Button mapping bug on game start

First of all, fantastic library, very much appreciate that it was shared with the world. Also realise that there's not much traction on this anymore so this may never be answered!

Using Unity 2020.3.33f1 on Mac I'm finding that very occasionally - maybe 1 in 100 plays - that my game starts up and the button mapping for the controller is wrong. Stick x direction is being triggered without moving and buttons are debugging as different button presses. Stop/restart or reload of scene fixes it. Not been able to consistently replicate and can't confirm if its isolated to a specific OS or version.

Mac itself - macOS 12.3.1 - has connection issues with a Joy-Con anyway, disconnects itself randomly after approx. 15-20 mins. That appears to be a hardware issue unrelated to the library as have read about it elsewhere.

Can someone help me with this?

I'm new to all this and I'm having a lot of troubles to making it work, when I add the lib everything looks fine, but, when i put the demo code and make it play, only the accel and gyro works, and the buttons doesn't work at all, I'm using the vjoy driver but apparently it doesn't work either because, when I put the monitor and press any button, it doesnt detect anything

Read Joycon color?

Does this read the Joycons colors? The Joycons store a color for their body and a color their buttons. I wonder how I can get the colors to my game.

connecting already paired controllers

hi.
i have problem that I am not able to connect controllers already paired to pc after reboot.
actually i need unpair them and pair agian :(
also they seem to turn off after 20 minutes not matter what I do.

any suggestion?

Lag and controllers becoming unresponsive

Thanks again for getting this all working. I have finally freed up time to start tinkering with this and have noticed some interesting issues. The first time I fired it up the entire thing went incredibly easy. My joycons connected flawlessly, Unity read them and they were super responsive, I was loving it and testing out the different buttons and delighted to see the rumble button firing correctly.

I then set about creating a UWP friendly version of the joycon class, I finally got that in a good place, went to test and nothing. I noticed my controllers were only showing paired in the settings and would not connect. removed the entire package and reimported it, taking the code back to before. I removed them and tried again, nothing, checked for driver updates, restarted bluetooth and computer and they finally connected but when I ran the code they were responding about 3-4 seconds behind and the rumble and joysticks were no longer registering.

I am currently charging them back up in case it is a battery level issue but was wondering if you have ever encountered lag and no joystick/rumble response? It's very confusing as it worked flawlessly last night and I have reverted the entire build back to your latest without any of my modifications.

How to Use Both Joycons (for different controls)

Hello! Sorry if this is a bit of a noob question, but I'm working on a game where one player uses the left joy-con to control a spaceship, and the other player uses the right to control the turret. I seem to be having issues connecting a second Joy-Con, and was wondering how to do so.

Support for Android Builds

Hey, first I have to say; great project, felt good to use the Joycons immediately.

However, I'm wondering if there's way I could use this on a mobile device. I have built for android and it doesn't seem to work. I don't know much about Plugins but I'm assuming this is because androids don't support the Hidapi DLL. Sorry if this is an obvious solution, but is there anyway I can use an android compatible plugin instead, and if yes, how would I go about it? Thanks.

Multiple Controller Support

Would you be interested in including other controller support for devices like traditional controllers (Xbox, PS, steam) as well as controllers like Thalmic Myo in this library? If so, I'd be willing to provide PRs to wrap functionalities in the one library (as a work around for Unity's presently difficult interface when it comes to controllers).

Just an Inquiry.

I don't intend to buy a switch. But if I just buy joy-cons from amazon, will they work with your lib.?
And how can I charge them if bought without switch?
Will I have to install any drivers or can I use them directly in unity with your lib.
And should I get grey or neon ones.

In their Nintendo Labo Demo they show IR tracking, but I didn't see IR implemented in your lib code.
Do you plan to implement IR too,

I have wiimotes and razer hydra but I am also interested in joycons . So I need your advice if I should buy joycons?

My main aim is to use them as pointers and the HD Rumble for personal projects.

Android compatibility

Hi, I would like to use this plugin for android mobile devices. I already have the project working on windows but when I transfer to android it doesn't recognize the connected joycon (I successfully connected the joycon through Bluetooth on my android device). Does this plugin work for android or is there a way to make it work for android?

hidapi not found

I'm new to unity and would love a walkthrough of how to properly set up the demo scene. I keep running into errors about the hidapi not being x64 architecture, which causes it to fail to load, which then causes a dll not found exception

Wrong orientations

I can make a work around for this, but just raising this for visibility.
It seems that the Y and Z axis are swapped.

ezgif-2-e0fee5af1ac2

Game builds instant start crash

Everything is working great but when I build the game the instant the unity logo fades it crashes and closes and after ALOT of testing I figured out it was the JoyconManager and the game only doesn't crash when the object its in and itself is disabled or deleted, but if only the manager is disabled then it still crashes.

Gimbal Lock

I'm getting gimbal lock when I rotate the Joycon is anyone else getting this?

transform.rotation = Quaternion.Lerp(transform.rotation, myJoycon.GetVector(), .15f);

hidapi.bundle errors on mac

MacOS Catalina 10.15.3
Unity 2019.3.5

Trying to run the package on the current macOSX results in this error window:
"hidapi.bundle” cannot be opened because the developer cannot be verified. macOS cannot verify that this app is free from malware.
Options are "Move to Trash" and "Cancel"
This results in a DLLNotFoundException in Unity

  • John

FormatException: Input string was not in a correct format in Unity 2018.3.0f2

" FormatException: Input string was not in a correct format.
System.Globalization.TimeSpanFormat.Format (System.TimeSpan value, System.String format, System.IFormatProvider formatProvider) (at :0)
System.TimeSpan.ToString (System.String format, System.IFormatProvider formatProvider) (at :0)
System.Text.StringBuilder.AppendFormatHelper (System.IFormatProvider provider, System.String format, System.ParamsArray args) (at :0)
System.String.FormatHelper (System.IFormatProvider provider, System.String format, System.ParamsArray args) (at :0)
System.String.Format (System.String format, System.Object[] args) (at :0)
Joycon.Update () (at Assets/JoyconLib_scripts/Joycon.cs:370)
JoyconManager.Update () (at Assets/JoyconLib_scripts/JoyconManager.cs:92) "

Test project is here, added only the latest package provided.

Switch Game.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.