2020-08-25 19:23:38 +00:00
|
|
|
/*
|
2021-01-26 03:03:26 +00:00
|
|
|
* Copyright (c) 2020-2021 ndeadly
|
2020-08-25 19:23:38 +00:00
|
|
|
*
|
2020-08-26 22:50:34 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
2020-08-25 19:23:38 +00:00
|
|
|
*
|
2020-08-26 22:50:34 +00:00
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
2020-08-25 19:23:38 +00:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-06-02 21:24:40 +00:00
|
|
|
#pragma once
|
2020-08-26 18:52:47 +00:00
|
|
|
#include "emulated_switch_controller.hpp"
|
2020-06-09 20:39:30 +00:00
|
|
|
|
2020-07-11 11:43:21 +00:00
|
|
|
namespace ams::controller {
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2021-07-06 14:19:49 +00:00
|
|
|
enum Dualshock4ReportRate {
|
|
|
|
Dualshock4ReportRate_Max = 0,
|
|
|
|
Dualshock4ReportRate_1000Hz = 1,
|
|
|
|
Dualshock4ReportRate_500Hz = 2,
|
|
|
|
Dualshock4ReportRate_333Hz = 3,
|
|
|
|
Dualshock4ReportRate_250Hz = 4,
|
|
|
|
Dualshock4ReportRate_200Hz = 5,
|
|
|
|
Dualshock4ReportRate_166Hz = 6,
|
|
|
|
Dualshock4ReportRate_142Hz = 7,
|
|
|
|
Dualshock4ReportRate_125Hz = 8,
|
|
|
|
Dualshock4ReportRate_111Hz = 9,
|
|
|
|
Dualshock4ReportRate_100Hz = 10,
|
|
|
|
Dualshock4ReportRate_90Hz = 11,
|
|
|
|
Dualshock4ReportRate_83Hz = 12,
|
|
|
|
Dualshock4ReportRate_76Hz = 13,
|
|
|
|
Dualshock4ReportRate_71Hz = 14,
|
|
|
|
Dualshock4ReportRate_66Hz = 15,
|
|
|
|
Dualshock4ReportRate_62Hz = 16
|
|
|
|
};
|
|
|
|
|
2020-06-02 21:24:40 +00:00
|
|
|
enum Dualshock4ControllerVariant {
|
|
|
|
Dualshock4ControllerVariant_V1,
|
|
|
|
Dualshock4ControllerVariant_V2,
|
|
|
|
Dualshock4ControllerVariant_Unknown
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Dualshock4DPadDirection {
|
|
|
|
Dualshock4DPad_N,
|
|
|
|
Dualshock4DPad_NE,
|
|
|
|
Dualshock4DPad_E,
|
|
|
|
Dualshock4DPad_SE,
|
|
|
|
Dualshock4DPad_S,
|
|
|
|
Dualshock4DPad_SW,
|
|
|
|
Dualshock4DPad_W,
|
|
|
|
Dualshock4DPad_NW,
|
|
|
|
Dualshock4DPad_Released
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Dualshock4StickData {
|
|
|
|
uint8_t x;
|
|
|
|
uint8_t y;
|
2020-07-07 19:29:47 +00:00
|
|
|
} __attribute__((packed));
|
2020-06-02 21:24:40 +00:00
|
|
|
|
|
|
|
struct Dualshock4ButtonData {
|
|
|
|
uint8_t dpad : 4;
|
|
|
|
uint8_t square : 1;
|
|
|
|
uint8_t cross : 1;
|
|
|
|
uint8_t circle : 1;
|
|
|
|
uint8_t triangle : 1;
|
|
|
|
|
|
|
|
uint8_t L1 : 1;
|
|
|
|
uint8_t R1 : 1;
|
|
|
|
uint8_t L2 : 1;
|
|
|
|
uint8_t R2 : 1;
|
|
|
|
uint8_t share : 1;
|
|
|
|
uint8_t options : 1;
|
|
|
|
uint8_t L3 : 1;
|
|
|
|
uint8_t R3 : 1;
|
|
|
|
|
|
|
|
uint8_t ps : 1;
|
|
|
|
uint8_t tpad : 1;
|
|
|
|
uint8_t counter : 6;
|
2020-07-07 19:29:47 +00:00
|
|
|
} __attribute__((packed));
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-09-30 23:03:34 +00:00
|
|
|
struct Dualshock4RumbleData {
|
|
|
|
uint8_t amp_motor_left;
|
|
|
|
uint8_t amp_motor_right;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2020-06-02 21:24:40 +00:00
|
|
|
struct Dualshock4OutputReport0x11 {
|
|
|
|
struct {
|
|
|
|
uint8_t data[75];
|
|
|
|
};
|
|
|
|
uint32_t crc;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct Dualshock4InputReport0x01 {
|
|
|
|
Dualshock4StickData left_stick;
|
|
|
|
Dualshock4StickData right_stick;
|
|
|
|
Dualshock4ButtonData buttons;
|
|
|
|
uint8_t left_trigger;
|
|
|
|
uint8_t right_trigger;
|
2020-07-07 19:29:47 +00:00
|
|
|
} __attribute__((packed));
|
2020-06-02 21:24:40 +00:00
|
|
|
|
|
|
|
struct Dualshock4InputReport0x11 {
|
2020-08-08 00:05:41 +00:00
|
|
|
uint8_t _unk0[2];
|
2020-06-02 21:24:40 +00:00
|
|
|
Dualshock4StickData left_stick;
|
|
|
|
Dualshock4StickData right_stick;
|
|
|
|
Dualshock4ButtonData buttons;
|
|
|
|
uint8_t left_trigger;
|
|
|
|
uint8_t right_trigger;
|
2020-07-07 19:27:49 +00:00
|
|
|
uint16_t timestamp;
|
2020-06-02 21:24:40 +00:00
|
|
|
uint8_t battery;
|
|
|
|
uint16_t vel_x;
|
|
|
|
uint16_t vel_y;
|
|
|
|
uint16_t vel_z;
|
|
|
|
uint16_t acc_x;
|
|
|
|
uint16_t acc_y;
|
|
|
|
uint16_t acc_z;
|
2020-08-08 00:05:41 +00:00
|
|
|
uint8_t _unk1[5];
|
2020-06-02 21:24:40 +00:00
|
|
|
|
|
|
|
uint8_t battery_level : 4;
|
|
|
|
uint8_t usb : 1;
|
|
|
|
uint8_t mic : 1;
|
|
|
|
uint8_t phone : 1;
|
|
|
|
uint8_t : 0;
|
|
|
|
|
|
|
|
uint16_t _unk2;
|
2020-08-26 18:52:47 +00:00
|
|
|
uint8_t tpad_packets;
|
|
|
|
uint8_t packet_counter;
|
2020-07-07 19:29:47 +00:00
|
|
|
} __attribute__((packed));
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-07-11 11:43:21 +00:00
|
|
|
struct Dualshock4ReportData {
|
|
|
|
uint8_t id;
|
|
|
|
union {
|
2020-07-27 17:42:40 +00:00
|
|
|
Dualshock4OutputReport0x11 output0x11;
|
|
|
|
Dualshock4InputReport0x01 input0x01;
|
|
|
|
Dualshock4InputReport0x11 input0x11;
|
2020-07-11 11:43:21 +00:00
|
|
|
};
|
|
|
|
} __attribute__((packed));
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-08-17 21:17:02 +00:00
|
|
|
class Dualshock4Controller : public EmulatedSwitchController {
|
2020-06-02 21:24:40 +00:00
|
|
|
|
|
|
|
public:
|
2020-08-26 18:52:47 +00:00
|
|
|
static constexpr const HardwareID hardware_ids[] = {
|
2020-09-12 17:29:41 +00:00
|
|
|
{0x054c, 0x05c4}, // Official Dualshock4 v1
|
|
|
|
{0x054c, 0x09cc}, // Official Dualshock4 v2
|
2021-01-15 21:06:04 +00:00
|
|
|
{0x0f0d, 0x00f6}, // Hori ONYX
|
|
|
|
{0x1532, 0x100a} // Razer Raiju Tournament
|
2020-06-02 21:24:40 +00:00
|
|
|
};
|
|
|
|
|
2020-07-30 20:07:26 +00:00
|
|
|
Dualshock4Controller(const bluetooth::Address *address)
|
2020-09-30 23:03:34 +00:00
|
|
|
: EmulatedSwitchController(address)
|
2021-07-06 14:19:49 +00:00
|
|
|
, m_report_rate(Dualshock4ReportRate_125Hz)
|
2020-09-30 23:03:34 +00:00
|
|
|
, m_led_colour({0, 0, 0})
|
|
|
|
, m_rumble_state({0, 0}) { };
|
2021-07-06 14:19:49 +00:00
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
Result Initialize(void);
|
2021-03-15 23:09:21 +00:00
|
|
|
Result SetVibration(const SwitchRumbleData *rumble_data);
|
2020-10-03 09:53:12 +00:00
|
|
|
Result CancelVibration(void);
|
2020-08-26 18:52:47 +00:00
|
|
|
Result SetPlayerLed(uint8_t led_mask);
|
2020-10-04 15:16:49 +00:00
|
|
|
Result SetLightbarColour(RGBColour colour);
|
2021-07-06 14:19:49 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void UpdateControllerState(const bluetooth::HidReport *report);
|
2020-06-02 21:24:40 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-03 15:22:21 +00:00
|
|
|
void HandleInputReport0x01(const Dualshock4ReportData *src);
|
|
|
|
void HandleInputReport0x11(const Dualshock4ReportData *src);
|
2020-07-27 17:42:40 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void MapButtons(const Dualshock4ButtonData *buttons);
|
2020-10-06 18:40:19 +00:00
|
|
|
|
|
|
|
Result PushRumbleLedState(void);
|
2020-07-27 17:42:40 +00:00
|
|
|
|
2021-07-06 14:19:49 +00:00
|
|
|
Dualshock4ReportRate m_report_rate;
|
2020-10-04 15:16:49 +00:00
|
|
|
RGBColour m_led_colour;
|
2020-09-30 23:03:34 +00:00
|
|
|
Dualshock4RumbleData m_rumble_state;
|
2020-06-02 21:24:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|