2020-06-09 20:39:30 +00:00
|
|
|
#include <cstring>
|
2020-06-17 23:36:56 +00:00
|
|
|
#include <stratosphere.hpp>
|
2020-06-09 20:39:30 +00:00
|
|
|
|
2020-06-02 21:24:40 +00:00
|
|
|
#include "xboxone.hpp"
|
|
|
|
|
|
|
|
namespace controller {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-07-01 13:21:05 +00:00
|
|
|
const constexpr float scale_factor = float(UINT12_MAX) / UINT16_MAX;
|
2020-06-02 21:24:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-10 21:15:26 +00:00
|
|
|
XboxOneController::XboxOneController(const BluetoothAddress *address)
|
|
|
|
: BluetoothController(ControllerType_XboxOne, address) {
|
2020-06-30 21:19:05 +00:00
|
|
|
|
2020-06-10 21:15:26 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 20:39:30 +00:00
|
|
|
void XboxOneController::convertReportFormat(const HidReport *inReport, HidReport *outReport) {
|
|
|
|
auto xboxData = reinterpret_cast<const XboxOneReportData *>(&inReport->data);
|
|
|
|
auto switchData = reinterpret_cast<SwitchReportData *>(&outReport->data);
|
|
|
|
|
|
|
|
outReport->type = 0x31;
|
|
|
|
outReport->id = 0x30;
|
|
|
|
|
|
|
|
switchData->report0x30.conn_info = 0x0;
|
|
|
|
switchData->report0x30.battery = 0x8;
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-06-09 20:39:30 +00:00
|
|
|
switch(inReport->id) {
|
2020-06-02 21:24:40 +00:00
|
|
|
case 0x01:
|
2020-06-09 20:39:30 +00:00
|
|
|
handleInputReport0x01(xboxData, switchData);
|
2020-06-02 21:24:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x02:
|
2020-06-09 20:39:30 +00:00
|
|
|
handleInputReport0x02(xboxData, switchData);
|
2020-06-02 21:24:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 20:39:30 +00:00
|
|
|
void XboxOneController::handleInputReport0x01(const XboxOneReportData *src, SwitchReportData *dst) {
|
2020-07-01 23:34:13 +00:00
|
|
|
packStickData(&dst->report0x30.left_stick,
|
|
|
|
static_cast<uint16_t>(scale_factor * src->report0x01.left_stick.x) & 0xfff,
|
|
|
|
static_cast<uint16_t>(scale_factor * (UINT16_MAX - src->report0x01.left_stick.y)) & 0xfff
|
|
|
|
);
|
|
|
|
packStickData(&dst->report0x30.right_stick,
|
|
|
|
static_cast<uint16_t>(scale_factor * src->report0x01.right_stick.x) & 0xfff,
|
|
|
|
static_cast<uint16_t>(scale_factor * (UINT16_MAX - src->report0x01.right_stick.y)) & 0xfff
|
|
|
|
);
|
2020-07-01 13:21:05 +00:00
|
|
|
|
2020-06-09 20:39:30 +00:00
|
|
|
dst->report0x30.buttons.dpad_down = (src->report0x01.buttons.dpad == XboxOneDPad_S) ||
|
|
|
|
(src->report0x01.buttons.dpad == XboxOneDPad_SE) ||
|
|
|
|
(src->report0x01.buttons.dpad == XboxOneDPad_SW);
|
|
|
|
dst->report0x30.buttons.dpad_up = (src->report0x01.buttons.dpad == XboxOneDPad_N) ||
|
|
|
|
(src->report0x01.buttons.dpad == XboxOneDPad_NE) ||
|
|
|
|
(src->report0x01.buttons.dpad == XboxOneDPad_NW);
|
|
|
|
dst->report0x30.buttons.dpad_right = (src->report0x01.buttons.dpad == XboxOneDPad_E) ||
|
|
|
|
(src->report0x01.buttons.dpad == XboxOneDPad_NE) ||
|
|
|
|
(src->report0x01.buttons.dpad == XboxOneDPad_SE);
|
|
|
|
dst->report0x30.buttons.dpad_left = (src->report0x01.buttons.dpad == XboxOneDPad_W) ||
|
|
|
|
(src->report0x01.buttons.dpad == XboxOneDPad_NW) ||
|
|
|
|
(src->report0x01.buttons.dpad == XboxOneDPad_SW);
|
|
|
|
|
|
|
|
dst->report0x30.buttons.A = src->report0x01.buttons.B;
|
|
|
|
dst->report0x30.buttons.B = src->report0x01.buttons.A;
|
|
|
|
dst->report0x30.buttons.X = src->report0x01.buttons.Y;
|
|
|
|
dst->report0x30.buttons.Y = src->report0x01.buttons.X;
|
|
|
|
|
|
|
|
dst->report0x30.buttons.R = src->report0x01.buttons.RB;
|
|
|
|
dst->report0x30.buttons.ZR = src->report0x01.right_trigger > 0;
|
|
|
|
dst->report0x30.buttons.L = src->report0x01.buttons.LB;
|
|
|
|
dst->report0x30.buttons.ZL = src->report0x01.left_trigger > 0;
|
|
|
|
|
|
|
|
dst->report0x30.buttons.minus = src->report0x01.buttons.view;
|
|
|
|
dst->report0x30.buttons.plus = src->report0x01.buttons.menu;
|
|
|
|
|
|
|
|
dst->report0x30.buttons.lstick_press = src->report0x01.buttons.lstick_press;
|
|
|
|
dst->report0x30.buttons.rstick_press = src->report0x01.buttons.rstick_press;
|
2020-07-01 13:27:02 +00:00
|
|
|
|
|
|
|
dst->report0x30.buttons.capture = 0;
|
2020-06-02 21:24:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 20:39:30 +00:00
|
|
|
void XboxOneController::handleInputReport0x02(const XboxOneReportData *src, SwitchReportData *dst) {
|
2020-07-01 13:27:02 +00:00
|
|
|
std::memset(&dst->report0x30.buttons, 0, sizeof(SwitchButtonData));
|
2020-06-09 20:39:30 +00:00
|
|
|
dst->report0x30.buttons.home = src->report0x02.guide;
|
2020-06-02 21:24:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|