Skip to main content

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.

NameValue
TypeUnknown0
TypeJoystick1
TypeGamePad2
TypeWheel3
NumTypes4

Stick

Controller sticks.

NameValue
StickLeft0
StickRight1
NumSticks2

Axis

Controller axes.

NameValue
AxisX0
AxisY1
AxisZ2
AxisRX3
AxisRY4
AxisRZ5
NumAxes16

Button

Controller buttons.

NameValue
ButtonLeft0
ButtonRight1
ButtonDown2
ButtonUp3
ButtonHome4
ButtonShoulderLeft5
ButtonShoulderRight6
ButtonTriggerLeft7
ButtonTriggerRight8
ButtonStickLeft9
ButtonStickRight10
ButtonA11
ButtonB12
ButtonX13
ButtonY14
ButtonView15
ButtonMenu16
ButtonL1ButtonShoulderLeft
ButtonR16
ButtonL27
ButtonR28
ButtonL39
ButtonR310
ButtonCross11
ButtonCircle12
ButtonSquare13
ButtonTriangle14
ButtonShare15
ButtonOptions16
NumButtons32

Motor

Controller motors.

NameValue
MotorLow0
MotorHigh1
NumMotors2

Variables

TypeNameDescription
static const char*NameXboxController names.
static const char*NamePlayStation
static const char*NameNintendo