1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include <QObject>
#include <SDL2/SDL.h>
#include <iostream>
#include <vector>
#include <chrono>
#include <thread>
#include <algorithm>
#include <fstream>
#include <string>
#include "module_data.h"
class sdl_module : public QObject
{
Q_OBJECT
public:
sdl_module(QObject* parent = nullptr);
~sdl_module();
private:
void LoadConnectedControllers(std::vector<SDL_Joystick*>& connectedControllers);
void CheckControllerConnection(std::vector<SDL_Joystick*>& connectedControllers);
void ReloadConnectedControllers(std::vector<SDL_Joystick*>& connectedControllers, int disconnectedControllerIndex);
void CheckControllerDisconnection(std::vector<SDL_Joystick*>& connectedControllers, int disconnectedControllerIndex);
void SaveConnectedControllers();
bool IsNewControllerConnected(const std::vector<SDL_Joystick*>& connectedControllers);
void ProcessEvent(const SDL_Event& event);
float NormalizeAxisValue(Sint16 value);
void RunControllerEventLoop();
void call_sdl_data();
signals:
void buttonStateEvent(int joystickIndex, const QString& guid, int button, bool pressed);
void axisMotionEvent(int joystickIndex, const QString& guid, int axis, double value);
private:
// std::vector<SDL_Joystick*> connectedControllers;
std::shared_ptr<module_data> _module_data = nullptr;
int disconnectedControllerIndex = 0;
const std::string configFilePath = "./conf/controller_config.txt";
};