1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-12-26 03:17:58 +00:00
sys-con/ControllerUSB/include/Controllers/Xbox360WirelessController.h
2019-11-09 23:26:47 +03:00

60 lines
1.5 KiB
C++

#pragma once
#include "IController.h"
#include "Xbox360Controller.h"
//References used:
//https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c
struct OutputPacket
{
const uint8_t *packet;
uint8_t length;
};
class Xbox360WirelessController : public IController
{
private:
IUSBEndpoint *m_inPipe = nullptr;
IUSBEndpoint *m_outPipe = nullptr;
Xbox360ButtonData m_buttonData;
bool m_presence = false;
std::vector<OutputPacket> m_outputBuffer;
public:
Xbox360WirelessController(std::unique_ptr<IUSBDevice> &&interface);
virtual ~Xbox360WirelessController();
virtual Status Initialize();
virtual void Exit();
Status OpenInterfaces();
void CloseInterfaces();
virtual Status GetInput();
virtual NormalizedButtonData GetNormalizedButtonData();
virtual ControllerType GetType() { return CONTROLLER_XBOX360W; }
inline const Xbox360ButtonData &GetButtonData() { return m_buttonData; };
float NormalizeTrigger(uint8_t value);
void NormalizeAxis(int16_t x, int16_t y, uint8_t deadzonePercent, float *x_out, float *y_out);
Status SetRumble(uint8_t strong_magnitude, uint8_t weak_magnitude);
Status SetLED(Xbox360LEDValue value);
Status OnControllerConnect();
Status OnControllerDisconnect();
static void LoadConfig(const ControllerConfig *config);
virtual ControllerConfig *GetConfig();
Status OutputBuffer();
bool IsControllerActive() override { return m_presence; }
};