21#include <source_location>
24#include "../extern/hidapi/hidapi/hidapi.h"
25#include "../include/export.h"
35 class OWC_EXPORT Controller {
37 std::function<void(
const std::wstring &)> logFn;
38 hid_device *gamepad =
nullptr;
39 uint8_t *sendBuf =
nullptr;
40 uint8_t *respBuf =
nullptr;
45 [[nodiscard]]
virtual int getVID()
const = 0;
46 [[nodiscard]]
virtual int getPID()
const = 0;
48 void prepareRespBuffer()
const;
49 void writeLog(
const std::wstring &msg, std::source_location loc = std::source_location::current())
const;
50 [[nodiscard]]
bool sendReadRequest()
const;
51 [[nodiscard]]
bool sendWriteRequest()
const;
52 [[nodiscard]]
bool setButtonKey(uint16_t *btn,
const std::string &key)
const;
53 [[nodiscard]]
bool setXinputKey(uint16_t *btn,
const std::string &key)
const;
54 void setBackButtonTime(uint16_t *field,
int time)
const;
55 void setAnalogDeadzone(int8_t *field,
int value)
const;
58 Controller(
int controllerFeatures,
int sendBufSz,
int respBufSz);
59 virtual ~Controller();
98 [[nodiscard]]
virtual bool setButton(
Button btn,
const std::string &key)
const = 0;
116 [[nodiscard]]
virtual bool setBackButton(
int num,
int slot,
const std::string &key)
const = 0;
126 [[nodiscard]]
virtual std::string
getBackButton(
int num,
int slot)
const = 0;
186 [[nodiscard]]
virtual std::tuple<int, int, int>
getLedColor()
const = 0;
220 void enableLogging(
const std::function<
void(
const std::wstring &)> &logCB) { logFn = logCB; }
227 [[nodiscard]]
bool init();
234 [[nodiscard]]
bool hasFeature(
int feature)
const;
LedMode
led mode
Definition LedMode.h:28
RumbleMode
vibration intensity
Definition RumbleMode.h:28
virtual LedMode getLedMode() const =0
get current led mode
virtual void setAnalogBoundary(int boundary, bool left) const =0
set the analog stick boundary offset (circularity)
virtual std::string getButton(Button btn) const =0
get the current key of button btn
virtual bool readConfig()=0
read the whole configuration
virtual bool resetConfig() const =0
reset the whole controller configuration memory
virtual bool writeConfig() const =0
write the configuration
virtual std::string getBackButton(int num, int slot) const =0
get the current key in slot slot of back button num
virtual void setAnalogCenter(int center, bool left) const =0
set the analog stick offset from center (deadzone)
void enableLogging(const std::function< void(const std::wstring &)> &logCB)
Enable log messages.
Definition Controller.h:220
virtual void setBackButtonStartTime(int num, int slot, int timeMs) const =0
set start time for key in slot slot of back button num
virtual int getAnalogBoundary(bool left) const =0
get the current analog stick boundary offset (circularity)
virtual int getBackButtonStartTime(int num, int slot) const =0
get start time for key in slot slot of back button num
virtual bool setButton(Button btn, const std::string &key) const =0
set a new key for the button btn
virtual bool readVersion()=0
read the controller firmware version
virtual int getAnalogCenter(bool left) const =0
get the current analog stick offset from center (deadzone)
virtual bool setBackButton(int num, int slot, const std::string &key) const =0
set a new key in slot slot for back button num
virtual void setRumble(RumbleMode mode) const =0
set vibration intensity
virtual void setLedMode(LedMode mode) const =0
set led mode
virtual int getControllerType() const =0
int value of the controller class version
virtual RumbleMode getRumbleMode() const =0
get current vibration intesity
virtual void setLedColor(int r, int g, int b) const =0
set a custom color for the leds
virtual std::tuple< int, int, int > getLedColor() const =0
get current led custom color