Skip to content

Commit

Permalink
Cache and directly construct Triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold856 committed Jun 22, 2024
1 parent 74806e7 commit f2e8cf1
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
* to the given loop.
*/
public Trigger {{ button.name }}(EventLoop loop) {
return m_hid.{{ button.name }}(loop).castTo(Trigger::new);
return button({{ ConsoleName }}Controller.Button.k{{ capitalize_first(button.name) }}.value, loop);
}
{% endfor -%}
{% for trigger in triggers -%}
Expand All @@ -76,7 +76,7 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
* threshold, attached to the given event loop
*/
public Trigger {{ trigger.name }}(double threshold, EventLoop loop) {
return m_hid.{{ trigger.name }}(threshold, loop).castTo(Trigger::new);
return axisGreaterThan({{ ConsoleName }}Controller.Axis.k{{ capitalize_first(trigger.name) }}.value, threshold, loop);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ frc::{{ ConsoleName }}Controller& Command{{ ConsoleName }}Controller::GetHID() {
}
{% for button in buttons %}
Trigger Command{{ ConsoleName }}Controller::{{ capitalize_first(button.name) }}(frc::EventLoop* loop) const {
return m_hid.{{ capitalize_first(button.name) }}(loop).CastTo<Trigger>();
return Button(frc::{{ ConsoleName }}Controller::Button::k{{ capitalize_first(button.name) }}, loop);
}
{% endfor -%}
{% for trigger in triggers -%}
{% if trigger.UseThresholdMethods %}
Trigger Command{{ ConsoleName }}Controller::{{ capitalize_first(trigger.name) }}(double threshold,
frc::EventLoop* loop) const {
return m_hid.{{ capitalize_first(trigger.name) }}(threshold, loop).CastTo<Trigger>();
return Trigger(loop, [this, threshold] {
return m_hid.Get{{ capitalize_first(trigger.name) }}Axis() > threshold;
});
}
{% endif -%}
{% endfor -%}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f2e8cf1

Please sign in to comment.