Controller
The Controller class provides cross-platform methods to interact with various types of controllers such as joysticks, gamepads, and steering wheels. It supports querying and setting controller properties such as type, name, model, buttons, sticks, axes, and motors. It also allows you to check the connection status of the controller and register callbacks for button presses, releases, and connection events. The class allows for managing multiple controllers, retrieving controller details by index, and interacting with buttons, axes, and motors by name or value. It also supports the use of custom callbacks for button events and connection changes. The class includes static methods for querying and managing all connected controllers.
#include <system/TellusimController.h>
Constructors
Controller()
explicit Controller(uint32_t index)
explicit Controller(Type type, uint32_t index = Maxu32)
Methods
All controllers.
static uint32_t getNumControllers()
static uint32_t findController(const char *name)
static Controller getController(uint32_t index)
Update controllers.
static void update()
Controller type.
void setType(Type type)
Type getType() const
static const char *getTypeName(Type type)
const char *getTypeName() const
bool isUnknown() const
bool isJoystick() const
bool isGamePad() const
bool isWheel() const
Controller index.
void setIndex(uint32_t index)
uint32_t getIndex() const
Controller name.
void setName(const char *name)
String getName() const
Controller model.
void setModel(const char *model)
String getModel() const
Check controller.
bool isConnected() const
bool wasConnected() const
Connect controller.
bool connect(const char *name = nullptr)
void release()
Stick name.
void setStickName(Stick stick, const char *name)
String getStickName(Stick stick) const
Stick findStick(const char *name) const
Stick value.
void setStick(Stick stick, float32_t x, float32_t y)
float32_t getStickX(Stick stick) const
float32_t getStickY(Stick stick) const
Axis name.
void setAxisName(Axis axis, const char *name)
String getAxisName(Axis axis) const
Axis findAxis(const char *name) const
Axis value.
void setAxis(Axis axis, float32_t value)
float32_t getAxis(Axis axis) const
Button name.
void setButtonName(Button button, const char *name)
String getButtonName(Button button) const
Button findButton(const char *name) const
Button state.
void setButton(Button button, bool value)
bool getButton(Button button, bool clear = false) const
Button value.
void setButtonValue(Button button, float32_t value)
float32_t getButtonValue(Button button) const
Motor name.
void setMotorName(Motor motor, const char *name)
String getMotorName(Motor motor) const
Motor findMotor(const char *name) const
Motor state.
void setMotor(Motor motor, float32_t value)
float32_t getMotor(Motor motor) const
Button pressed callback.
void setButtonPressedCallback(const ButtonPressedCallback &func)
ButtonPressedCallback getButtonPressedCallback() const
Button released callback.
void setButtonReleasedCallback(const ButtonReleasedCallback &func)
ButtonReleasedCallback getButtonReleasedCallback() const
Connected callback.
void setConnectedCallback(const ConnectedCallback &func)
ConnectedCallback getConnectedCallback() const
Disconnected callback.
void setDisconnectedCallback(const DisconnectedCallback &func)
DisconnectedCallback getDisconnectedCallback() const
Types
using ButtonPressedCallback = Function<void(Controller controller, Button button)>
using ButtonReleasedCallback = Function<void(Controller controller, Button button)>
using ConnectedCallback = Function<void(Controller controller)>
using DisconnectedCallback = Function<void(Controller controller)>
Enums
Type
Controller types.
Name | Value |
---|---|
TypeUnknown | 0 |
TypeJoystick | 1 |
TypeGamePad | 2 |
TypeWheel | 3 |
NumTypes | 4 |
Stick
Controller sticks.
Name | Value |
---|---|
StickLeft | 0 |
StickRight | 1 |
NumSticks | 2 |
Axis
Controller axes.
Name | Value |
---|---|
AxisX | 0 |
AxisY | 1 |
AxisZ | 2 |
AxisRX | 3 |
AxisRY | 4 |
AxisRZ | 5 |
NumAxes | 16 |
Button
Controller buttons.
Name | Value |
---|---|
ButtonLeft | 0 |
ButtonRight | 1 |
ButtonDown | 2 |
ButtonUp | 3 |
ButtonHome | 4 |
ButtonShoulderLeft | 5 |
ButtonShoulderRight | 6 |
ButtonTriggerLeft | 7 |
ButtonTriggerRight | 8 |
ButtonStickLeft | 9 |
ButtonStickRight | 10 |
ButtonA | 11 |
ButtonB | 12 |
ButtonX | 13 |
ButtonY | 14 |
ButtonView | 15 |
ButtonMenu | 16 |
ButtonL1 | ButtonShoulderLeft |
ButtonR1 | 6 |
ButtonL2 | 7 |
ButtonR2 | 8 |
ButtonL3 | 9 |
ButtonR3 | 10 |
ButtonCross | 11 |
ButtonCircle | 12 |
ButtonSquare | 13 |
ButtonTriangle | 14 |
ButtonShare | 15 |
ButtonOptions | 16 |
NumButtons | 32 |
Motor
Controller motors.
Name | Value |
---|---|
MotorLow | 0 |
MotorHigh | 1 |
NumMotors | 2 |
Variables
Type | Name | Description |
---|---|---|
static const char* | NameXbox | Controller names. |
static const char* | NamePlayStation | |
static const char* | NameNintendo |