1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-11-16 23:11:25 +00:00
sys-con/source/ControllerLib/Controllers/Dualshock3Controller.h

161 lines
3.7 KiB
C
Raw Permalink Normal View History

2019-10-31 18:00:42 +00:00
#pragma once
#include "IController.h"
//References used:
//https://cs.chromium.org/chromium/src/device/gamepad/dualshock4_controller.cc
2019-11-22 00:47:16 +00:00
enum Dualshock3FeatureValue : uint16_t
2019-11-04 19:11:55 +00:00
{
Ds3FeatureUnknown1 = 0x0201,
Ds3FeatureUnknown2 = 0x0301,
Ds3FeatureDeviceAddress = 0x03F2,
Ds3FeatureStartDevice = 0x03F4,
Ds3FeatureHostAddress = 0x03F5,
Ds3FeatureUnknown3 = 0x03F7,
Ds3FeatureUnknown4 = 0x03EF,
Ds3FeatureUnknown5 = 0x03F8,
};
2019-11-22 00:47:16 +00:00
enum Dualshock3InputPacketType : uint8_t
2019-11-04 19:11:55 +00:00
{
Ds3InputPacket_Button = 0x01,
};
2019-10-31 18:00:42 +00:00
struct Dualshock3ButtonData
{
2019-11-04 19:11:55 +00:00
//byte0
2019-10-31 18:00:42 +00:00
uint8_t type;
2019-11-04 19:11:55 +00:00
//byte1
uint8_t pad0;
2019-10-31 18:00:42 +00:00
2019-11-04 19:11:55 +00:00
//byte2
2019-10-31 18:00:42 +00:00
bool back : 1;
bool stick_left_click : 1;
bool stick_right_click : 1;
2019-11-04 19:11:55 +00:00
bool start : 1;
2019-10-31 18:00:42 +00:00
2019-11-04 19:11:55 +00:00
bool dpad_up : 1;
bool dpad_right : 1;
bool dpad_down : 1;
bool dpad_left : 1;
//byte3
bool trigger_left : 1;
bool trigger_right : 1;
2019-10-31 18:00:42 +00:00
bool bumper_left : 1;
bool bumper_right : 1;
2019-11-04 19:11:55 +00:00
bool triangle : 1;
bool circle : 1;
bool cross : 1;
bool square : 1;
2019-10-31 18:00:42 +00:00
2019-11-04 19:11:55 +00:00
//byte4
bool guide : 1;
uint8_t pad1 : 7;
//byte5
uint8_t pad2;
//byte6-7
uint8_t stick_left_x;
uint8_t stick_left_y;
//byte8-9
uint8_t stick_right_x;
uint8_t stick_right_y;
//byte10-13
uint8_t pad3[4];
//byte14-17 These respond for how hard the corresponding button has been pressed. 0xFF completely, 0x00 not at all
uint8_t dpad_up_pressure;
uint8_t dpad_right_pressure;
uint8_t dpad_down_pressure;
uint8_t dpad_left_pressure;
//byte18-19
uint8_t trigger_left_pressure;
uint8_t trigger_right_pressure;
//byte20-21
uint8_t bumper_left_pressure;
uint8_t bumper_right_pressure;
//byte22-25
uint8_t triangle_pressure;
uint8_t circle_pressure;
uint8_t cross_pressure;
uint8_t square_pressure;
uint8_t pad4[15];
//byte41-48
uint16_t accelerometer_x;
uint16_t accelerometer_y;
uint16_t accelerometer_z;
uint16_t gyroscope;
} __attribute__((packed));
2019-10-31 18:00:42 +00:00
/*
#define DS3_VENDOR_ID 0x054C
#define DS3_PRODUCT_ID 0x0268
#define PS_MOVE_NAVI_PRODUCT_ID 0x042F
*/
2019-10-31 18:00:42 +00:00
2019-11-22 00:47:16 +00:00
enum Dualshock3LEDValue : uint8_t
{
DS3LED_1 = 0x01,
DS3LED_2 = 0x02,
DS3LED_3 = 0x04,
DS3LED_4 = 0x08,
DS3LED_5 = 0x09,
DS3LED_6 = 0x0A,
DS3LED_7 = 0x0C,
DS3LED_8 = 0x0D,
DS3LED_9 = 0x0E,
DS3LED_10 = 0x0F,
2019-10-31 18:00:42 +00:00
};
#define LED_PERMANENT 0xff, 0x27, 0x00, 0x00, 0x32
2019-10-31 18:00:42 +00:00
class Dualshock3Controller : public IController
{
private:
IUSBEndpoint *m_inPipe = nullptr;
IUSBEndpoint *m_outPipe = nullptr;
IUSBInterface *m_interface = nullptr;
2019-10-31 18:00:42 +00:00
2019-11-21 21:41:07 +00:00
Dualshock3ButtonData m_buttonData{};
2019-10-31 18:00:42 +00:00
public:
Dualshock3Controller(std::unique_ptr<IUSBDevice> &&interface);
virtual ~Dualshock3Controller() override;
2019-10-31 18:00:42 +00:00
virtual Result Initialize() override;
virtual void Exit() override;
2019-10-31 18:00:42 +00:00
2019-11-13 11:16:13 +00:00
Result OpenInterfaces();
2019-10-31 18:00:42 +00:00
void CloseInterfaces();
virtual Result GetInput() override;
2019-10-31 18:00:42 +00:00
virtual NormalizedButtonData GetNormalizedButtonData() override;
2019-10-31 18:00:42 +00:00
virtual ControllerType GetType() override { return CONTROLLER_DUALSHOCK3; }
2019-10-31 18:00:42 +00:00
inline const Dualshock3ButtonData &GetButtonData() { return m_buttonData; };
float NormalizeTrigger(uint8_t deadzonePercent, uint8_t value);
2019-11-07 17:46:47 +00:00
void NormalizeAxis(uint8_t x, uint8_t y, uint8_t deadzonePercent, float *x_out, float *y_out);
2019-10-31 18:00:42 +00:00
2019-11-13 11:16:13 +00:00
Result SendInitBytes();
Result SetRumble(uint8_t strong_magnitude, uint8_t weak_magnitude);
2019-11-06 22:20:58 +00:00
static Result SendCommand(IUSBInterface *interface, Dualshock3FeatureValue feature, const void *buffer, uint16_t size);
2019-11-13 11:16:13 +00:00
Result SetLED(Dualshock3LEDValue value);
2019-11-06 22:20:58 +00:00
static void LoadConfig(const ControllerConfig *config);
virtual ControllerConfig *GetConfig() override;
2019-10-31 18:00:42 +00:00
};