1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-11-16 14:09:51 +00:00
sys-con/source/ControllerLib/Controllers/Xbox360WirelessController.h

62 lines
1.6 KiB
C
Raw Normal View History

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
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);
virtual ~Xbox360WirelessController() override;
2019-11-08 12:56:20 +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();
virtual Result GetInput() override;
2019-11-08 12:56:20 +00:00
virtual NormalizedButtonData GetNormalizedButtonData() override;
2019-11-08 12:56:20 +00:00
virtual ControllerType GetType() override { return CONTROLLER_XBOX360W; }
2019-11-08 12:56:20 +00:00
inline const Xbox360ButtonData &GetButtonData() { return m_buttonData; };
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 12:56:20 +00:00
static void LoadConfig(const ControllerConfig *config);
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);
virtual Result OutputBuffer() override;
bool IsControllerActive() override { return m_presence; }
2019-11-08 12:56:20 +00:00
};