okapi::Controller class

Constructors, destructors, conversion operators

Controller(ControllerId iid = ControllerId::master)
~Controller() virtual

Public functions

auto isConnected() -> bool virtual
Returns whether the controller is connected.
auto getAnalog(ControllerAnalog ichannel) -> float virtual
Returns the current analog reading for the channel in the range [-1, 1].
auto getDigital(ControllerDigital ibutton) -> bool virtual
Returns whether the digital button is currently pressed.
auto operator[](ControllerDigital ibtn) -> ControllerButton& virtual
Returns a ControllerButton for the given button on this controller.
auto setText(std::uint8_t iline, std::uint8_t icol, std::string itext) -> std::int32_t virtual
Sets text to the controller LCD screen.
auto clear() -> std::int32_t virtual
Clears all of the lines of the controller screen.
auto clearLine(std::uint8_t iline) -> std::int32_t virtual
Clears an individual line of the controller screen.
auto rumble(std::string irumblePattern) -> std::int32_t virtual
Rumble the controller.
auto getBatteryCapacity() -> std::int32_t virtual
Gets the battery capacity of the given controller.
auto getBatteryLevel() -> std::int32_t virtual
Gets the battery level of the given controller.

Protected variables

ControllerId okapiId
pros::controller_id_e_t prosId
std::array<ControllerButton*, 12> buttonArray

Function documentation

bool okapi::Controller::isConnected() virtual

Returns whether the controller is connected.

Returns true if the controller is connected

float okapi::Controller::getAnalog(ControllerAnalog ichannel) virtual

Returns the current analog reading for the channel in the range [-1, 1].

Parameters
ichannel the channel to read
Returns the value of that channel in the range [-1, 1]

Returns 0 if the controller is not connected.

bool okapi::Controller::getDigital(ControllerDigital ibutton) virtual

Returns whether the digital button is currently pressed.

Parameters
ibutton the button to check
Returns true if the button is pressed, false if the controller is not connected

Returns false if the controller is not connected.

ControllerButton& okapi::Controller::operator[](ControllerDigital ibtn) virtual

Returns a ControllerButton for the given button on this controller.

Parameters
ibtn the button
Returns a ControllerButton on this controller

std::int32_t okapi::Controller::setText(std::uint8_t iline, std::uint8_t icol, std::string itext) virtual

Sets text to the controller LCD screen.

Parameters
iline the line number in the range [0-2] at which the text will be displayed
icol the column number in the range [0-14] at which the text will be displayed
itext the string to display
Returns 1 if the operation was successful, PROS_ERR otherwise

std::int32_t okapi::Controller::clear() virtual

Clears all of the lines of the controller screen.

Returns 1 if the operation was successful, PROS_ERR otherwise

On vexOS version 1.0.0 this function will block for 110ms.

std::int32_t okapi::Controller::clearLine(std::uint8_t iline) virtual

Clears an individual line of the controller screen.

Parameters
iline the line number to clear in the range [0, 2].
Returns 1 if the operation was successful, PROS_ERR otherwise

std::int32_t okapi::Controller::rumble(std::string irumblePattern) virtual

Rumble the controller.

Parameters
irumblePattern A string consisting of the characters '.', '-', and ' ', where dots are short rumbles, dashes are long rumbles, and spaces are pauses. Maximum supported length is 8 characters.
Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Controller rumble activation is currently in beta, so continuous, fast updates will not work well.

std::int32_t okapi::Controller::getBatteryCapacity() virtual

Gets the battery capacity of the given controller.

Returns the controller's battery capacity

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the controller port.

std::int32_t okapi::Controller::getBatteryLevel() virtual

Gets the battery level of the given controller.

Returns the controller's battery level

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the controller port.