// 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 "wpi/driverstation/{{ ConsoleName }}Controller.hpp"

#include "wpi/hal/UsageReporting.hpp"
#include "wpi/util/sendable/SendableBuilder.hpp"

#include "wpi/event/BooleanEvent.hpp"

using namespace wpi;

{{ ConsoleName }}Controller::{{ ConsoleName }}Controller(int port) : GenericHID(port) {
  HAL_ReportUsage("HID", port, "{{ ConsoleName }}Controller");
}
{% 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 %}
void {{ ConsoleName }}Controller::InitSendable(wpi::util::SendableBuilder& builder) {
  builder.SetSmartDashboardType("HID");
  builder.PublishConstString("ControllerType", "{{ ConsoleName }}");
{%- for trigger in triggers %}
  builder.AddDoubleProperty("{{ capitalize_first(trigger.name) }} Axis", [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 %}
}
