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
cathery fb578f6987 Change controller config options
Allow unmapping keys
Allow mapping multiple keys to the same button
Allow changing the deadzone for each trigger
Remove dualshock4 global option from the config files

Update config files for new changes
2020-12-07 15:03:35 +03:00

62 lines
1.6 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() override;
virtual Result Initialize() override;
virtual void Exit() override;
Result OpenInterfaces();
void CloseInterfaces();
virtual Result GetInput() override;
virtual NormalizedButtonData GetNormalizedButtonData() override;
virtual ControllerType GetType() override { return CONTROLLER_XBOX360W; }
inline const Xbox360ButtonData &GetButtonData() { return m_buttonData; };
float NormalizeTrigger(uint8_t deadzonePercent, uint8_t value);
void NormalizeAxis(int16_t x, int16_t y, uint8_t deadzonePercent, float *x_out, float *y_out);
Result SetRumble(uint8_t strong_magnitude, uint8_t weak_magnitude);
Result SetLED(Xbox360LEDValue value);
Result OnControllerConnect();
Result OnControllerDisconnect();
static void LoadConfig(const ControllerConfig *config);
virtual ControllerConfig *GetConfig() override;
Result WriteToEndpoint(const uint8_t *buffer, size_t size);
virtual Result OutputBuffer() override;
bool IsControllerActive() override { return m_presence; }
};