Skip to content

Commit

Permalink
Add POV Button
Browse files Browse the repository at this point in the history
Fixes #530
  • Loading branch information
sciencewhiz committed Jul 20, 2023
1 parent a238fb8 commit 0e3c372
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
22 changes: 20 additions & 2 deletions src/main/resources/PaletteDescription.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ Palette:
- !Component
name: Joystick
type: Joystick
supports: {Joystick Button: -1}
supports: {Joystick Button: -1, POV Button: -1}
help: A joystick that drivers can use as input.
properties:
- !ChoicesProperty
Expand Down Expand Up @@ -812,7 +812,25 @@ Palette:
- !BooleanProperty
name: Send to SmartDashboard
default: false

- !Component
name: POV Button
type: POV Button
help: A POV button that binds a driver action to a command.
properties:
- !ParentProperty
name: Joystick
- !ChoicesProperty
name: POVNumber
choices: ["0", "1", "2", "3", "4", "5"]
default: 0
- !ChoicesProperty
name: Angle
choices: ["0", "45", "90", "135", "180", "225", "270", "315"]
default: "0"
#Button("")
- !BooleanProperty
name: Send to SmartDashboard
default: false
- Commands:
- !Component
name: Command
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/export/cpp/ExportDescription.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ Instructions:
ClassName: "JoystickButton"
Construction: "frc2::${ClassName} #variable($Name){&#variable($Joystick), (int)frc::PS4Controller::Button::k${Button}};"
Import: "\\#include <frc2/command/button/${ClassName}.h>"
POV Button:
Defaults: "Button,OI,None"
ClassName: "POVButton"
Construction: "frc2::${ClassName} #variable($Name){&#variable($Joystick), ${Angle}, ${POVNumber}};"
Import: "\\#include <frc2/command/button/${ClassName}.h>"

Command:
Defaults: "Command,None"
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/export/cpp/RobotContainer-buttons.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#foreach( $component in $components )
#if ($helper.exportsTo("OI", $component) && ("#type($component)" == "JoystickButton") && ("#constructor($component)" != "" || "#extra($component)" != ""))
#if ($helper.exportsTo("OI", $component) && (("#type($component)" == "JoystickButton") || ("#type($component)" == "POVButton")) && ("#constructor($component)" != "" || "#extra($component)" != ""))
#foreach ($command in $commands)
#if($command.name == $component.getProperty("Command").value)
#constructor($component)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##${Collections.reverse($components)}
#foreach( $component in $components )
#if ($helper.exportsTo("OI", $component)
&& ("#constructor($component)" != "" || "#extra($component)" != "") && "#base_type($component)" != "Joystick" && "#type($component)" != "JoystickButton")
&& ("#constructor($component)" != "" || "#extra($component)" != "") && "#base_type($component)" != "Joystick" && "#type($component)" != "JoystickButton" && "#type($component)" != "POVButton")
#constructor($component)
#extra($component)
#end
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/export/java/ExportDescription.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Defaults:
Import: "import edu.wpi.first.wpilibj.${ClassName};\nimport ${package}.subsystems.*;"
Declaration: "public ${ClassName} #variable($Name);"
Button:
Import: "import edu.wpi.first.wpilibj2.command.button.JoystickButton;"
Import: "import edu.wpi.first.wpilibj2.command.button.${ClassName};"
Extra: "#if(\"$Command\" != \"None\")#variable($Name).${When_to_Run}(#new_command_instantiation_nt(${Command} ${Parameters}));#end"
Command:
Export: ""
Expand Down Expand Up @@ -349,6 +349,10 @@ Instructions:
Defaults: "Button,OI,None"
ClassName: "JoystickButton"
Construction: "final ${ClassName} #variable($Name) = new ${ClassName}(#variable($Joystick), PS4Controller.Button.k${Button}.value);"
POV Button:
Defaults: "Button,OI,None"
ClassName: "POVButton"
Construction: "final ${ClassName} #variable($Name) = new ${ClassName}(#variable($Joystick), ${Angle}, ${POVNumber});"

Command:
Defaults: "Command,None"
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/robotbuilder/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ public static RobotTree generateTestTree() {
leftstick.add(armUpButton);
RobotComponent autoButton = new RobotComponent("Autonomous Button", "Joystick Button", tree);
rightstick.add(autoButton);
RobotComponent povButton = new RobotComponent("POVButton", "POV Button", tree);
rightstick.add(povButton);
autoButton.getProperty("When to Run").setValueAndUpdate("onTrue");
RobotComponent xbox = new RobotComponent("Xbox", "Xbox Controller", tree);
oi.add(xbox);
Expand Down Expand Up @@ -233,6 +235,7 @@ public static RobotTree generateTestTree() {
autoButton.getProperty("Command").setValueAndUpdate("Autonomous");
xboxButton.getProperty("Command").setValueAndUpdate("Instant Command 1");
ps4Button.getProperty("Command").setValueAndUpdate("Instant Command 2");
povButton.getProperty("Command").setValueAndUpdate("Instant Command 2");

return tree;
}
Expand Down

0 comments on commit 0e3c372

Please sign in to comment.