Yamakaky / joy

Library and tools for working with Nintendo Switch JoyCon/Pro Controller
MIT License
27 stars 6 forks source link

Windows compatible? #13

Closed cooperate closed 2 years ago

cooperate commented 2 years ago

Is it possible to get this running on windows, if so - how?

Also - I seen in a post that this has the ability to read the squeeze values from the ringcon.

FYI, I just managed to reverse engineer how the ringcon sweeze work. I have a working tool, available here: https://github.com/Yamakaky/joy. I have to do some doc, but for now you can connect the joycon via bluetooth and run cargo run --bin joytk ringcon, which will show the squeeze value. It doesn't require any additional hardware. If you want, we can work on integrating this to your mod.

Is it possible to map this value to an xinput device through say an analog stick value?

Yamakaky commented 2 years ago

IIRC it should work on Windows, though there is no binaries so you will have to compile it. You will need https://rustup.rs/ for that, then cargo run --bin joytk in the terminal.

As for the protocol, you can find the high level overview there https://github.com/Yamakaky/joy/blob/master/crates/joycon/src/hid.rs#L485. The squeeze value is here, https://github.com/Yamakaky/joy/blob/master/crates/joycon-sys/src/imu.rs#L25, in place of the second component of the accelerometer when ringcon mode is enabled. Usage: https://github.com/Yamakaky/joy/blob/master/joytk/src/main.rs#L497.

cooperate commented 2 years ago

Thanks @Yamakaky I was able to build it but now I'm getting this error when running joytk.exe -w monitor (this is with only the right joycon although I tried with the left only and both at once and received the same result)

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `362`,
 right: `49`', crates\joycon\src\hid.rs:94:9
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\panicking.rs:498
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\core\src\panicking.rs:116
   2: core::fmt::Arguments::new_v1
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\core\src\fmt\mod.rs:365
   3: core::panicking::assert_failed_inner
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\core\src\panicking.rs:197
   4: core::panicking::assert_failed<usize,usize>
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\core\src\panicking.rs:154
   5: joycon::hid::JoyCon::recv
             at E:\App_Dev\joy\crates\joycon\src\hid.rs:94
   6: joycon::hid::impl$0::call_subcmd_wait::closure$0<joycon_sys::output::report::SubcommandRequest>
             at E:\App_Dev\joy\crates\joycon\src\hid.rs:202
   7: joycon::hid::JoyCon::call_subcmd_wait<joycon_sys::output::report::SubcommandRequest>
             at E:\App_Dev\joy\crates\joycon\src\hid.rs:196
   8: joycon::hid::impl$0::new::closure$0
             at E:\App_Dev\joy\crates\joycon\src\hid.rs:70
   9: joycon::hid::JoyCon::new
             at E:\App_Dev\joy\crates\joycon\src\hid.rs:44
  10: joytk::main
             at E:\App_Dev\joy\joytk\src\main.rs:84
  11: core::ops::function::FnOnce::call_once<enum$<core::result::Result<tuple$<>,anyhow::Error>, 1, 18446744073709551615, Err> (*)(),tuple$<> >
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\core\src\ops\function.rs:227
Yamakaky commented 2 years ago

hum, it seems you always read the max report length instead of just what is needed. Can you replace the assert_eq with assert_ge?

cooperate commented 2 years ago

hum, it seems you always read the max report length instead of just what is needed. Can you replace the assert_eq with assert_ge?

Replacing that line with assert_ne!(nb_read, report.len()); did the trick!