-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Jinja to generate C++ HID classes
- Loading branch information
Showing
47 changed files
with
2,389 additions
and
1,091 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
wpilibNewCommands/src/generate/main/native/cpp/frc2/command/button/commandhid.cpp.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY | ||
|
||
#include "frc2/command/button/Command{{ ConsoleName }}Controller.h" | ||
|
||
using namespace frc2; | ||
|
||
Trigger Command{{ ConsoleName }}Controller::Button(int button, frc::EventLoop* loop) const { | ||
return GenericHID::Button(button, loop).CastTo<Trigger>(); | ||
} | ||
{% for button in buttons %} | ||
Trigger Command{{ ConsoleName }}Controller::{{ button.NameParts|map("capitalize")|join }}(frc::EventLoop* loop) const { | ||
return {{ ConsoleName }}Controller::{{ button.NameParts|map("capitalize")|join }}(loop).CastTo<Trigger>(); | ||
} | ||
{% endfor -%} | ||
{% for trigger in axes if trigger.type == "trigger" -%} | ||
{% if trigger.UseThresholdMethods %} | ||
Trigger Command{{ ConsoleName }}Controller::{{ trigger.HumanName }}(double threshold, | ||
frc::EventLoop* loop) const { | ||
return {{ ConsoleName }}Controller::{{ trigger.HumanName }}(threshold, loop).CastTo<Trigger>(); | ||
} | ||
{% endif -%} | ||
{% endfor -%} |
69 changes: 69 additions & 0 deletions
69
wpilibNewCommands/src/generate/main/native/include/frc2/command/button/commandhid.h.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
// THIS FILE WAS AUTO-GENERATED BY ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY | ||
|
||
#pragma once | ||
#include <frc/{{ ConsoleName }}Controller.h> | ||
|
||
#include "frc2/command/CommandScheduler.h" | ||
#include "frc2/command/button/Trigger.h" | ||
|
||
namespace frc2 { | ||
/** | ||
* A version of {@link {{ ConsoleName }}Controller} with {@link Trigger} factories for | ||
* command-based. | ||
* | ||
* @see {{ ConsoleName }}Controller | ||
*/ | ||
class Command{{ ConsoleName }}Controller : public frc::{{ ConsoleName }}Controller { | ||
public: | ||
using {{ ConsoleName }}Controller::{{ ConsoleName }}Controller; | ||
|
||
/** | ||
* Constructs an event instance around this button's digital signal. | ||
* | ||
* @param button the button index | ||
* @param loop the event loop instance to attach the event to. Defaults to the | ||
* CommandScheduler's default loop. | ||
* @return an event instance representing the button's digital signal attached | ||
* to the given loop. | ||
*/ | ||
Trigger Button(int button, | ||
frc::EventLoop* loop = CommandScheduler::GetInstance() | ||
.GetDefaultButtonLoop()) const; | ||
{% for button in buttons %} | ||
/** | ||
* Constructs an event instance around the {{ button.DocName|default(button.NameParts|map("lower")|join(" ")) }}'s digital signal. | ||
* | ||
* @param loop the event loop instance to attach the event to. Defaults to the | ||
* CommandScheduler's default loop. | ||
* @return an event instance representing the {{ button.DocName|default(button.NameParts|map("lower")|join(" ")) }}'s digital signal | ||
* attached to the given loop. | ||
*/ | ||
Trigger {{ button.NameParts|map("capitalize")|join }}(frc::EventLoop* loop = CommandScheduler::GetInstance() | ||
.GetDefaultButtonLoop()) const; | ||
{% endfor -%} | ||
{% for trigger in axes if trigger.type == "trigger" -%} | ||
{% if trigger.UseThresholdMethods %} | ||
/** | ||
* Constructs a Trigger instance around the axis value of the {{ trigger.DocName }}. | ||
* The returned Trigger will be true when the axis value is greater than | ||
* {@code threshold}. | ||
* | ||
* @param threshold the minimum axis value for the returned Trigger to be | ||
* true. This value should be in the range [0, 1] where 0 is the unpressed | ||
* state of the axis. Defaults to 0.5. | ||
* @param loop the event loop instance to attach the Trigger to. Defaults to | ||
* the CommandScheduler's default loop. | ||
* @return a Trigger instance that is true when the {{ trigger.DocName }}'s axis | ||
* exceeds the provided threshold, attached to the given loop | ||
*/ | ||
Trigger {{ trigger.HumanName }}(double threshold = 0.5, | ||
frc::EventLoop* loop = CommandScheduler::GetInstance() | ||
.GetDefaultButtonLoop()) const; | ||
{% endif -%} | ||
{% endfor -%} | ||
}; | ||
} // namespace frc2 |
6 changes: 6 additions & 0 deletions
6
...2/command/button/CommandPS4Controller.cpp → ...2/command/button/CommandPS4Controller.cpp
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
...2/command/button/CommandPS5Controller.cpp → ...2/command/button/CommandPS5Controller.cpp
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
53 changes: 27 additions & 26 deletions
53
...ommand/button/CommandStadiaController.cpp → ...ommand/button/CommandStadiaController.cpp
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
36 changes: 19 additions & 17 deletions
36
.../command/button/CommandXboxController.cpp → .../command/button/CommandXboxController.cpp
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.