sdl_module.h 1.4 KB
#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";
};