mirror of
https://github.com/ndeadly/MissionControl
synced 2024-11-26 22:30:21 +00:00
mc.mitm: add methods for fetching and modifying packed switch analog stick data
This commit is contained in:
parent
29e7808fd0
commit
34698dbd53
22 changed files with 60 additions and 73 deletions
|
@ -55,11 +55,11 @@ namespace ams::controller {
|
||||||
(src->input0x01_v1.dpad == EightBitDoDPadV1_SW);
|
(src->input0x01_v1.dpad == EightBitDoDPadV1_SW);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01_v2.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01_v2.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x01_v2.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x01_v2.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01_v2.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01_v2.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x01_v2.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x01_v2.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -37,11 +37,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtGamesController::HandleInputReport0x01(const AtGamesReportData *src) {
|
void AtGamesController::HandleInputReport0x01(const AtGamesReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
STICK_ZERO + 0x7ff * (src->input0x01.nudge_left - src->input0x01.nudge_right),
|
STICK_ZERO + 0x7ff * (src->input0x01.nudge_left - src->input0x01.nudge_right),
|
||||||
STICK_ZERO
|
STICK_ZERO
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
STICK_ZERO,
|
STICK_ZERO,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.x)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.x)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -101,11 +101,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DualsenseController::HandleInputReport0x01(const DualsenseReportData *src) {
|
void DualsenseController::HandleInputReport0x01(const DualsenseReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
@ -127,11 +127,11 @@ namespace ams::controller {
|
||||||
|
|
||||||
m_battery = static_cast<uint8_t>(8 * (battery_level + 1) / 10) & 0x0e;
|
m_battery = static_cast<uint8_t>(8 * (battery_level + 1) / 10) & 0x0e;
|
||||||
|
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x31.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x31.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x31.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x31.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x31.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x31.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x31.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x31.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -90,11 +90,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dualshock4Controller::HandleInputReport0x01(const Dualshock4ReportData *src) {
|
void Dualshock4Controller::HandleInputReport0x01(const Dualshock4ReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
@ -116,11 +116,11 @@ namespace ams::controller {
|
||||||
|
|
||||||
m_battery = static_cast<uint8_t>(8 * (battery_level + 1) / 10) & 0x0e;
|
m_battery = static_cast<uint8_t>(8 * (battery_level + 1) / 10) & 0x0e;
|
||||||
|
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x11.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x11.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x11.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x11.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x11.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x11.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x11.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x11.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -98,8 +98,8 @@ namespace ams::controller {
|
||||||
|
|
||||||
void EmulatedSwitchController::ClearControllerState(void) {
|
void EmulatedSwitchController::ClearControllerState(void) {
|
||||||
std::memset(&m_buttons, 0, sizeof(m_buttons));
|
std::memset(&m_buttons, 0, sizeof(m_buttons));
|
||||||
m_left_stick = this->PackStickData(STICK_ZERO, STICK_ZERO);
|
m_left_stick.SetData(STICK_ZERO, STICK_ZERO);
|
||||||
m_right_stick = this->PackStickData(STICK_ZERO, STICK_ZERO);
|
m_right_stick.SetData(STICK_ZERO, STICK_ZERO);
|
||||||
std::memset(&m_motion_data, 0, sizeof(m_motion_data));
|
std::memset(&m_motion_data, 0, sizeof(m_motion_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,14 +39,6 @@ namespace ams::controller {
|
||||||
virtual Result CancelVibration(void) { return ams::ResultSuccess(); };
|
virtual Result CancelVibration(void) { return ams::ResultSuccess(); };
|
||||||
virtual Result SetPlayerLed(uint8_t led_mask) { return ams::ResultSuccess(); };
|
virtual Result SetPlayerLed(uint8_t led_mask) { return ams::ResultSuccess(); };
|
||||||
|
|
||||||
constexpr SwitchStickData PackStickData(uint16_t x, uint16_t y) {
|
|
||||||
return {
|
|
||||||
static_cast<uint8_t>(x & 0xff),
|
|
||||||
static_cast<uint8_t>((x >> 8) | ((y & 0xff) << 4)),
|
|
||||||
static_cast<uint8_t>((y >> 4) & 0xff)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Result HandleSubCmdReport(const bluetooth::HidReport *report);
|
Result HandleSubCmdReport(const bluetooth::HidReport *report);
|
||||||
Result HandleRumbleReport(const bluetooth::HidReport *report);
|
Result HandleRumbleReport(const bluetooth::HidReport *report);
|
||||||
|
|
||||||
|
@ -66,12 +58,12 @@ namespace ams::controller {
|
||||||
|
|
||||||
Result FakeSubCmdResponse(const SwitchSubcommandResponse *response);
|
Result FakeSubCmdResponse(const SwitchSubcommandResponse *response);
|
||||||
|
|
||||||
bool m_charging;
|
bool m_charging;
|
||||||
uint8_t m_battery;
|
uint8_t m_battery;
|
||||||
SwitchButtonData m_buttons;
|
SwitchButtonData m_buttons;
|
||||||
SwitchStickData m_left_stick;
|
SwitchAnalogStick m_left_stick;
|
||||||
SwitchStickData m_right_stick;
|
SwitchAnalogStick m_right_stick;
|
||||||
Switch6AxisData m_motion_data[3];
|
Switch6AxisData m_motion_data[3];
|
||||||
|
|
||||||
ProControllerColours m_colours;
|
ProControllerColours m_colours;
|
||||||
bool m_enable_rumble;
|
bool m_enable_rumble;
|
||||||
|
|
|
@ -44,11 +44,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamesirController::HandleInputReport0xc4(const GamesirReportData *src) {
|
void GamesirController::HandleInputReport0xc4(const GamesirReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0xc4.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0xc4.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0xc4.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0xc4.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0xc4.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0xc4.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0xc4.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0xc4.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -46,11 +46,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamestickController::HandleInputReport0x03(const GamestickReportData *src) {
|
void GamestickController::HandleInputReport0x03(const GamestickReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x03.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x03.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x03.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x03.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x03.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x03.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x03.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x03.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -45,11 +45,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GemboxController::HandleInputReport0x07(const GemboxReportData *src) {
|
void GemboxController::HandleInputReport0x07(const GemboxReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * -static_cast<int8_t>(~src->input0x07.left_stick.x + 1) + 0x7ff) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * -static_cast<int8_t>(~src->input0x07.left_stick.x + 1) + 0x7ff) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX + static_cast<int8_t>(~src->input0x07.left_stick.y + 1)) + 0x7ff) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX + static_cast<int8_t>(~src->input0x07.left_stick.y + 1)) + 0x7ff) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * -static_cast<int8_t>(~src->input0x07.right_stick.x + 1) + 0x7ff) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * -static_cast<int8_t>(~src->input0x07.right_stick.x + 1) + 0x7ff) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX + static_cast<int8_t>(~src->input0x07.right_stick.y + 1)) + 0x7ff) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX + static_cast<int8_t>(~src->input0x07.right_stick.y + 1)) + 0x7ff) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -44,11 +44,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void IpegaController::HandleInputReport0x07(const IpegaReportData *src) {
|
void IpegaController::HandleInputReport0x07(const IpegaReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x07.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x07.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x07.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x07.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x07.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x07.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x07.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x07.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -37,11 +37,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanShenController::HandleInputReport0x01(const LanShenReportData *src) {
|
void LanShenController::HandleInputReport0x01(const LanShenReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -40,11 +40,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MadCatzController::HandleInputReport0x01(const MadCatzReportData *src) {
|
void MadCatzController::HandleInputReport0x01(const MadCatzReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -39,11 +39,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MocuteController::HandleInputReport(const MocuteReportData *src) {
|
void MocuteController::HandleInputReport(const MocuteReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -40,11 +40,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NvidiaShieldController::HandleInputReport0x01(const NvidiaShieldReportData *src) {
|
void NvidiaShieldController::HandleInputReport0x01(const NvidiaShieldReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x01.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x01.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x01.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x01.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -45,11 +45,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OuyaController::HandleInputReport0x07(const OuyaReportData *src) {
|
void OuyaController::HandleInputReport0x07(const OuyaReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x07.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x07.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x07.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x07.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x07.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x07.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x07.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x07.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -40,11 +40,11 @@ namespace ams::controller {
|
||||||
void PowerAController::HandleInputReport0x03(const PowerAReportData *src) {
|
void PowerAController::HandleInputReport0x03(const PowerAReportData *src) {
|
||||||
m_battery = convert_battery_255(src->input0x03.battery);
|
m_battery = convert_battery_255(src->input0x03.battery);
|
||||||
|
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x03.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x03.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x03.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x03.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x03.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x03.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x03.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x03.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -37,11 +37,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RazerController::HandleInputReport0x01(const RazerReportData *src) {
|
void RazerController::HandleInputReport0x01(const RazerReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -45,11 +45,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SteelseriesController::HandleInputReport0x01(const SteelseriesReportData *src) {
|
void SteelseriesController::HandleInputReport0x01(const SteelseriesReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * -static_cast<int8_t>(~src->input0x01.left_stick.x + 1) + 0x7ff) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * -static_cast<int8_t>(~src->input0x01.left_stick.x + 1) + 0x7ff) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX + static_cast<int8_t>(~src->input0x01.left_stick.y + 1)) + 0x7ff) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX + static_cast<int8_t>(~src->input0x01.left_stick.y + 1)) + 0x7ff) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * -static_cast<int8_t>(~src->input0x01.right_stick.x + 1) + 0x7ff) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * -static_cast<int8_t>(~src->input0x01.right_stick.x + 1) + 0x7ff) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX + static_cast<int8_t>(~src->input0x01.right_stick.y + 1)) + 0x7ff) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX + static_cast<int8_t>(~src->input0x01.right_stick.y + 1)) + 0x7ff) & 0xfff
|
||||||
);
|
);
|
||||||
|
@ -84,11 +84,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SteelseriesController::HandleInputReport0xc4(const SteelseriesReportData *src) {
|
void SteelseriesController::HandleInputReport0xc4(const SteelseriesReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0xc4.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0xc4.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0xc4.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0xc4.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0xc4.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0xc4.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0xc4.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0xc4.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
@ -124,11 +124,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SteelseriesController::HandleMfiInputReport(const SteelseriesReportData *src) {
|
void SteelseriesController::HandleMfiInputReport(const SteelseriesReportData *src) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * -static_cast<int8_t>(~src->input_mfi.left_stick.x + 1) + 0x7ff) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * -static_cast<int8_t>(~src->input_mfi.left_stick.x + 1) + 0x7ff) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (-static_cast<int8_t>(~src->input_mfi.left_stick.y + 1)) + 0x7ff) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (-static_cast<int8_t>(~src->input_mfi.left_stick.y + 1)) + 0x7ff) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * -static_cast<int8_t>(~src->input_mfi.right_stick.x + 1) + 0x7ff) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * -static_cast<int8_t>(~src->input_mfi.right_stick.x + 1) + 0x7ff) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (-static_cast<int8_t>(~src->input_mfi.right_stick.y + 1)) + 0x7ff) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (-static_cast<int8_t>(~src->input_mfi.right_stick.y + 1)) + 0x7ff) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -14,13 +14,12 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "switch_analog_stick.hpp"
|
||||||
#include "../bluetooth_mitm/bluetooth/bluetooth_types.hpp"
|
#include "../bluetooth_mitm/bluetooth/bluetooth_types.hpp"
|
||||||
#include "../bluetooth_mitm/bluetooth/bluetooth_hid_report.hpp"
|
#include "../bluetooth_mitm/bluetooth/bluetooth_hid_report.hpp"
|
||||||
|
|
||||||
namespace ams::controller {
|
namespace ams::controller {
|
||||||
|
|
||||||
constexpr auto UINT12_MAX = 0xfff;
|
|
||||||
constexpr auto STICK_ZERO = 0x800;
|
|
||||||
constexpr auto BATTERY_MAX = 8;
|
constexpr auto BATTERY_MAX = 8;
|
||||||
|
|
||||||
enum SwitchPlayerNumber : uint8_t {
|
enum SwitchPlayerNumber : uint8_t {
|
||||||
|
@ -53,10 +52,6 @@ namespace ams::controller {
|
||||||
RGBColour right_grip;
|
RGBColour right_grip;
|
||||||
} __attribute__ ((__packed__));
|
} __attribute__ ((__packed__));
|
||||||
|
|
||||||
struct SwitchStickData {
|
|
||||||
uint8_t xy[3];
|
|
||||||
} __attribute__ ((__packed__));
|
|
||||||
|
|
||||||
struct SwitchButtonData {
|
struct SwitchButtonData {
|
||||||
uint8_t Y : 1;
|
uint8_t Y : 1;
|
||||||
uint8_t X : 1;
|
uint8_t X : 1;
|
||||||
|
@ -200,8 +195,8 @@ namespace ams::controller {
|
||||||
uint8_t conn_info : 4;
|
uint8_t conn_info : 4;
|
||||||
uint8_t battery : 4;
|
uint8_t battery : 4;
|
||||||
SwitchButtonData buttons;
|
SwitchButtonData buttons;
|
||||||
SwitchStickData left_stick;
|
SwitchAnalogStick left_stick;
|
||||||
SwitchStickData right_stick;
|
SwitchAnalogStick right_stick;
|
||||||
uint8_t vibrator;
|
uint8_t vibrator;
|
||||||
SwitchSubcommandResponse response;
|
SwitchSubcommandResponse response;
|
||||||
} __attribute__ ((__packed__));
|
} __attribute__ ((__packed__));
|
||||||
|
@ -213,8 +208,8 @@ namespace ams::controller {
|
||||||
uint8_t conn_info : 4;
|
uint8_t conn_info : 4;
|
||||||
uint8_t battery : 4;
|
uint8_t battery : 4;
|
||||||
SwitchButtonData buttons;
|
SwitchButtonData buttons;
|
||||||
SwitchStickData left_stick;
|
SwitchAnalogStick left_stick;
|
||||||
SwitchStickData right_stick;
|
SwitchAnalogStick right_stick;
|
||||||
uint8_t vibrator;
|
uint8_t vibrator;
|
||||||
|
|
||||||
// IMU samples at 0, 5 and 10ms
|
// IMU samples at 0, 5 and 10ms
|
||||||
|
|
|
@ -220,7 +220,7 @@ namespace ams::controller {
|
||||||
void WiiController::MapNunchuckExtension(const uint8_t ext[]) {
|
void WiiController::MapNunchuckExtension(const uint8_t ext[]) {
|
||||||
auto extension = reinterpret_cast<const WiiNunchuckExtensionData *>(ext);
|
auto extension = reinterpret_cast<const WiiNunchuckExtensionData *>(ext);
|
||||||
|
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
std::clamp<uint16_t>(static_cast<uint16_t>(nunchuck_stick_scale_factor * (extension->stick_x - 0x80) + STICK_ZERO), 0, 0xfff),
|
std::clamp<uint16_t>(static_cast<uint16_t>(nunchuck_stick_scale_factor * (extension->stick_x - 0x80) + STICK_ZERO), 0, 0xfff),
|
||||||
std::clamp<uint16_t>(static_cast<uint16_t>(nunchuck_stick_scale_factor * (extension->stick_y - 0x80) + STICK_ZERO), 0, 0xfff)
|
std::clamp<uint16_t>(static_cast<uint16_t>(nunchuck_stick_scale_factor * (extension->stick_y - 0x80) + STICK_ZERO), 0, 0xfff)
|
||||||
);
|
);
|
||||||
|
@ -230,11 +230,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiiController::MapClassicControllerExtension(const uint8_t ext[]) {
|
void WiiController::MapClassicControllerExtension(const uint8_t ext[]) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(left_stick_scale_factor * ((ext[0] & 0x3f) - 0x20) + STICK_ZERO) & 0xfff,
|
static_cast<uint16_t>(left_stick_scale_factor * ((ext[0] & 0x3f) - 0x20) + STICK_ZERO) & 0xfff,
|
||||||
static_cast<uint16_t>(left_stick_scale_factor * ((ext[1] & 0x3f) - 0x20) + STICK_ZERO) & 0xfff
|
static_cast<uint16_t>(left_stick_scale_factor * ((ext[1] & 0x3f) - 0x20) + STICK_ZERO) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(right_stick_scale_factor * ((((ext[0] >> 3) & 0x18) | ((ext[1] >> 5) & 0x06) | ((ext[2] >> 7) & 0x01)) - 0x10) + STICK_ZERO) & 0xfff,
|
static_cast<uint16_t>(right_stick_scale_factor * ((((ext[0] >> 3) & 0x18) | ((ext[1] >> 5) & 0x06) | ((ext[2] >> 7) & 0x01)) - 0x10) + STICK_ZERO) & 0xfff,
|
||||||
static_cast<uint16_t>(right_stick_scale_factor * ((ext[2] & 0x1f) - 0x10) + STICK_ZERO) & 0xfff
|
static_cast<uint16_t>(right_stick_scale_factor * ((ext[2] & 0x1f) - 0x10) + STICK_ZERO) & 0xfff
|
||||||
);
|
);
|
||||||
|
@ -265,11 +265,11 @@ namespace ams::controller {
|
||||||
void WiiController::MapWiiUProControllerExtension(const uint8_t ext[]) {
|
void WiiController::MapWiiUProControllerExtension(const uint8_t ext[]) {
|
||||||
auto extension = reinterpret_cast<const WiiUProExtensionData *>(ext);
|
auto extension = reinterpret_cast<const WiiUProExtensionData *>(ext);
|
||||||
|
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
std::clamp<uint16_t>(((wiiu_scale_factor * (extension->left_stick_x - STICK_ZERO))) + STICK_ZERO, 0, 0xfff),
|
std::clamp<uint16_t>(((wiiu_scale_factor * (extension->left_stick_x - STICK_ZERO))) + STICK_ZERO, 0, 0xfff),
|
||||||
std::clamp<uint16_t>(((wiiu_scale_factor * (extension->left_stick_y - STICK_ZERO))) + STICK_ZERO, 0, 0xfff)
|
std::clamp<uint16_t>(((wiiu_scale_factor * (extension->left_stick_y - STICK_ZERO))) + STICK_ZERO, 0, 0xfff)
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
std::clamp<uint16_t>(((wiiu_scale_factor * (extension->right_stick_x - STICK_ZERO))) + STICK_ZERO, 0, 0xfff),
|
std::clamp<uint16_t>(((wiiu_scale_factor * (extension->right_stick_x - STICK_ZERO))) + STICK_ZERO, 0, 0xfff),
|
||||||
std::clamp<uint16_t>(((wiiu_scale_factor * (extension->right_stick_y - STICK_ZERO))) + STICK_ZERO, 0, 0xfff)
|
std::clamp<uint16_t>(((wiiu_scale_factor * (extension->right_stick_y - STICK_ZERO))) + STICK_ZERO, 0, 0xfff)
|
||||||
);
|
);
|
||||||
|
|
|
@ -58,11 +58,11 @@ namespace ams::controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void XboxOneController::HandleInputReport0x01(const XboxOneReportData *src, bool new_format) {
|
void XboxOneController::HandleInputReport0x01(const XboxOneReportData *src, bool new_format) {
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x01.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x01.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x01.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT16_MAX - src->input0x01.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
|
@ -50,11 +50,11 @@ namespace ams::controller {
|
||||||
void XiaomiController::HandleInputReport0x04(const XiaomiReportData *src) {
|
void XiaomiController::HandleInputReport0x04(const XiaomiReportData *src) {
|
||||||
m_battery = convert_battery_100(src->input0x04.battery);
|
m_battery = convert_battery_100(src->input0x04.battery);
|
||||||
|
|
||||||
m_left_stick = this->PackStickData(
|
m_left_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x04.left_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x04.left_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x04.left_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x04.left_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
m_right_stick = this->PackStickData(
|
m_right_stick.SetData(
|
||||||
static_cast<uint16_t>(stick_scale_factor * src->input0x04.right_stick.x) & 0xfff,
|
static_cast<uint16_t>(stick_scale_factor * src->input0x04.right_stick.x) & 0xfff,
|
||||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x04.right_stick.y)) & 0xfff
|
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x04.right_stick.y)) & 0xfff
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue