Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
JoysticksController Class Reference

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
 

Detailed Description

The JoysticksController class.

This class is responsible for controlling the joysticks of the car.

Definition at line 28 of file JoysticksController.hpp.

Constructor & Destructor Documentation

◆ JoysticksController()

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.

Parameters
steeringCallbackThe callback to be called when the steering of the joystick is updated.
speedCallbackThe callback to be called when the speed of the joystick is updated.
parentThe QObject parent of this JoysticksController object.

Definition at line 34 of file JoysticksController.cpp.

◆ ~JoysticksController()

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.

Member Function Documentation

◆ finished

void JoysticksController::finished ( )
signal
Here is the caller graph for this function:

◆ init()

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.

Returns
True if the joystick is successfully initialized and opened, false otherwise.

Definition at line 60 of file JoysticksController.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processInput

void JoysticksController::processInput ( )
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.

Returns
if the joystick is not initialized.

Definition at line 90 of file JoysticksController.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ requestStop()

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.

Field Documentation

◆ m_joystick

SDL_Joystick* JoysticksController::m_joystick
private

Definition at line 33 of file JoysticksController.hpp.

◆ m_running

bool JoysticksController::m_running
private

Definition at line 36 of file JoysticksController.hpp.

◆ m_updateSpeed

std::function<void(int)> JoysticksController::m_updateSpeed
private

Definition at line 35 of file JoysticksController.hpp.

◆ m_updateSteering

std::function<void(int)> JoysticksController::m_updateSteering
private

Definition at line 34 of file JoysticksController.hpp.


The documentation for this class was generated from the following files: