2020-06-02 21:24:40 +00:00
|
|
|
#pragma once
|
2020-07-11 18:26:55 +00:00
|
|
|
#include "fakeswitchcontroller.hpp"
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-07-11 11:43:21 +00:00
|
|
|
namespace ams::controller {
|
2020-06-02 21:24:40 +00:00
|
|
|
|
|
|
|
enum XboxOneDPadDirection {
|
|
|
|
XboxOneDPad_Released,
|
|
|
|
XboxOneDPad_N,
|
|
|
|
XboxOneDPad_NE,
|
|
|
|
XboxOneDPad_E,
|
|
|
|
XboxOneDPad_SE,
|
|
|
|
XboxOneDPad_S,
|
|
|
|
XboxOneDPad_SW,
|
|
|
|
XboxOneDPad_W,
|
|
|
|
XboxOneDPad_NW
|
|
|
|
};
|
|
|
|
|
|
|
|
struct XboxOneStickData {
|
|
|
|
uint16_t x;
|
|
|
|
uint16_t y;
|
2020-07-11 11:43:21 +00:00
|
|
|
} __attribute__ ((__packed__));
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-08-05 21:18:54 +00:00
|
|
|
// Used on older firmware
|
2020-06-02 21:24:40 +00:00
|
|
|
struct XboxOneButtonData {
|
|
|
|
uint8_t dpad;
|
|
|
|
|
|
|
|
uint8_t A : 1;
|
|
|
|
uint8_t B : 1;
|
|
|
|
uint8_t X : 1;
|
|
|
|
uint8_t Y : 1;
|
|
|
|
uint8_t LB : 1;
|
|
|
|
uint8_t RB : 1;
|
|
|
|
uint8_t view : 1;
|
|
|
|
uint8_t menu : 1;
|
|
|
|
|
|
|
|
uint8_t lstick_press : 1;
|
|
|
|
uint8_t rstick_press : 1;
|
|
|
|
uint8_t : 0;
|
2020-07-11 11:43:21 +00:00
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-08-05 21:18:54 +00:00
|
|
|
// Used on latest firmwares
|
|
|
|
struct XboxOneButtonDataNew {
|
|
|
|
uint8_t dpad;
|
|
|
|
|
|
|
|
uint8_t A : 1;
|
|
|
|
uint8_t B : 1;
|
|
|
|
uint8_t : 1;
|
|
|
|
uint8_t X : 1;
|
|
|
|
uint8_t Y : 1;
|
|
|
|
uint8_t : 1;
|
|
|
|
uint8_t LB : 1;
|
|
|
|
uint8_t RB : 1;
|
|
|
|
|
|
|
|
uint8_t : 3;
|
|
|
|
uint8_t menu : 1;
|
|
|
|
uint8_t guide : 1;
|
|
|
|
uint8_t lstick_press : 1;
|
|
|
|
uint8_t rstick_press : 1;
|
|
|
|
uint8_t : 0;
|
|
|
|
|
|
|
|
uint8_t view : 1;
|
|
|
|
uint8_t : 0;
|
|
|
|
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-07-11 13:24:00 +00:00
|
|
|
struct XboxOneInputReport0x01 {
|
2020-08-05 21:18:54 +00:00
|
|
|
XboxOneStickData left_stick;
|
|
|
|
XboxOneStickData right_stick;
|
|
|
|
uint16_t left_trigger;
|
|
|
|
uint16_t right_trigger;
|
|
|
|
XboxOneButtonDataNew buttons;
|
2020-07-11 11:43:21 +00:00
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-07-11 13:24:00 +00:00
|
|
|
struct XboxOneInputReport0x02{
|
2020-07-11 11:43:21 +00:00
|
|
|
uint8_t guide : 1;
|
|
|
|
uint8_t : 0;
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-08-06 19:17:55 +00:00
|
|
|
struct XboxOneInputReport0x04 {
|
2020-07-11 11:43:21 +00:00
|
|
|
uint8_t capacity : 2;
|
|
|
|
uint8_t mode : 2;
|
|
|
|
uint8_t charging : 1;
|
|
|
|
uint8_t : 2;
|
|
|
|
uint8_t online : 1;
|
|
|
|
} __attribute__ ((__packed__));
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-07-11 11:43:21 +00:00
|
|
|
struct XboxOneReportData {
|
|
|
|
uint8_t id;
|
|
|
|
union {
|
2020-07-11 13:24:00 +00:00
|
|
|
XboxOneInputReport0x01 input0x01;
|
|
|
|
XboxOneInputReport0x02 input0x02;
|
|
|
|
XboxOneInputReport0x04 input0x04;
|
2020-07-11 11:43:21 +00:00
|
|
|
};
|
|
|
|
} __attribute__ ((__packed__));
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-07-11 18:26:55 +00:00
|
|
|
class XboxOneController : public FakeSwitchController {
|
2020-06-02 21:24:40 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
static constexpr const HardwareID hardwareIds[] = {
|
|
|
|
{0x045e, 0x02e0}, // Official Xbox One S Controller (old FW?)
|
|
|
|
{0x045e, 0x02fd} // Official Xbox One S Controller
|
|
|
|
};
|
|
|
|
|
2020-07-30 20:07:26 +00:00
|
|
|
XboxOneController(const bluetooth::Address *address)
|
|
|
|
: FakeSwitchController(ControllerType_XboxOne, address) { };
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-07-27 17:39:49 +00:00
|
|
|
Result initialize(void);
|
2020-07-11 11:43:21 +00:00
|
|
|
void convertReportFormat(const bluetooth::HidReport *inReport, bluetooth::HidReport *outReport);
|
2020-06-02 21:24:40 +00:00
|
|
|
|
|
|
|
private:
|
2020-06-09 20:39:30 +00:00
|
|
|
void handleInputReport0x01(const XboxOneReportData *src, SwitchReportData *dst);
|
2020-08-05 21:18:54 +00:00
|
|
|
//void handleInputReport0x02(const XboxOneReportData *src, SwitchReportData *dst);
|
2020-07-10 20:02:24 +00:00
|
|
|
void handleInputReport0x04(const XboxOneReportData *src, SwitchReportData *dst);
|
|
|
|
|
2020-06-02 21:24:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|