wpilibsuite / allwpilib

Official Repository of WPILibJ and WPILibC
https://wpilib.org/
Other
1.06k stars 614 forks source link

[C++ cmd] Make CommandGenericHID as a public base class of CommandXboxController #6658

Closed KangarooKoala closed 4 months ago

KangarooKoala commented 4 months ago

6296 accidentally omitted the public specifier on CommandGenericHID in the base class section of CommandXboxController. Since CommandXboxController is declared using class, the default access for base classes is private, which prevents users outside the class from using methods declared in CommandGenericHID, which was the point of the PR.

I checked and the other files touched by that PR do not have the issue. I also confirmed locally that using methods declared in CommandGenericHID (such as Button(int)) on a CommandXboxController works with the following diff:

diff --git a/developerRobot/src/main/native/cpp/Robot.cpp b/developerRobot/src/main/native/cpp/Robot.cpp
index 238697d42..9f6075dae 100644
--- a/developerRobot/src/main/native/cpp/Robot.cpp
+++ b/developerRobot/src/main/native/cpp/Robot.cpp
@@ -3,13 +3,14 @@
 // the WPILib BSD license file in the root directory of this project.

 #include <frc/TimedRobot.h>
+#include <frc2/command/button/CommandXboxController.h>

 class Robot : public frc::TimedRobot {
   /**
    * This function is run when the robot is first started up and should be
    * used for any initialization code.
    */
-  void RobotInit() override {}
+  void RobotInit() override { m_controller.Button(0); }

   /**
    * This function is run once each time the robot enters autonomous mode
@@ -40,6 +41,9 @@ class Robot : public frc::TimedRobot {
    * This function is called periodically during all modes
    */
   void RobotPeriodic() override {}
+
+ private:
+  frc2::CommandXboxController m_controller{0};
 };

 int main() {
KangarooKoala commented 4 months ago

This does not require a corresponding Python PR because the Python version is already correct- Classes inherit from CommandGenericHID and there is no private subclassing to worry about.