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

facekapow

New Member
OP
Newbie
Joined
Oct 12, 2017
Messages
4
Trophies
0
Age
21
XP
56
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)
 

facekapow

New Member
OP
Newbie
Joined
Oct 12, 2017
Messages
4
Trophies
0
Age
21
XP
56
Country
United States
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).
 

ihaveahax

Well-Known Member
Member
Joined
Apr 20, 2015
Messages
6,070
Trophies
2
XP
7,860
Country
United States
  • Like
Reactions: facekapow

themperror

Well-Known Member
Member
Joined
Aug 12, 2009
Messages
181
Trophies
0
XP
367
Country
Netherlands
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

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: Yeah but I'd tie him up in the females bathroom