35 std::function<
void(
int)> steeringCallback,
36 std::function<
void(
int)> speedCallback, QObject *parent)
61 if (SDL_Init(SDL_INIT_JOYSTICK) < 0) {
62 qDebug() <<
"Failed to initialize SDL:" << SDL_GetError();
94 qDebug() <<
"Joystick not initialized.";
99 while (
m_running && !QThread::currentThread()->isInterruptionRequested()) {
101 while (SDL_PollEvent(&e)) {
102 if (e.type == SDL_JOYAXISMOTION) {
103 if (e.jaxis.axis == 0) {
105 }
else if (e.jaxis.axis == 3) {
106 m_updateSpeed(
static_cast<int>(e.jaxis.value / 32767.0 * 100));
File containing the JoysticksController class.
JoysticksController(std::function< void(int)> steeringCallback, std::function< void(int)> speedCallback, QObject *parent=nullptr)
Construct a JoysticksController object.
SDL_Joystick * m_joystick
void requestStop()
Requests the joystick controller to stop.
std::function< void(int)> m_updateSpeed
bool init()
Initializes the joystick controller.
void processInput()
Runs the joystick controller loop.
~JoysticksController()
Destruct a JoysticksController object.
std::function< void(int)> m_updateSteering