2022-03-21 21:52:44 -04:00
|
|
|
#pragma once
|
|
|
|
#include "Controller.h"
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
|
|
|
#define INVALID_SDL_CONTROLLER_GUID (std::string("00000000000000000000000000000000"))
|
|
|
|
|
|
|
|
namespace Ship {
|
|
|
|
class SDLController : public Controller {
|
|
|
|
public:
|
|
|
|
SDLController(int32_t dwControllerNumber);
|
|
|
|
~SDLController();
|
|
|
|
|
|
|
|
void ReadFromSource();
|
|
|
|
void WriteToSource(ControllerCallback* controller);
|
2022-04-26 19:50:24 -04:00
|
|
|
bool Connected() const { return Cont != nullptr; }
|
2022-05-11 13:18:24 -04:00
|
|
|
bool CanRumble() const {
|
|
|
|
#if SDL_COMPILEDVERSION >= SDL_VERSIONNUM(2,0,18)
|
|
|
|
return SDL_GameControllerHasRumble(Cont);
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
2022-03-21 21:52:44 -04:00
|
|
|
|
|
|
|
std::string GetGuid() { return guid; };
|
|
|
|
|
2022-04-26 19:50:24 -04:00
|
|
|
bool HasPadConf() const { return true; }
|
|
|
|
std::optional<std::string> GetPadConfSection();
|
|
|
|
|
2022-03-21 21:52:44 -04:00
|
|
|
protected:
|
|
|
|
std::string GetControllerType();
|
|
|
|
void SetButtonMapping(const std::string& szButtonName, int32_t dwScancode);
|
|
|
|
std::string GetConfSection();
|
|
|
|
std::string GetBindingConfSection();
|
|
|
|
void CreateDefaultBinding();
|
2022-04-26 19:50:24 -04:00
|
|
|
void CreateDefaultPadConf();
|
2022-03-21 21:52:44 -04:00
|
|
|
static bool IsGuidInUse(const std::string& guid);
|
|
|
|
|
|
|
|
private:
|
|
|
|
SDL_GameController* Cont;
|
2022-05-11 13:18:24 -04:00
|
|
|
std::string guid;
|
2022-03-21 21:52:44 -04:00
|
|
|
std::map<int32_t, int16_t> ThresholdMapping;
|
|
|
|
|
|
|
|
void LoadAxisThresholds();
|
|
|
|
void NormalizeStickAxis(int16_t wAxisValueX, int16_t wAxisValueY, int16_t wAxisThreshold);
|
|
|
|
bool Open();
|
|
|
|
bool Close();
|
|
|
|
};
|
|
|
|
}
|