2019-10-31 18:00:42 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "IController.h"
|
|
|
|
|
|
|
|
//References used:
|
|
|
|
//https://cs.chromium.org/chromium/src/device/gamepad/xbox_controller_mac.mm
|
|
|
|
|
|
|
|
struct Xbox360ButtonData
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
bool bumper_left : 1;
|
|
|
|
bool bumper_right : 1;
|
|
|
|
bool guide : 1;
|
|
|
|
bool dummy1 : 1; // Always 0.
|
|
|
|
|
|
|
|
bool a : 1;
|
|
|
|
bool b : 1;
|
|
|
|
bool x : 1;
|
|
|
|
bool y : 1;
|
|
|
|
|
|
|
|
uint8_t trigger_left;
|
|
|
|
uint8_t trigger_right;
|
|
|
|
|
|
|
|
int16_t stick_left_x;
|
|
|
|
int16_t stick_left_y;
|
|
|
|
int16_t stick_right_x;
|
|
|
|
int16_t stick_right_y;
|
|
|
|
|
|
|
|
// Always 0.
|
|
|
|
uint32_t dummy2;
|
|
|
|
uint16_t dummy3;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Xbox360RumbleData
|
|
|
|
{
|
|
|
|
uint8_t command;
|
|
|
|
uint8_t size;
|
|
|
|
uint8_t dummy1;
|
|
|
|
uint8_t big;
|
|
|
|
uint8_t little;
|
|
|
|
uint8_t dummy2[3];
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Xbox360InputPacketType
|
|
|
|
{
|
|
|
|
XBOX360INPUT_BUTTON = 0,
|
|
|
|
XBOX360INPUT_LED = 1,
|
|
|
|
XBOX360INPUT_RUMBLE = 3,
|
|
|
|
};
|
|
|
|
|
2019-11-07 09:48:06 +00:00
|
|
|
enum Xbox360LEDValue
|
|
|
|
{
|
|
|
|
XBOX360LED_OFF,
|
|
|
|
XBOX360LED_ALLBLINK,
|
|
|
|
XBOX360LED_TOPLEFTBLINK,
|
|
|
|
XBOX360LED_TOPRIGHTBLINK,
|
|
|
|
XBOX360LED_BOTTOMLEFTBLINK,
|
|
|
|
XBOX360LED_BOTTOMRIGHTBLINK,
|
|
|
|
XBOX360LED_TOPLEFT,
|
|
|
|
XBOX360LED_TOPRIGHT,
|
|
|
|
XBOX360LED_BOTTOMLEFT,
|
|
|
|
XBOX360LED_BOTTOMRIGHT,
|
|
|
|
XBOX360LED_ROTATE,
|
|
|
|
XBOX360LED_BLINK,
|
|
|
|
XBOX360LED_SLOWBLINK,
|
|
|
|
XBOX360LED_ROTATE_2,
|
|
|
|
XBOX360LED_ALLSLOWBLINK,
|
|
|
|
XBOX360LED_BLINKONCE,
|
|
|
|
};
|
|
|
|
|
2019-10-31 18:00:42 +00:00
|
|
|
class Xbox360Controller : public IController
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
IUSBEndpoint *m_inPipe = nullptr;
|
|
|
|
IUSBEndpoint *m_outPipe = nullptr;
|
|
|
|
|
|
|
|
Xbox360ButtonData m_buttonData;
|
2019-11-06 22:20:58 +00:00
|
|
|
/*
|
2019-10-31 18:00:42 +00:00
|
|
|
|
2019-11-05 19:44:44 +00:00
|
|
|
int16_t kLeftThumbDeadzone = 8000; //7849;
|
|
|
|
int16_t kRightThumbDeadzone = 8000; //8689;
|
|
|
|
uint16_t kTriggerMax = 0; //1023;
|
|
|
|
uint16_t kTriggerDeadzone = 0; //120;
|
2019-11-06 22:20:58 +00:00
|
|
|
*/
|
2019-10-31 18:00:42 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
Xbox360Controller(std::unique_ptr<IUSBDevice> &&interface);
|
|
|
|
virtual ~Xbox360Controller();
|
|
|
|
|
|
|
|
virtual Status Initialize();
|
|
|
|
virtual void Exit();
|
|
|
|
|
|
|
|
Status OpenInterfaces();
|
|
|
|
void CloseInterfaces();
|
|
|
|
|
|
|
|
virtual Status GetInput();
|
|
|
|
|
|
|
|
virtual NormalizedButtonData GetNormalizedButtonData();
|
|
|
|
|
|
|
|
virtual ControllerType GetType() { return CONTROLLER_XBOX360; }
|
|
|
|
|
|
|
|
inline const Xbox360ButtonData &GetButtonData() { return m_buttonData; };
|
|
|
|
|
2019-11-07 17:46:47 +00:00
|
|
|
float NormalizeTrigger(uint8_t value);
|
|
|
|
void NormalizeAxis(int16_t x, int16_t y, uint8_t deadzonePercent, float *x_out, float *y_out);
|
2019-10-31 18:00:42 +00:00
|
|
|
|
|
|
|
Status SendInitBytes();
|
|
|
|
Status SetRumble(uint8_t strong_magnitude, uint8_t weak_magnitude);
|
2019-11-06 22:20:58 +00:00
|
|
|
|
2019-11-07 09:48:06 +00:00
|
|
|
Status SetLED(Xbox360LEDValue value);
|
|
|
|
|
2019-11-06 22:20:58 +00:00
|
|
|
static void LoadConfig(const ControllerConfig *config);
|
2019-10-31 18:00:42 +00:00
|
|
|
};
|