2020-11-13 22:26:40 +00:00
|
|
|
/*
|
2021-01-26 03:03:26 +00:00
|
|
|
* Copyright (c) 2020-2021 ndeadly
|
2020-11-13 22:26:40 +00:00
|
|
|
*
|
2021-01-26 03:03:26 +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-11-13 22:26:40 +00:00
|
|
|
*
|
2021-01-26 03:03:26 +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-11-13 22:26:40 +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/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "emulated_switch_controller.hpp"
|
|
|
|
|
|
|
|
namespace ams::controller {
|
|
|
|
|
|
|
|
enum DualsenseDPadDirection {
|
|
|
|
DualsenseDPad_N,
|
|
|
|
DualsenseDPad_NE,
|
|
|
|
DualsenseDPad_E,
|
|
|
|
DualsenseDPad_SE,
|
|
|
|
DualsenseDPad_S,
|
|
|
|
DualsenseDPad_SW,
|
|
|
|
DualsenseDPad_W,
|
|
|
|
DualsenseDPad_NW,
|
|
|
|
DualsenseDPad_Released
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DualsenseStickData {
|
|
|
|
uint8_t x;
|
|
|
|
uint8_t y;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct DualsenseButtonData {
|
|
|
|
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;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2021-01-28 21:10:05 +00:00
|
|
|
struct DualsenseRumbleData {
|
|
|
|
uint8_t amp_motor_left;
|
|
|
|
uint8_t amp_motor_right;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2021-07-28 19:30:47 +00:00
|
|
|
struct DualsenseOutputReport0x31 {
|
2021-01-27 19:51:22 +00:00
|
|
|
struct {
|
|
|
|
uint8_t data[75];
|
|
|
|
};
|
|
|
|
uint32_t crc;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2020-11-13 22:26:40 +00:00
|
|
|
struct DualsenseInputReport0x01 {
|
2021-01-27 19:51:22 +00:00
|
|
|
DualsenseStickData left_stick;
|
|
|
|
DualsenseStickData right_stick;
|
|
|
|
DualsenseButtonData buttons;
|
|
|
|
uint8_t left_trigger;
|
|
|
|
uint8_t right_trigger;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct DualsenseInputReport0x31 {
|
|
|
|
uint8_t _unk0;
|
|
|
|
DualsenseStickData left_stick;
|
|
|
|
DualsenseStickData right_stick;
|
2020-11-13 22:26:40 +00:00
|
|
|
uint8_t left_trigger;
|
|
|
|
uint8_t right_trigger;
|
2021-01-27 19:51:22 +00:00
|
|
|
uint8_t counter;
|
|
|
|
DualsenseButtonData buttons;
|
|
|
|
uint8_t _unk1[5];
|
|
|
|
uint16_t vel_x;
|
|
|
|
uint16_t vel_y;
|
|
|
|
uint16_t vel_z;
|
|
|
|
uint16_t acc_x;
|
|
|
|
uint16_t acc_y;
|
|
|
|
uint16_t acc_z;
|
|
|
|
uint8_t _unk2[25];
|
|
|
|
|
|
|
|
uint8_t battery_level : 4;
|
|
|
|
uint8_t usb : 1;
|
|
|
|
uint8_t full : 1;
|
|
|
|
uint8_t : 0;
|
2020-11-13 22:26:40 +00:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct DualsenseReportData {
|
|
|
|
uint8_t id;
|
|
|
|
union {
|
|
|
|
DualsenseInputReport0x01 input0x01;
|
2021-01-27 19:51:22 +00:00
|
|
|
DualsenseInputReport0x31 input0x31;
|
2020-11-13 22:26:40 +00:00
|
|
|
};
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
class DualsenseController : public EmulatedSwitchController {
|
|
|
|
|
|
|
|
public:
|
2021-07-28 19:30:47 +00:00
|
|
|
static constexpr const HardwareID hardware_ids[] = {
|
2020-11-13 22:26:40 +00:00
|
|
|
{0x054c, 0x0ce6} // Sony Dualsense Controller
|
2021-07-28 19:30:47 +00:00
|
|
|
};
|
2020-11-13 22:26:40 +00:00
|
|
|
|
2021-07-28 19:30:47 +00:00
|
|
|
DualsenseController(const bluetooth::Address *address, HardwareID id)
|
|
|
|
: EmulatedSwitchController(address, id)
|
|
|
|
, m_led_flags(0)
|
|
|
|
, m_led_colour({0, 0, 0})
|
|
|
|
, m_rumble_state({0, 0}) { }
|
2020-11-13 22:26:40 +00:00
|
|
|
|
2021-01-27 19:51:22 +00:00
|
|
|
Result Initialize(void);
|
2021-03-15 23:09:21 +00:00
|
|
|
Result SetVibration(const SwitchRumbleData *rumble_data);
|
2021-01-28 21:10:05 +00:00
|
|
|
Result CancelVibration(void);
|
2021-01-27 19:51:22 +00:00
|
|
|
Result SetPlayerLed(uint8_t led_mask);
|
|
|
|
Result SetLightbarColour(RGBColour colour);
|
2020-11-13 22:26:40 +00:00
|
|
|
|
|
|
|
void UpdateControllerState(const bluetooth::HidReport *report);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void HandleInputReport0x01(const DualsenseReportData *src);
|
2021-01-27 19:51:22 +00:00
|
|
|
void HandleInputReport0x31(const DualsenseReportData *src);
|
|
|
|
|
2020-11-13 22:26:40 +00:00
|
|
|
void MapButtons(const DualsenseButtonData *buttons);
|
|
|
|
|
2021-01-27 19:51:22 +00:00
|
|
|
Result PushRumbleLedState(void);
|
|
|
|
|
|
|
|
uint8_t m_led_flags;
|
|
|
|
RGBColour m_led_colour;
|
2021-01-28 21:10:05 +00:00
|
|
|
DualsenseRumbleData m_rumble_state;
|
2020-11-13 22:26:40 +00:00
|
|
|
};
|
2021-07-28 19:30:47 +00:00
|
|
|
|
2020-11-13 22:26:40 +00:00
|
|
|
}
|