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/XboxController.h

86 lines
1.8 KiB
C
Raw Normal View History

2019-11-08 14:15:02 +00:00
#pragma once
#include "IController.h"
//References used:
//http://euc.jp/periphs/xbox-controller.ja.html
struct XboxButtonData
{
uint8_t type;
uint8_t length;
bool dpad_up : 1;
bool dpad_down : 1;
bool dpad_left : 1;
bool dpad_right : 1;
bool start : 1;
bool back : 1;
bool stick_left_click : 1;
bool stick_right_click : 1;
uint8_t reserved;
2019-11-10 16:11:38 +00:00
//These are analog
uint8_t a;
uint8_t b;
uint8_t x;
uint8_t y;
2019-11-08 14:15:02 +00:00
2019-11-10 16:11:38 +00:00
uint8_t black_buttton;
uint8_t white_button;
2019-11-08 14:15:02 +00:00
2019-11-10 16:11:38 +00:00
uint8_t trigger_left;
uint8_t trigger_right;
2019-11-08 14:15:02 +00:00
int16_t stick_left_x;
int16_t stick_left_y;
int16_t stick_right_x;
int16_t stick_right_y;
};
struct XboxRumbleData
{
uint8_t command;
uint8_t size;
uint8_t dummy1;
uint8_t big;
uint8_t dummy2;
uint8_t little;
};
class XboxController : public IController
{
private:
IUSBEndpoint *m_inPipe = nullptr;
IUSBEndpoint *m_outPipe = nullptr;
2019-11-21 21:41:07 +00:00
XboxButtonData m_buttonData{};
2019-11-08 14:15:02 +00:00
public:
XboxController(std::unique_ptr<IUSBDevice> &&interface);
virtual ~XboxController() override;
2019-11-08 14:15:02 +00:00
virtual Result Initialize() override;
virtual void Exit() override;
2019-11-08 14:15:02 +00:00
2019-11-13 11:16:13 +00:00
Result OpenInterfaces();
2019-11-08 14:15:02 +00:00
void CloseInterfaces();
virtual Result GetInput() override;
2019-11-08 14:15:02 +00:00
virtual NormalizedButtonData GetNormalizedButtonData() override;
2019-11-08 14:15:02 +00:00
virtual ControllerType GetType() override { return CONTROLLER_XBOX360; }
2019-11-08 14:15:02 +00:00
inline const XboxButtonData &GetButtonData() { return m_buttonData; };
float NormalizeTrigger(uint8_t deadzonePercent, uint8_t value);
2019-11-08 14:15:02 +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);
2019-11-08 14:15:02 +00:00
static void LoadConfig(const ControllerConfig *config);
virtual ControllerConfig *GetConfig() override;
2019-11-08 14:15:02 +00:00
};