@@ -190,23 +190,23 @@ static Instance& GetInstance() {
190190static void SendMatchData ();
191191
192192template <typename S, typename ... Args>
193- static inline void ReportJoystickUnpluggedError ( const S& format,
194- Args&&... args) {
195- ReportJoystickUnpluggedErrorV ( format, fmt::make_format_args (args...));
193+ static inline void ReportJoystickError ( int stick, const S& format,
194+ Args&&... args) {
195+ ReportJoystickErrorV (stick, format, fmt::make_format_args (args...));
196196}
197197
198198/* *
199- * Reports errors related to unplugged joysticks .
199+ * Reports errors related to joystick availability .
200200 *
201201 * Throttles the errors so that they don't overwhelm the DS.
202202 */
203- static void ReportJoystickUnpluggedWarningV ( fmt::string_view format,
204- fmt::format_args args);
203+ static void ReportJoystickWarningV ( int stick, fmt::string_view format,
204+ fmt::format_args args);
205205
206206template <typename S, typename ... Args>
207- static inline void ReportJoystickUnpluggedWarning ( const S& format,
208- Args&&... args) {
209- ReportJoystickUnpluggedWarningV ( format, fmt::make_format_args (args...));
207+ static inline void ReportJoystickWarning ( int stick, const S& format,
208+ Args&&... args) {
209+ ReportJoystickWarningV (stick, format, fmt::make_format_args (args...));
210210}
211211
212212Instance::Instance () {
@@ -245,11 +245,8 @@ bool DriverStation::GetStickButton(int stick, int button) {
245245 HAL_GetJoystickButtons (stick, &buttons);
246246
247247 if ((buttons.available & mask) == 0 ) {
248- ReportJoystickUnpluggedWarning (
249- " Joystick Button {} missing (available {}), check if all controllers "
250- " are "
251- " plugged in" ,
252- button, buttons.available );
248+ ReportJoystickWarning (stick, " Joystick Button {} on port {} not available" ,
249+ button, stick);
253250 return false ;
254251 }
255252
@@ -297,11 +294,8 @@ bool DriverStation::GetStickButtonPressed(int stick, int button) {
297294 uint64_t mask = 1LLU << button;
298295
299296 if ((buttons.available & mask) == 0 ) {
300- ReportJoystickUnpluggedWarning (
301- " Joystick Button {} missing (available {}), check if all controllers "
302- " are "
303- " plugged in" ,
304- button, buttons.available );
297+ ReportJoystickWarning (stick, " Joystick Button {} on port {} not available" ,
298+ button, stick);
305299 return false ;
306300 }
307301 auto & inst = ::GetInstance ();
@@ -331,11 +325,8 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) {
331325 uint64_t mask = 1LLU << button;
332326
333327 if ((buttons.available & mask) == 0 ) {
334- ReportJoystickUnpluggedWarning (
335- " Joystick Button {} missing (available {}), check if all controllers "
336- " are "
337- " plugged in" ,
338- button, buttons.available );
328+ ReportJoystickWarning (stick, " Joystick Button {} on port {} not available" ,
329+ button, stick);
339330 return false ;
340331 }
341332 auto & inst = ::GetInstance ();
@@ -364,10 +355,8 @@ double DriverStation::GetStickAxis(int stick, int axis) {
364355 HAL_GetJoystickAxes (stick, &axes);
365356
366357 if ((axes.available & mask) == 0 ) {
367- ReportJoystickUnpluggedWarning (
368- " Joystick Axis {} missing (available {}), check if all controllers are "
369- " plugged in" ,
370- axis, axes.available );
358+ ReportJoystickWarning (stick, " Joystick axis {} on port {} not available" ,
359+ axis, stick);
371360 return 0.0 ;
372361 }
373362
@@ -403,10 +392,10 @@ DriverStation::TouchpadFinger DriverStation::GetStickTouchpadFinger(
403392 }
404393 }
405394
406- ReportJoystickUnpluggedWarning (
407- " Joystick Touchpad Finger {} missing, check if all controllers are "
408- " plugged in " ,
409- touchpad);
395+ ReportJoystickWarning (
396+ stick,
397+ " Joystick touchpad finger {} on touchpad {} on port {} not available " ,
398+ finger, touchpad, stick );
410399 return TouchpadFinger{false , 0 .0f , 0 .0f };
411400}
412401
@@ -478,10 +467,8 @@ DriverStation::POVDirection DriverStation::GetStickPOV(int stick, int pov) {
478467 HAL_GetJoystickPOVs (stick, &povs);
479468
480469 if ((povs.available & mask) == 0 ) {
481- ReportJoystickUnpluggedWarning (
482- " Joystick POV {} missing (available {}), check if all controllers are "
483- " plugged in" ,
484- pov, povs.available );
470+ ReportJoystickWarning (stick, " Joystick POV {} on port {} not available" ,
471+ pov, stick);
485472 return kCenter ;
486473 }
487474
@@ -855,13 +842,21 @@ void DriverStation::StartDataLog(wpi::log::DataLog& log, bool logJoysticks) {
855842 }
856843}
857844
858- void ReportJoystickUnpluggedWarningV ( fmt::string_view format,
859- fmt::format_args args) {
845+ void ReportJoystickWarningV ( int stick, fmt::string_view format,
846+ fmt::format_args args) {
860847 auto & inst = GetInstance ();
861848 if (DriverStation::IsFMSAttached () || !inst.silenceJoystickWarning ) {
862849 auto currentTime = Timer::GetTimestamp ();
863850 if (currentTime > inst.nextMessageTime ) {
864- ReportErrorV (warn::Warning, " " , 0 , " " , format, args);
851+ if (DriverStation::IsJoystickConnected (stick)) {
852+ ReportErrorV (warn::Warning, " " , 0 , " " , format, args);
853+ } else {
854+ ReportError (
855+ warn::Warning, " " , 0 , " " ,
856+ " Joystick on port {} not available, check if all controllers are "
857+ " plugged in" ,
858+ stick);
859+ }
865860 inst.nextMessageTime = currentTime + kJoystickUnpluggedMessageInterval ;
866861 }
867862 }
0 commit comments