The JoysticksController class. More...
#include <JoysticksController.hpp>
Public Slots | |
void | processInput () |
Runs the joystick controller loop. | |
Signals | |
void | finished () |
Public Member Functions | |
JoysticksController (std::function< void(int)> steeringCallback, std::function< void(int)> speedCallback, QObject *parent=nullptr) | |
Construct a JoysticksController object. | |
~JoysticksController () | |
Destruct a JoysticksController object. | |
bool | init () |
Initializes the joystick controller. | |
void | requestStop () |
Requests the joystick controller to stop. | |
Private Attributes | |
SDL_Joystick * | m_joystick |
std::function< void(int)> | m_updateSteering |
std::function< void(int)> | m_updateSpeed |
bool | m_running |
The JoysticksController class.
This class is responsible for controlling the joysticks of the car.
Definition at line 28 of file JoysticksController.hpp.
JoysticksController::JoysticksController | ( | std::function< void(int)> | steeringCallback, |
std::function< void(int)> | speedCallback, | ||
QObject * | parent = nullptr ) |
Construct a JoysticksController object.
This constructor takes a QObject parent and two std::function callbacks. The first callback is called when the steering of the joystick is updated, and the second one is called when the speed of the joystick is updated.
steeringCallback | The callback to be called when the steering of the joystick is updated. |
speedCallback | The callback to be called when the speed of the joystick is updated. |
parent | The QObject parent of this JoysticksController object. |
Definition at line 34 of file JoysticksController.cpp.
JoysticksController::~JoysticksController | ( | ) |
Destruct a JoysticksController object.
This destructor closes the SDL joystick and quits SDL if a joystick was opened.
Definition at line 46 of file JoysticksController.cpp.
|
signal |
bool JoysticksController::init | ( | ) |
Initializes the joystick controller.
This function initializes the SDL joystick subsystem and opens the first available joystick device. If SDL initialization fails, an error message is logged and the function returns false.
Definition at line 60 of file JoysticksController.cpp.
|
slot |
Runs the joystick controller loop.
This function is run in its own thread and waits for SDL events from the joystick. If the joystick is not initialized, it logs an error message and emits the finished() signal. The loop will stop when the running flag is set to false (by calling requestStop()) or when the thread is interrupted. The finished() signal is emitted when the loop finishes.
Definition at line 90 of file JoysticksController.cpp.
void JoysticksController::requestStop | ( | ) |
Requests the joystick controller to stop.
This function sets the running flag to false, which will stop the joystick controller loop.
Definition at line 79 of file JoysticksController.cpp.
|
private |
Definition at line 33 of file JoysticksController.hpp.
|
private |
Definition at line 36 of file JoysticksController.hpp.
|
private |
Definition at line 35 of file JoysticksController.hpp.
|
private |
Definition at line 34 of file JoysticksController.hpp.