C/C++ Joystick class not returning proper values

So my team is attempting to be able to plug in either a flight stick or a xbox controller to our driver station and have the robot determine which control scheme to use.

We have done this in the past using the Joystick class’s GetName() and GetType() functions. The problem is, no matter how we call them, this year, GetName() always returns an empty string, and GetType() always returns an integer value of 255, even though the only values in the enum range from -1 to 24.

Is anyone else having similar issues, or is it simply our install of WPILib?

soooo, TIL that these methods cant be called in the constructor :expressionless:

Problem solved by moving the calls to the beginning of teleop…

Ah. Yes these would not have valid data until a DS connection actually occurs. During a constructor, the DS most likely has not sent a packet, so it has no data to actually receive. Waiting until teleop will definitely work. Note doing the setup in disabled would work as well.

That makes sense. I feel like the default return value shouldn’t be out of scope on the GetType() tho. especially when theres a -1 kUnknown value that would make a whole lot more sense.

Doing this during disabled makes a heck of a lot more sense anyways. I didn’t think of this. Thanks!

This is why wpilib recommends you use robotInit() for your initialization code, and not the constructor.

I have a few ideas I could do to make this work. Might even be able to make it work in the constructor too. But for your use case disabled works better anyway, since you could reconfigure during testing without a code reboot.