mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpilib,commands] Use Jinja to generate HID classes (#6274)
This commit is contained in:
92
wpilibc/src/generate/main/native/cpp/hid.cpp.jinja
Normal file
92
wpilibc/src/generate/main/native/cpp/hid.cpp.jinja
Normal file
@@ -0,0 +1,92 @@
|
||||
// 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 ./wpilibc/generate_hids.py. DO NOT MODIFY
|
||||
{% macro capitalize_first(string) -%}
|
||||
{{ string[0]|capitalize + string[1:] }}
|
||||
{%- endmacro %}
|
||||
#include "frc/{{ ConsoleName }}Controller.h"
|
||||
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
|
||||
#include "frc/event/BooleanEvent.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
{{ ConsoleName }}Controller::{{ ConsoleName }}Controller(int port) : GenericHID(port) {
|
||||
{{ "// " if SkipReporting }}HAL_Report(HALUsageReporting::kResourceType_{{ ConsoleName }}Controller, port + 1);
|
||||
}
|
||||
{% for stick in sticks %}
|
||||
double {{ ConsoleName }}Controller::Get{{ stick.NameParts|map("capitalize")|join }}() const {
|
||||
return GetRawAxis(Axis::k{{ stick.NameParts|map("capitalize")|join }});
|
||||
}
|
||||
{% endfor -%}
|
||||
{% for trigger in triggers %}
|
||||
double {{ ConsoleName }}Controller::Get{{ capitalize_first(trigger.name) }}Axis() const {
|
||||
return GetRawAxis(Axis::k{{ capitalize_first(trigger.name) }});
|
||||
}
|
||||
{% if trigger.UseThresholdMethods %}
|
||||
BooleanEvent {{ ConsoleName }}Controller::{{ capitalize_first(trigger.name) }}(double threshold, EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this, threshold] { return this->Get{{ capitalize_first(trigger.name) }}Axis() > threshold; });
|
||||
}
|
||||
|
||||
BooleanEvent {{ ConsoleName }}Controller::{{ capitalize_first(trigger.name) }}(EventLoop* loop) const {
|
||||
return this->{{ capitalize_first(trigger.name) }}(0.5, loop);
|
||||
}
|
||||
{% endif -%}
|
||||
{% endfor -%}
|
||||
{% for button in buttons %}
|
||||
bool {{ ConsoleName }}Controller::Get{{ capitalize_first(button.name) }}Button() const {
|
||||
return GetRawButton(Button::k{{ capitalize_first(button.name) }});
|
||||
}
|
||||
|
||||
bool {{ ConsoleName }}Controller::Get{{ capitalize_first(button.name) }}ButtonPressed() {
|
||||
return GetRawButtonPressed(Button::k{{ capitalize_first(button.name) }});
|
||||
}
|
||||
|
||||
bool {{ ConsoleName }}Controller::Get{{ capitalize_first(button.name) }}ButtonReleased() {
|
||||
return GetRawButtonReleased(Button::k{{ capitalize_first(button.name) }});
|
||||
}
|
||||
|
||||
BooleanEvent {{ ConsoleName }}Controller::{{ capitalize_first(button.name) }}(EventLoop* loop) const {
|
||||
return BooleanEvent(loop, [this]() { return this->Get{{ capitalize_first(button.name) }}Button(); });
|
||||
}
|
||||
{% endfor -%}
|
||||
{% if ConsoleName == "Xbox" or ConsoleName == "Stadia"%}
|
||||
bool {{ ConsoleName }}Controller::GetLeftBumper() const {
|
||||
return GetRawButton(Button::kLeftBumper);
|
||||
}
|
||||
|
||||
bool {{ ConsoleName }}Controller::GetRightBumper() const {
|
||||
return GetRawButton(Button::kRightBumper);
|
||||
}
|
||||
|
||||
bool {{ ConsoleName }}Controller::GetLeftBumperPressed() {
|
||||
return GetRawButtonPressed(Button::kLeftBumper);
|
||||
}
|
||||
|
||||
bool {{ ConsoleName }}Controller::GetRightBumperPressed() {
|
||||
return GetRawButtonPressed(Button::kRightBumper);
|
||||
}
|
||||
|
||||
bool {{ ConsoleName }}Controller::GetLeftBumperReleased() {
|
||||
return GetRawButtonReleased(Button::kLeftBumper);
|
||||
}
|
||||
|
||||
bool {{ ConsoleName }}Controller::GetRightBumperReleased() {
|
||||
return GetRawButtonReleased(Button::kRightBumper);
|
||||
}
|
||||
{% elif ConsoleName == "PS4" or ConsoleName == "PS5" %}
|
||||
bool {{ ConsoleName }}Controller::GetTouchpad() const {
|
||||
return GetRawButton(Button::kTouchpad);
|
||||
}
|
||||
|
||||
bool {{ ConsoleName }}Controller::GetTouchpadPressed() {
|
||||
return GetRawButtonPressed(Button::kTouchpad);
|
||||
}
|
||||
|
||||
bool {{ ConsoleName }}Controller::GetTouchpadReleased() {
|
||||
return GetRawButtonReleased(Button::kTouchpad);
|
||||
}
|
||||
{% endif %}
|
||||
Reference in New Issue
Block a user