2020-08-25 21:23:38 +02:00
|
|
|
/*
|
2024-01-26 10:23:42 +01:00
|
|
|
* Copyright (c) 2020-2024 ndeadly
|
2020-08-25 21:23:38 +02:00
|
|
|
*
|
2020-08-27 00:50:34 +02: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 21:23:38 +02:00
|
|
|
*
|
2020-08-27 00:50:34 +02: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 21:23:38 +02: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 23:24:40 +02:00
|
|
|
#pragma once
|
2020-08-26 20:52:47 +02:00
|
|
|
#include "emulated_switch_controller.hpp"
|
2020-06-02 23:24:40 +02:00
|
|
|
|
2020-07-11 13:43:21 +02:00
|
|
|
namespace ams::controller {
|
2020-06-02 23:24:40 +02:00
|
|
|
|
|
|
|
enum XboxOneDPadDirection {
|
|
|
|
XboxOneDPad_Released,
|
|
|
|
XboxOneDPad_N,
|
|
|
|
XboxOneDPad_NE,
|
|
|
|
XboxOneDPad_E,
|
|
|
|
XboxOneDPad_SE,
|
|
|
|
XboxOneDPad_S,
|
|
|
|
XboxOneDPad_SW,
|
|
|
|
XboxOneDPad_W,
|
|
|
|
XboxOneDPad_NW
|
|
|
|
};
|
|
|
|
|
2021-09-15 13:45:12 +02:00
|
|
|
enum XboxOnePowerMode {
|
|
|
|
XboxOnePowerMode_USB = 0,
|
|
|
|
XboxOnePowerMode_Battery = 1,
|
|
|
|
XboxOnePowerMode_PlayNCharge = 2
|
|
|
|
};
|
|
|
|
|
2020-08-05 23:18:54 +02:00
|
|
|
// Used on older firmware
|
2021-06-08 20:55:36 +02:00
|
|
|
struct XboxOneButtonDataOld {
|
2023-02-22 22:25:51 +01:00
|
|
|
u8 dpad;
|
|
|
|
|
|
|
|
u8 A : 1;
|
|
|
|
u8 B : 1;
|
|
|
|
u8 X : 1;
|
|
|
|
u8 Y : 1;
|
|
|
|
u8 LB : 1;
|
|
|
|
u8 RB : 1;
|
|
|
|
u8 view : 1;
|
|
|
|
u8 menu : 1;
|
|
|
|
|
|
|
|
u8 lstick_press : 1;
|
|
|
|
u8 rstick_press : 1;
|
|
|
|
u8 : 0;
|
2023-03-12 22:53:23 +01:00
|
|
|
} PACKED;
|
2020-07-11 13:43:21 +02:00
|
|
|
|
2020-08-05 23:18:54 +02:00
|
|
|
// Used on latest firmwares
|
2021-06-08 20:55:36 +02:00
|
|
|
struct XboxOneButtonData {
|
2023-02-22 22:25:51 +01:00
|
|
|
u8 dpad;
|
|
|
|
|
|
|
|
u8 A : 1;
|
|
|
|
u8 B : 1;
|
|
|
|
u8 : 1;
|
|
|
|
u8 X : 1;
|
|
|
|
u8 Y : 1;
|
|
|
|
u8 : 1;
|
|
|
|
u8 LB : 1;
|
|
|
|
u8 RB : 1;
|
|
|
|
|
|
|
|
u8 : 3;
|
|
|
|
u8 menu : 1;
|
|
|
|
u8 guide : 1;
|
|
|
|
u8 lstick_press : 1;
|
|
|
|
u8 rstick_press : 1;
|
|
|
|
u8 : 0;
|
|
|
|
|
|
|
|
u8 view : 1;
|
|
|
|
u8 : 0;
|
2023-03-12 22:53:23 +01:00
|
|
|
} PACKED;
|
2020-08-05 23:18:54 +02:00
|
|
|
|
2020-10-12 23:57:27 +02:00
|
|
|
struct XboxOneOutputReport0x03 {
|
2023-02-22 22:25:51 +01:00
|
|
|
u8 enable;
|
|
|
|
u8 magnitude_left;
|
|
|
|
u8 magnitude_right;
|
|
|
|
u8 magnitude_strong;
|
|
|
|
u8 magnitude_weak;
|
|
|
|
u8 pulse_sustain_10ms;
|
|
|
|
u8 pulse_release_10ms;
|
|
|
|
u8 loop_count;
|
2023-03-12 22:53:23 +01:00
|
|
|
} PACKED;
|
2020-10-03 11:52:41 +02:00
|
|
|
|
2020-07-11 15:24:00 +02:00
|
|
|
struct XboxOneInputReport0x01 {
|
2024-01-26 01:16:48 +01:00
|
|
|
AnalogStick<u16> left_stick;
|
|
|
|
AnalogStick<u16> right_stick;
|
2023-02-22 22:25:51 +01:00
|
|
|
u16 left_trigger;
|
|
|
|
u16 right_trigger;
|
2021-06-08 20:55:36 +02:00
|
|
|
union {
|
|
|
|
XboxOneButtonData buttons;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
XboxOneButtonDataOld buttons;
|
|
|
|
} old;
|
|
|
|
};
|
2023-03-12 22:53:23 +01:00
|
|
|
} PACKED;
|
2020-07-11 13:43:21 +02:00
|
|
|
|
2020-07-11 15:24:00 +02:00
|
|
|
struct XboxOneInputReport0x02{
|
2023-02-22 22:25:51 +01:00
|
|
|
u8 guide : 1;
|
|
|
|
u8 : 0;
|
2023-03-12 22:53:23 +01:00
|
|
|
} PACKED;
|
2020-07-11 13:43:21 +02:00
|
|
|
|
2020-08-06 21:17:55 +02:00
|
|
|
struct XboxOneInputReport0x04 {
|
2023-02-22 22:25:51 +01:00
|
|
|
u8 capacity : 2;
|
|
|
|
u8 mode : 2;
|
|
|
|
u8 charging : 1;
|
|
|
|
u8 : 2;
|
|
|
|
u8 online : 1;
|
2023-03-12 22:53:23 +01:00
|
|
|
} PACKED;
|
2020-06-02 23:24:40 +02:00
|
|
|
|
2020-07-11 13:43:21 +02:00
|
|
|
struct XboxOneReportData {
|
2023-02-22 22:25:51 +01:00
|
|
|
u8 id;
|
2020-07-11 13:43:21 +02:00
|
|
|
union {
|
2020-10-12 23:57:27 +02:00
|
|
|
XboxOneOutputReport0x03 output0x03;
|
2023-02-22 22:25:51 +01:00
|
|
|
XboxOneInputReport0x01 input0x01;
|
|
|
|
XboxOneInputReport0x02 input0x02;
|
|
|
|
XboxOneInputReport0x04 input0x04;
|
2020-07-11 13:43:21 +02:00
|
|
|
};
|
2023-03-12 22:53:23 +01:00
|
|
|
} PACKED;
|
2020-06-02 23:24:40 +02:00
|
|
|
|
2023-02-22 22:25:51 +01:00
|
|
|
class XboxOneController final : public EmulatedSwitchController {
|
2020-06-02 23:24:40 +02:00
|
|
|
|
|
|
|
public:
|
2023-02-22 22:25:51 +01:00
|
|
|
static constexpr const HardwareID hardware_ids[] = {
|
2020-08-28 10:37:11 +02:00
|
|
|
{0x045e, 0x02e0}, // Official Xbox One S Controller
|
|
|
|
{0x045e, 0x02fd}, // Official Xbox One S Controller
|
2020-09-24 12:19:20 +02:00
|
|
|
{0x045e, 0x0b00}, // Official Xbox One Elite 2 Controller
|
2020-09-24 12:31:56 +02:00
|
|
|
{0x045e, 0x0b05}, // Official Xbox One Elite 2 Controller
|
|
|
|
{0x045e, 0x0b0a} // Official Xbox Adaptive Controller
|
2023-02-22 22:25:51 +01:00
|
|
|
};
|
2020-06-02 23:24:40 +02:00
|
|
|
|
2023-02-22 22:25:51 +01:00
|
|
|
XboxOneController(const bluetooth::Address *address, HardwareID id)
|
2021-07-28 21:30:47 +02:00
|
|
|
: EmulatedSwitchController(address, id) { }
|
2020-06-02 23:24:40 +02:00
|
|
|
|
2021-03-16 00:09:21 +01:00
|
|
|
Result SetVibration(const SwitchRumbleData *rumble_data);
|
2022-03-30 19:27:24 +11:00
|
|
|
void ProcessInputData(const bluetooth::HidReport *report) override;
|
2020-06-02 23:24:40 +02:00
|
|
|
|
|
|
|
private:
|
2022-03-30 19:27:24 +11:00
|
|
|
void MapInputReport0x01(const XboxOneReportData *src, bool new_format);
|
|
|
|
void MapInputReport0x02(const XboxOneReportData *src);
|
|
|
|
void MapInputReport0x04(const XboxOneReportData *src);
|
2020-07-10 22:02:24 +02:00
|
|
|
|
2020-06-02 23:24:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|