7#include "RaidZeroLib/api/Runtime/Component.hpp"
8#include "RaidZeroLib/api/Runtime/Task.hpp"
21 enum class Stick : std::uint8_t { LeftX, LeftY, RightX, RightY };
22 enum class Button : std::uint8_t { L1, L2, R1, R2, Up, Down, Left, Right, X, B, Y, A };
31 [[nodiscard]]
bool held(
Button button)
const {
return current.buttons[
static_cast<std::size_t
>(button)]; }
35 const auto index =
static_cast<std::size_t
>(button);
36 return current.buttons[index] && !previous.buttons[index];
39 [[nodiscard]]
bool connected()
const {
return current.connected; }
48 std::array<double, STICK_COUNT>
sticks{};
std::string_view name() const noexcept
Used in log and error messages.
Definition Component.hpp:30
Component(const Component &)=delete
bool held(Button button) const
Whether the button is down.
Definition Controller.hpp:31
Task nextPress(Button button)
Waits for the next press of button, in a later tick than this one. Checked at estimatorsUpdated.
double stick(Stick stick) const
How far the stick is pushed, from -1 to 1. Right and up are positive.
Definition Controller.hpp:28
virtual State read()=0
Reads the controller now. Sticks from -1 to 1.
Button
Definition Controller.hpp:22
Stick
Definition Controller.hpp:21
bool connected() const
Definition Controller.hpp:39
static constexpr std::size_t BUTTON_COUNT
Definition Controller.hpp:25
bool pressed(Button button) const
Whether the button went down this tick.
Definition Controller.hpp:34
static constexpr std::size_t STICK_COUNT
Definition Controller.hpp:24
Controller(std::string_view name)
Definition Controller.hpp:52
corral::Task< T > Task
Lazy: nothing runs until it is co_awaited.
Definition Task.hpp:17
Definition DriverControl.hpp:11
Everything read from the controller in one tick.
Definition Controller.hpp:46
bool connected
Definition Controller.hpp:47
std::array< bool, BUTTON_COUNT > buttons
Definition Controller.hpp:49
std::array< double, STICK_COUNT > sticks
Definition Controller.hpp:48