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
  • cearp @ cearp:
    Even sugar free isn't good, as the acid is bad enough.
  • cearp @ cearp:
    oh earlier than 15 Ken, babies, children can get decay
  • K3Nv2 @ K3Nv2:
    So dentists give. Us these caps that'll last a few years to fight thrm
  • K3Nv2 @ K3Nv2:
    Yeah but babies get a new set
  • K3Nv2 @ K3Nv2:
    Screw godfor not giving us a new adult set after we mess up
    +2
  • cearp @ cearp:
    "You listening up there big guy?"
  • BigOnYa @ BigOnYa:
    Just smoke meth, all your dental problems will go away.
    +2
  • K3Nv2 @ K3Nv2:
    Even steven
  • cearp @ cearp:
    I wonder why edibles haven't caught on for meth
  • K3Nv2 @ K3Nv2:
    Locked down from government to dispensary
  • BigOnYa @ BigOnYa:
    In India it has, can't remember what its called yuka I think, they have a crisis like we have with fentanal
  • K3Nv2 @ K3Nv2:
    That's why we need regulation :teach:
  • SylverReZ @ SylverReZ:
    @BigOnYa, Speak to Psi, he'll offer you some in Tempycoin. :tpi:
    +1
  • OGSniper @ OGSniper:
    Day after day, we drink beer, Night after night my heartbeat shows the fear
    +1
  • K3Nv2 @ K3Nv2:
    Beer can be bad for your teeth
  • OGSniper @ OGSniper:
    Teeth? What Teeth?
  • SylverReZ @ SylverReZ:
    @K3Nv2, Do crack instead. Beer is more of a depressant.
  • OGSniper @ OGSniper:
    I like taking trips without even leaving my house, if ya know what I mean.
  • K3Nv2 @ K3Nv2:
    My hygienist name is Jose I'm like fuck Juan found me
    +2
  • BigOnYa @ BigOnYa:
    Did he ask to see yo feet?
  • K3Nv2 @ K3Nv2:
    Teeth
  • K3Nv2 @ K3Nv2:
    Juan's second cousin obsessed with teeth
    +1
  • BigOnYa @ BigOnYa:
    Did you wake up with your belt un-buckled?
  • K3Nv2 @ K3Nv2:
    Let me lift you up in my chair
    K3Nv2 @ K3Nv2: Let me lift you up in my chair