[wpilib] Implement Sendable for HID classes (#6782)

This commit is contained in:
Jade
2024-07-18 22:10:07 +08:00
committed by GitHub
parent 34b8b7a409
commit 7663211819
15 changed files with 287 additions and 14 deletions

View File

@@ -9,6 +9,7 @@
#include "frc/{{ ConsoleName }}Controller.h"
#include <hal/FRCUsageReporting.h>
#include <wpi/sendable/SendableBuilder.h>
#include "frc/event/BooleanEvent.h"
@@ -77,7 +78,7 @@ bool {{ ConsoleName }}Controller::GetLeftBumperReleased() {
bool {{ ConsoleName }}Controller::GetRightBumperReleased() {
return GetRawButtonReleased(Button::kRightBumper);
}
{% elif ConsoleName == "PS4" or ConsoleName == "PS5" %}
{%- elif ConsoleName == "PS4" or ConsoleName == "PS5" %}
bool {{ ConsoleName }}Controller::GetTouchpad() const {
return GetRawButton(Button::kTouchpad);
}
@@ -89,4 +90,18 @@ bool {{ ConsoleName }}Controller::GetTouchpadPressed() {
bool {{ ConsoleName }}Controller::GetTouchpadReleased() {
return GetRawButtonReleased(Button::kTouchpad);
}
{% endif %}
{%- endif %}
void {{ ConsoleName }}Controller::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("HID");
builder.PublishConstString("ControllerType", "{{ ConsoleName }}");
{%- for trigger in triggers %}
builder.AddDoubleProperty("{{ capitalize_first(trigger.name) }}", [this] { return Get{{ capitalize_first(trigger.name) }}Axis(); }, nullptr);
{%- endfor -%}
{% for stick in sticks %}
builder.AddDoubleProperty("{{ stick.NameParts|map("capitalize")|join }}", [this] { return Get{{ stick.NameParts|map("capitalize")|join }}(); }, nullptr);
{%- endfor -%}
{% for button in buttons %}
builder.AddBooleanProperty("{{ capitalize_first(button.name) }}", [this] { return Get{{ capitalize_first(button.name) }}Button(); }, nullptr);
{%- endfor %}
}

View File

@@ -8,6 +8,9 @@
{%- endmacro %}
#pragma once
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/GenericHID.h"
namespace frc {
@@ -24,7 +27,9 @@ namespace frc {
* correct mapping, and only through the official NI DS. Sim is not guaranteed
* to have the same mapping, as well as any 3rd party controllers.
*/
class {{ ConsoleName }}Controller : public GenericHID {
class {{ ConsoleName }}Controller : public GenericHID,
public wpi::Sendable,
public wpi::SendableHelper<{{ ConsoleName }}Controller> {
public:
/**
* Construct an instance of a controller.
@@ -203,6 +208,8 @@ class {{ ConsoleName }}Controller : public GenericHID {
static constexpr int k{{ capitalize_first(trigger.name) }} = {{ trigger.value }};
{%- endfor %}
};
void InitSendable(wpi::SendableBuilder& builder) override;
};
} // namespace frc