I have a program that is able to change the port of the controller object, and then will update all of the subsequent buttons inside of it. The problem is that the button bindings will not update when the controller/buttons are updated. SmartMap just returns button Ids.
I have tried calling configureButtonBinding multiple times, and that causes the controller to run the button bindings multiple times if the controller has not changed ports.
(In ControllerTracking class, called whenever teleop init because changing port numbers disables anyways)
public static void updatePortNumbers() {
JoystickTypes = new HIDType[5];
GenericHID testHID;
for (int i = 0; i < JoystickTypes.length; i++) {
testHID = new GenericHID(i);
if (testHID.isConnected()) {
JoystickTypes[i] = testHID.getType();
}
}
dynamicControllerXbox1.object = new XboxController(indexOf(JoystickTypes, HIDType.kXInputGamepad));
dynamicControllerXbox1.updateController();
}
(In robot container)
public static class dynamicControllerXbox1 {
public static XboxController object = new XboxController(5);
public static JoystickButton A;
public static JoystickButton B;
public static JoystickButton X;
public static JoystickButton Y;
public static JoystickButton LeftBumper;
public static JoystickButton RightBumper;
public static JoystickButton LeftStickPress;
public static JoystickButton RightStickPress;
public static JoystickButton Share;
public static JoystickButton Options;
public static void updateController() {
ControllerTracking.updatePortNumbers();
System.out.println("Assigning dXbox: " + object.getPort());
A = new JoystickButton(object, OIConstants.SmartMap(object, “A”));
B = new JoystickButton(object, OIConstants.SmartMap(object, “B”));
X = new JoystickButton(object, OIConstants.SmartMap(object, “X”));
Y = new JoystickButton(object, OIConstants.SmartMap(object, “Y”));
LeftBumper = new JoystickButton(object, OIConstants.SmartMap(object, “LBump”));
RightBumper = new JoystickButton(object, OIConstants.SmartMap(object, “RBump”));
LeftStickPress = new JoystickButton(object, OIConstants.SmartMap(object, “LStick”));
RightStickPress = new JoystickButton(object, OIConstants.SmartMap(object, “RStick”));
Share = new JoystickButton(object, OIConstants.SmartMap(object, “DoubleSquare”));
Options = new JoystickButton(object, OIConstants.SmartMap(object, “Options”));
}
}
private void configureButtonBindings() {
dynamicControllerXbox1.A.whileActiveContinuous(()-> System.out.println(dynamicControllerXbox1.object.getPort() + “: dynamic XBOX”));
}