Hacking Joytime - a library for writing programs that use the Switch's controllers

  • Thread starter Thread starter facekapow
  • Start date Start date
  • Views Views 2,471
  • Replies Replies 9
  • Likes Likes 6

facekapow

New Member
Newbie
Joined
Oct 12, 2017
Messages
4
Reaction score
8
Trophies
0
Age
24
XP
86
Country
United States
Hey everyone, I wrote a library (similar to @wormyrocks's library but more general purpose) for using the Switch's controllers with PCs (or any other platform it compiles on). It's written in C++ but also has a C wrapper available for C clients.

It's currently undocumented (I'm going to get on that as soon as possible), but if anyone would like to look through some headers and maybe try it out, feedback would be great. Also, if anyone is on macOS or Linux could see if it'll compile (it should, but I'd like to make sure). There's also a demo program at switch-joytime/joytime-demo on GitHub which should (if it works on your computer) output a bunch of data (stick updates) and set the first LED solid on all controllers.

I've only tested it with JoyCons, but it should also work with Pro Controllers (it'd be great if someone could test that).

By the way, I'm hoping to be able to write a driver for the JoyCons for OpenVR (we all know they'd be great for VR).

It's at switch-joytime/joytime-core on GitHub.

(I can't post links cause I'm a newbie)
 
Try it now (I replaced `std::exception` with `std::runtime_error`, since `exception`s with error messages are an MSVC extension). Should work this time (with a bunch of warnings still).
 
  • Like
Reactions: facekapow
Ok seems you wrote your own Clamp function in Rumble.cpp while there is std::clamp :
http://en.cppreference.com/w/cpp/algorithm/clamp
And you are checking for odd or even numbers using modulo's which is slow.. if the compiler doesn't fix this for you already you can use "number & 1" instead which works the same basically but lots faster.

Other than that.. using names that start with an underscore ( _ ) is discouraged:
https://stackoverflow.com/questions...s-about-using-an-underscore-in-a-c-identifier
if it's a global I'd recommend using g_ as prefix or as member variable m_ , this is the safest option to go and also more clear in readability.

And maybe using a different function for passing c-style arrays instead of std::vectors is a bit much, why not have it as a overload?, same function name, different arguments.

Though that's all just being nitpicky, in general the code seems fine.

edit-
The warnings that "ihaveamac" gets are personally totally ignorable for me, unless you are writing some complicated algorithm it really doesn't need paranthesis over simple equations just to indicated certain operations go first.. such as number & 0x80 - 1
it's a simple case of programmer pemdas, first bitwise, then multiplication/divide then add/substract.
 
Last edited by themperror,
  • Like
Reactions: facekapow

Site & Scene News

Popular threads in this forum