mc.mitm: change mapping of touchpad edges for sony controllers to avoid accidental activations of the capture button

This commit is contained in:
ndeadly 2023-05-14 23:38:23 +02:00
parent d3a01b6348
commit 669e4bc3e9
4 changed files with 85 additions and 9 deletions

View file

@ -26,6 +26,9 @@ namespace ams::controller {
constexpr float accel_scale_factor = 65535 / 16000.0f * 1000;
constexpr float gyro_scale_factor = 65535 / (13371 * 360.0f) * 1000;
constexpr u16 touchpad_width = 1920;
constexpr u16 touchpad_height = 1080;
const u8 player_led_flags[] = {
// Mimic the Switch's player LEDs
0x01,
@ -184,6 +187,25 @@ namespace ams::controller {
this->MapButtons(&src->input0x31.buttons);
if (src->input0x31.buttons.touchpad) {
for (int i = 0; i < 2; ++i) {
const DualsenseTouchpadPoint *point = &src->input0x31.touch_points[i];
bool active = point->contact & BIT(7) ? false : true;;
if (active) {
u16 x = (point->x_hi << 8) | point->x_lo;
if (x < (0.15 * touchpad_width)) {
m_buttons.minus = 1;
} else if (x > (0.85 * touchpad_width)) {
m_buttons.plus = 1;
} else {
m_buttons.capture = 1;
}
}
}
}
if (m_enable_motion) {
s16 acc_x = -static_cast<s16>(accel_scale_factor * src->input0x31.acc_z / float(m_motion_calibration.acc.z_max));
s16 acc_y = -static_cast<s16>(accel_scale_factor * src->input0x31.acc_x / float(m_motion_calibration.acc.x_max));

View file

@ -52,9 +52,11 @@ namespace ams::controller {
u8 R3 : 1;
u8 ps : 1;
u8 tpad : 1;
u8 touchpad : 1;
u8 mute : 1;
u8 : 0;
u8 unk;
} PACKED;
struct DualsenseRumbleData {
@ -87,6 +89,14 @@ namespace ams::controller {
} acc;
} PACKED;
struct DualsenseTouchpadPoint {
u8 contact;
u8 x_lo;
u8 x_hi : 4;
u8 y_lo : 4;
u8 y_hi;
} PACKED;
struct DualsenseVersionInfo {
char data[64];
} PACKED;
@ -123,14 +133,17 @@ namespace ams::controller {
u8 right_trigger;
u8 counter;
DualsenseButtonData buttons;
u8 _unk1[5];
u8 _unk1[4];
s16 vel_x;
s16 vel_y;
s16 vel_z;
s16 acc_x;
s16 acc_y;
s16 acc_z;
u8 _unk2[25];
s32 timestamp;
u8 _unk2;
DualsenseTouchpadPoint touch_points[2];
u8 _unk3[12];
u8 battery_level : 4;
u8 usb : 1;

View file

@ -27,6 +27,9 @@ namespace ams::controller {
constexpr float accel_scale_factor = 65535 / 16000.0f * 1000;
constexpr float gyro_scale_factor = 65535 / (13371 * 360.0f) * 1000;
constexpr u16 touchpad_width = 1920;
constexpr u16 touchpad_height = 942;
const RGBColour player_led_base_colours[] = {
// Same colours used by PS4
{0x00, 0x00, 0x04}, // blue
@ -147,6 +150,28 @@ namespace ams::controller {
this->MapButtons(&src->input0x11.buttons);
if (src->input0x11.buttons.touchpad) {
for (int i = 0; i < src->input0x11.num_reports; ++i) {
const Dualshock4TouchReport *touch_report = &src->input0x11.touch_reports[i];
for (int j = 0; j < 2; ++j) {
const Dualshock4TouchpadPoint *point = &touch_report->points[j];
bool active = point->contact & BIT(7) ? false : true;
if (active) {
u16 x = (point->x_hi << 8) | point->x_lo;
if (x < (0.15 * touchpad_width)) {
m_buttons.minus = 1;
} else if (x > (0.85 * touchpad_width)) {
m_buttons.plus = 1;
} else {
m_buttons.capture = 1;
}
}
}
}
}
if (m_enable_motion) {
s16 acc_x = -static_cast<s16>(accel_scale_factor * src->input0x11.acc_z / float(m_motion_calibration.acc.z_max));
s16 acc_y = -static_cast<s16>(accel_scale_factor * src->input0x11.acc_x / float(m_motion_calibration.acc.x_max));
@ -211,7 +236,6 @@ namespace ams::controller {
m_buttons.lstick_press = buttons->L3;
m_buttons.rstick_press = buttons->R3;
m_buttons.capture = buttons->tpad;
m_buttons.home = buttons->ps;
}

View file

@ -72,7 +72,7 @@ namespace ams::controller {
u8 R3 : 1;
u8 ps : 1;
u8 tpad : 1;
u8 touchpad : 1;
u8 counter : 6;
} PACKED;
@ -106,6 +106,19 @@ namespace ams::controller {
} acc;
} PACKED;
struct Dualshock4TouchpadPoint {
u8 contact;
u8 x_lo;
u8 x_hi : 4;
u8 y_lo : 4;
u8 y_hi;
} PACKED;
struct Dualshock4TouchReport {
u8 timestamp;
Dualshock4TouchpadPoint points[2];
} PACKED;
struct Dualshock4VersionInfo {
char date[48];
} PACKED;
@ -146,8 +159,9 @@ namespace ams::controller {
Dualshock4ButtonData buttons;
u8 left_trigger;
u8 right_trigger;
u16 timestamp;
u8 battery;
u8 temperature;
s16 vel_x;
s16 vel_y;
s16 vel_z;
@ -161,10 +175,13 @@ namespace ams::controller {
u8 mic : 1;
u8 phone : 1;
u8 : 0;
u8 _unk2[2];
u16 _unk2;
u8 tpad_packets;
u8 packet_counter;
u8 num_reports;
Dualshock4TouchReport touch_reports[4];
u8 _unk3[2];
u32 crc;
} PACKED;
struct Dualshock4ReportData {