rpcsx/rpcs3/Input/ds3_pad_handler.h

160 lines
3.5 KiB
C
Raw Permalink Normal View History

2020-12-05 13:08:24 +01:00
#pragma once
2019-02-02 15:15:09 +01:00
2021-02-12 01:07:10 +01:00
#include "hid_pad_handler.h"
2019-04-26 13:25:27 +02:00
#include <unordered_map>
2024-06-27 20:37:33 +02:00
namespace reports
{
struct ds3_rumble
{
u8 padding = 0x00;
u8 small_motor_duration = 0xFF; // 0xff means forever
u8 small_motor_on = 0x00; // 0 or 1 (off/on)
u8 large_motor_duration = 0xFF; // 0xff means forever
u8 large_motor_force = 0x00; // 0 to 255
};
struct ds3_led
{
u8 duration = 0xFF; // total duration, 0xff means forever
u8 interval_duration = 0xFF; // interval duration in deciseconds
u8 enabled = 0x10;
u8 interval_portion_off = 0x00; // in percent (100% = 0xFF)
u8 interval_portion_on = 0xFF; // in percent (100% = 0xFF)
};
struct ds3_output_report
{
#ifdef _WIN32
u8 report_id = 0x00;
u8 idk_what_this_is[3] = {0x02, 0x00, 0x00};
#else
u8 report_id = 0x01;
#endif
ds3_rumble rumble;
u8 padding[4] = {0x00, 0x00, 0x00, 0x00};
u8 led_enabled = 0x00; // LED 1 = 0x02, LED 2 = 0x04, etc.
ds3_led led[4];
ds3_led led_5; // reserved for another LED
};
struct ds3_input_report
{
2024-04-29 20:49:39 +02:00
u8 unknown_0[2];
u8 buttons[3];
u8 unknown_1;
u8 lsx;
u8 lsy;
u8 rsx;
u8 rsy;
u8 unknown_2[4];
u8 button_values[12];
u8 unknown_3[4];
u8 battery_status;
u8 unknown_4[10];
le_t<u16, 1> accel_x;
le_t<u16, 1> accel_z;
le_t<u16, 1> accel_y;
2024-06-24 23:18:07 +02:00
le_t<u16, 1> gyro;
};
2024-04-29 20:49:39 +02:00
static_assert(sizeof(ds3_input_report) == 49);
} // namespace reports
2021-02-12 01:07:10 +01:00
class ds3_device : public HidDevice
{
public:
#ifdef _WIN32
u8 report_id = 0;
#endif
2024-06-27 20:37:33 +02:00
reports::ds3_input_report report{};
2021-02-12 01:07:10 +01:00
};
class ds3_pad_handler final : public hid_pad_handler<ds3_device>
2019-02-02 15:15:09 +01:00
{
enum DS3KeyCodes
{
2021-08-08 16:45:45 +02:00
None = 0,
Triangle,
2019-02-02 15:15:09 +01:00
Circle,
Cross,
Square,
Left,
Right,
Up,
Down,
R1,
R3,
L1,
L3,
Select,
Start,
PSButton,
L2,
R2,
LSXNeg,
LSXPos,
LSYNeg,
LSYPos,
RSXNeg,
RSXPos,
RSYNeg,
2021-08-08 16:45:45 +02:00
RSYPos
2019-02-02 15:15:09 +01:00
};
enum HidRequest
{
HID_GETREPORT = 0x01,
HID_GETIDLE,
HID_GETPROTOCOL,
HID_SETREPORT = 0x09,
HID_SETIDLE,
HID_SETPROTOCOL
};
enum ReportType
{
HIDREPORT_INPUT = 0x0100,
HIDREPORT_OUTPUT = 0x0200,
HIDREPORT_FEATURE = 0x0300
};
enum DS3Endpoints
{
DS3_ENDPOINT_OUT = 0x02,
DS3_ENDPOINT_IN = 0x81
};
2019-05-07 18:28:57 +02:00
#ifdef _WIN32
const u8 DS3_HID_OFFSET = 0x01;
#else
const u8 DS3_HID_OFFSET = 0x00;
#endif
2019-02-02 15:15:09 +01:00
public:
ds3_pad_handler();
2019-02-02 15:15:09 +01:00
~ds3_pad_handler();
void SetPadData(const std::string& padId, u8 player_id, u8 large_motor, u8 small_motor, s32 r, s32 g, s32 b, bool player_led, bool battery_led, u32 battery_led_brightness) override;
u32 get_battery_level(const std::string& padId) override;
2021-08-10 21:45:26 +02:00
void init_config(cfg_pad* cfg) override;
2019-02-02 15:15:09 +01:00
private:
2021-02-12 02:44:26 +01:00
ds3_pad_handler::DataStatus get_data(ds3_device* ds3dev) override;
int send_output_report(ds3_device* ds3dev) override;
2025-03-03 19:59:08 +01:00
void check_add_device(hid_device* hidDevice, hid_enumerated_device_view path, std::wstring_view serial) override;
2019-02-02 15:15:09 +01:00
2022-10-15 12:41:21 +02:00
bool get_is_left_trigger(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_right_trigger(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_left_stick(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
bool get_is_right_stick(const std::shared_ptr<PadDevice>& device, u64 keyCode) override;
PadHandlerBase::connection update_connection(const std::shared_ptr<PadDevice>& device) override;
2022-08-13 09:56:04 +02:00
void get_extended_info(const pad_ensemble& binding) override;
void apply_pad_data(const pad_ensemble& binding) override;
std::unordered_map<u64, u16> get_button_values(const std::shared_ptr<PadDevice>& device) override;
pad_preview_values get_preview_values(const std::unordered_map<u64, u16>& data) override;
2019-02-02 15:15:09 +01:00
};