2019-11-08 12:56:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "IController.h"
|
|
|
|
#include "Xbox360Controller.h"
|
|
|
|
|
|
|
|
//References used:
|
2019-11-08 14:15:02 +00:00
|
|
|
//https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c
|
2019-11-08 12:56:20 +00:00
|
|
|
|
2019-11-08 18:06:02 +00:00
|
|
|
struct OutputPacket
|
|
|
|
{
|
|
|
|
const uint8_t *packet;
|
|
|
|
uint8_t length;
|
|
|
|
};
|
|
|
|
|
2019-11-08 12:56:20 +00:00
|
|
|
class Xbox360WirelessController : public IController
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
IUSBEndpoint *m_inPipe = nullptr;
|
|
|
|
IUSBEndpoint *m_outPipe = nullptr;
|
|
|
|
|
2019-11-21 21:41:07 +00:00
|
|
|
Xbox360ButtonData m_buttonData{};
|
2019-11-08 12:56:20 +00:00
|
|
|
|
2019-11-08 23:31:49 +00:00
|
|
|
bool m_presence = false;
|
2019-11-08 12:56:20 +00:00
|
|
|
|
2019-11-08 18:06:02 +00:00
|
|
|
std::vector<OutputPacket> m_outputBuffer;
|
|
|
|
|
2019-11-08 12:56:20 +00:00
|
|
|
public:
|
|
|
|
Xbox360WirelessController(std::unique_ptr<IUSBDevice> &&interface);
|
2019-11-13 11:27:43 +00:00
|
|
|
virtual ~Xbox360WirelessController() override;
|
2019-11-08 12:56:20 +00:00
|
|
|
|
2019-11-13 11:27:43 +00:00
|
|
|
virtual Result Initialize() override;
|
|
|
|
virtual void Exit() override;
|
2019-11-08 12:56:20 +00:00
|
|
|
|
2019-11-13 11:16:13 +00:00
|
|
|
Result OpenInterfaces();
|
2019-11-08 12:56:20 +00:00
|
|
|
void CloseInterfaces();
|
|
|
|
|
2019-11-13 11:27:43 +00:00
|
|
|
virtual Result GetInput() override;
|
2019-11-08 12:56:20 +00:00
|
|
|
|
2019-11-13 11:27:43 +00:00
|
|
|
virtual NormalizedButtonData GetNormalizedButtonData() override;
|
2019-11-08 12:56:20 +00:00
|
|
|
|
2019-11-13 11:27:43 +00:00
|
|
|
virtual ControllerType GetType() override { return CONTROLLER_XBOX360W; }
|
2019-11-08 12:56:20 +00:00
|
|
|
|
|
|
|
inline const Xbox360ButtonData &GetButtonData() { return m_buttonData; };
|
|
|
|
|
2020-04-22 00:54:49 +00:00
|
|
|
float NormalizeTrigger(uint8_t deadzonePercent, uint8_t value);
|
2019-11-08 12:56:20 +00:00
|
|
|
void NormalizeAxis(int16_t x, int16_t y, uint8_t deadzonePercent, float *x_out, float *y_out);
|
|
|
|
|
2019-11-13 11:16:13 +00:00
|
|
|
Result SetRumble(uint8_t strong_magnitude, uint8_t weak_magnitude);
|
|
|
|
Result SetLED(Xbox360LEDValue value);
|
2019-11-08 12:56:20 +00:00
|
|
|
|
2019-11-13 11:16:13 +00:00
|
|
|
Result OnControllerConnect();
|
|
|
|
Result OnControllerDisconnect();
|
2019-11-08 23:31:49 +00:00
|
|
|
|
2019-11-08 12:56:20 +00:00
|
|
|
static void LoadConfig(const ControllerConfig *config);
|
2019-11-13 11:27:43 +00:00
|
|
|
virtual ControllerConfig *GetConfig() override;
|
2019-11-08 18:06:02 +00:00
|
|
|
|
2019-11-13 11:16:13 +00:00
|
|
|
Result WriteToEndpoint(const uint8_t *buffer, size_t size);
|
2019-11-09 21:02:30 +00:00
|
|
|
|
2019-11-13 11:27:43 +00:00
|
|
|
virtual Result OutputBuffer() override;
|
2019-11-08 23:31:49 +00:00
|
|
|
|
|
|
|
bool IsControllerActive() override { return m_presence; }
|
2019-11-08 12:56:20 +00:00
|
|
|
};
|