mc.mitm: add setting for analog trigger activation threshold

This commit is contained in:
ndeadly 2023-05-16 23:17:58 +02:00
parent 669e4bc3e9
commit 5e7b06915e
24 changed files with 106 additions and 86 deletions

View file

@ -140,6 +140,7 @@ These settings can be used to spoof your switch bluetooth to appear as another d
- `[misc]`
These are miscellaneous controller-specific settings etc.
- `analog_trigger_activation_threshold` Set the threshold for which ZL/ZR are considered pressed for controllers with analog triggers. Valid range [0-100] percent.
- `dualshock3_led_mode` Set Dualshock 3 player LED behaviour. Valid modes [0-1] where 0=Switch pattern, 1=PS3 pattern, 2=Hybrid (Switch pattern reversed to line up with numeric labels on the controller)
- `dualshock4_polling_rate` Set polling rate for Sony Dualshock 4 controllers. Valid range [0-16] where 0=max, 16=min. Refer [here](https://github.com/ndeadly/MissionControl/blob/4a0326308d1ff39353b045f5efb1a99c4a504c28/mc_mitm/source/controllers/dualshock4_controller.hpp#L21) for corresponding frequency values.
- `dualshock4_lightbar_brightness` Set LED lightbar brightness for Sony Dualshock 4 controllers. Valid range [0-9] where 0=off, 1=min, 2-9=12.5-100% in 12.5% increments.

View file

@ -11,6 +11,8 @@
;host_address=04:20:69:04:20:69
[misc]
; Set the threshold for which ZL/ZR are considered pressed for controllers with analog triggers. Valid range [0-100] percent [default 50]
;analog_trigger_activation_threshold=50
; Set Dualshock 3 player LED behaviour. Valid modes [0-2] where 0=Switch pattern, 1=PS3 pattern, 2=Hybrid (Switch pattern reversed to line up with numeric labels on the controller) [default 0]
;dualshock3_led_mode=0
; Set polling rate for Sony Dualshock 4 controllers. Valid range [0-16] where 0=max, 16=min [default 8 (125Hz)]

View file

@ -82,10 +82,10 @@ namespace ams::controller {
m_buttons.L = src->input0x01_v2.buttons.L1;
m_buttons.R = src->input0x01_v2.buttons.R1;
if (m_controller_type == EightBitDoControllerType_Sn30ProXboxCloud) {
m_buttons.ZL = src->input0x01_v2.left_trigger > 0x7f;
m_buttons.ZR = src->input0x01_v2.right_trigger > 0x7f;
m_buttons.ZL = src->input0x01_v2.left_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.ZR = src->input0x01_v2.right_trigger > (m_trigger_threshold * UINT8_MAX);
if (m_controller_type == EightBitDoControllerType_Sn30ProXboxCloud) {
m_buttons.minus = src->input0x01_v2.buttons.v1.select;
m_buttons.plus = src->input0x01_v2.buttons.v1.start;
@ -94,9 +94,6 @@ namespace ams::controller {
m_buttons.home = src->input0x01_v2.buttons.v1.home;
} else {
m_buttons.ZL = src->input0x01_v2.buttons.v2.L2;
m_buttons.ZR = src->input0x01_v2.buttons.v2.R2;
m_buttons.minus = src->input0x01_v2.buttons.v2.select;
m_buttons.plus = src->input0x01_v2.buttons.v2.start;

View file

@ -155,6 +155,9 @@ namespace ams::controller {
);
this->MapButtons(&src->input0x01.buttons);
m_buttons.ZR = src->input0x01.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.ZL = src->input0x01.left_trigger > (m_trigger_threshold * UINT8_MAX);
}
void DualsenseController::MapInputReport0x31(const DualsenseReportData *src) {
@ -187,6 +190,9 @@ namespace ams::controller {
this->MapButtons(&src->input0x31.buttons);
m_buttons.ZR = src->input0x31.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.ZL = src->input0x31.left_trigger > (m_trigger_threshold * UINT8_MAX);
if (src->input0x31.buttons.touchpad) {
for (int i = 0; i < 2; ++i) {
const DualsenseTouchpadPoint *point = &src->input0x31.touch_points[i];
@ -260,9 +266,7 @@ namespace ams::controller {
m_buttons.Y = buttons->square;
m_buttons.R = buttons->R1;
m_buttons.ZR = buttons->R2;
m_buttons.L = buttons->L1;
m_buttons.ZL = buttons->L2;
m_buttons.minus = buttons->share;
m_buttons.plus = buttons->options;

View file

@ -265,9 +265,9 @@ namespace ams::controller {
m_buttons.Y = src->input0x01.buttons.square;
m_buttons.R = src->input0x01.buttons.R1;
m_buttons.ZR = src->input0x01.buttons.R2;
m_buttons.ZR = src->input0x01.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.L = src->input0x01.buttons.L1;
m_buttons.ZL = src->input0x01.buttons.L2;
m_buttons.ZL = src->input0x01.left_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.minus = src->input0x01.buttons.select;
m_buttons.plus = src->input0x01.buttons.start;

View file

@ -118,6 +118,9 @@ namespace ams::controller {
);
this->MapButtons(&src->input0x01.buttons);
m_buttons.ZR = src->input0x01.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.ZL = src->input0x01.left_trigger > (m_trigger_threshold * UINT8_MAX);
}
void Dualshock4Controller::MapInputReport0x11(const Dualshock4ReportData *src) {
@ -150,6 +153,9 @@ namespace ams::controller {
this->MapButtons(&src->input0x11.buttons);
m_buttons.ZR = src->input0x11.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.ZL = src->input0x11.left_trigger > (m_trigger_threshold * UINT8_MAX);
if (src->input0x11.buttons.touchpad) {
for (int i = 0; i < src->input0x11.num_reports; ++i) {
const Dualshock4TouchReport *touch_report = &src->input0x11.touch_reports[i];

View file

@ -132,6 +132,7 @@ namespace ams::controller {
auto config = mitm::GetGlobalConfig();
m_enable_rumble = config->general.enable_rumble;
m_enable_motion = config->general.enable_motion;
m_trigger_threshold = config->misc.analog_trigger_activation_threshold / 100.0;
};
Result EmulatedSwitchController::Initialize() {

View file

@ -83,6 +83,8 @@ namespace ams::controller {
bool m_enable_rumble;
bool m_enable_motion;
float m_trigger_threshold;
VirtualSpiFlash m_virtual_memory;
};

View file

@ -68,9 +68,9 @@ namespace ams::controller {
m_buttons.Y = src->input0x03.buttons.X;
m_buttons.R = src->input0x03.buttons.RB;
m_buttons.ZR = src->input0x03.buttons.RT;
m_buttons.ZR = src->input0x03.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.L = src->input0x03.buttons.LB;
m_buttons.ZL = src->input0x03.buttons.LT;
m_buttons.ZL = src->input0x03.left_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.minus = src->input0x03.buttons.select;
m_buttons.plus = src->input0x03.buttons.start;
@ -114,9 +114,9 @@ namespace ams::controller {
m_buttons.Y = src->input0xc4.buttons.X;
m_buttons.R = src->input0xc4.buttons.RB;
m_buttons.ZR = src->input0xc4.buttons.RT;
m_buttons.ZR = src->input0xc4.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.L = src->input0xc4.buttons.LB;
m_buttons.ZL = src->input0xc4.buttons.LT;
m_buttons.ZL = src->input0xc4.left_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.minus = src->input0xc4.buttons.select;
m_buttons.plus = src->input0xc4.buttons.start;

View file

@ -71,9 +71,9 @@ namespace ams::controller {
m_buttons.Y = src->input0x07.buttons.X;
m_buttons.R = src->input0x07.buttons.RB;
m_buttons.ZR = src->input0x07.right_trigger > 0;
m_buttons.ZR = src->input0x07.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.L = src->input0x07.buttons.LB;
m_buttons.ZL = src->input0x07.left_trigger > 0;
m_buttons.ZL = src->input0x07.left_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.plus = src->input0x07.buttons.start;

View file

@ -70,9 +70,9 @@ namespace ams::controller {
m_buttons.Y = src->input0x07.buttons.X;
m_buttons.R = src->input0x07.buttons.RB;
m_buttons.ZR = src->input0x07.buttons.RT;
m_buttons.ZR = src->input0x07.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.L = src->input0x07.buttons.LB;
m_buttons.ZL = src->input0x07.buttons.LT;
m_buttons.ZL = src->input0x07.left_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.minus = src->input0x07.buttons.view;
m_buttons.plus = src->input0x07.buttons.menu;

View file

@ -73,9 +73,9 @@ namespace ams::controller {
m_buttons.Y = src->input0x01.buttons.X;
m_buttons.R = src->input0x01.buttons.R1;
m_buttons.ZR = src->input0x01.right_trigger > 0;
m_buttons.ZR = src->input0x01.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.L = src->input0x01.buttons.L1;
m_buttons.ZL = src->input0x01.left_trigger > 0;
m_buttons.ZL = src->input0x01.left_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.minus = src->input0x01.buttons.select;
m_buttons.plus = src->input0x01.buttons.start;
@ -120,9 +120,9 @@ namespace ams::controller {
m_buttons.Y = src->input0x81.buttons.X;
m_buttons.R = src->input0x81.buttons.R1;
m_buttons.ZR = src->input0x81.right_trigger > 0;
m_buttons.ZR = src->input0x81.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.L = src->input0x81.buttons.L1;
m_buttons.ZL = src->input0x81.left_trigger > 0;
m_buttons.ZL = src->input0x81.left_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.minus = src->input0x81.buttons.select;
m_buttons.plus = src->input0x81.buttons.start;

View file

@ -77,73 +77,73 @@ namespace ams::controller {
struct {
union {
struct {
uint8_t A : 1;
uint8_t B : 1;
uint8_t X : 1;
uint8_t Y : 1;
uint8_t L1 : 1;
uint8_t R1 : 1;
uint8_t select : 1;
uint8_t start : 1;
u8 A : 1;
u8 B : 1;
u8 X : 1;
u8 Y : 1;
u8 L1 : 1;
u8 R1 : 1;
u8 select : 1;
u8 start : 1;
uint8_t L3 : 1;
uint8_t R3 : 1;
uint8_t : 0;
u8 L3 : 1;
u8 R3 : 1;
u8 : 0;
};
struct {
uint8_t A : 1;
uint8_t B : 1;
uint8_t : 1;
uint8_t X : 1;
uint8_t Y : 1;
uint8_t : 1;
uint8_t L1 : 1;
uint8_t R1 : 1;
u8 A : 1;
u8 B : 1;
u8 : 1;
u8 X : 1;
u8 Y : 1;
u8 : 1;
u8 L1 : 1;
u8 R1 : 1;
uint8_t : 3;
uint8_t start : 1;
uint8_t : 1;
uint8_t L3 : 1;
uint8_t R3 : 1;
uint8_t : 0;
u8 : 3;
u8 start : 1;
u8 : 1;
u8 L3 : 1;
u8 R3 : 1;
u8 : 0;
} xinput;
};
uint8_t dpad;
u8 dpad;
} buttons;
MadCatzStickData left_stick;
MadCatzStickData right_stick;
uint8_t left_trigger;
uint8_t right_trigger;
uint8_t reserved;
u8 left_trigger;
u8 right_trigger;
u8 reserved;
} PACKED;
struct MadCatzInputReport0x82 {
struct {
uint8_t : 2;
uint8_t R1 : 1;
uint8_t L1 : 1;
uint8_t Y : 1;
uint8_t B : 1;
uint8_t X : 1;
uint8_t select : 1;
u8 : 2;
u8 R1 : 1;
u8 L1 : 1;
u8 Y : 1;
u8 B : 1;
u8 X : 1;
u8 select : 1;
uint8_t dpad;
u8 dpad;
} buttons;
uint8_t reserved;
u8 reserved;
} PACKED;
struct MadCatzInputReport0x83 {
struct {
uint8_t R2 : 1;
uint8_t L2 : 1;
uint8_t R3 : 1;
uint8_t L3 : 1;
uint8_t : 0;
u8 R2 : 1;
u8 L2 : 1;
u8 R3 : 1;
u8 L3 : 1;
u8 : 0;
} buttons;
MadCatzStickData left_stick;
uint8_t reserved[2];
u8 reserved[2];
} PACKED;
struct MadCatzReportData {

View file

@ -59,11 +59,17 @@ namespace ams::controller {
void MocuteController::MapInputReport0x01(const MocuteReportData *src) {
this->MapAnalogSticks(&src->input0x01.left_stick, &src->input0x01.right_stick);
this->MapButtons(&src->input0x01.buttons, src->id == 0x01);
m_buttons.ZR = src->input0x01.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.ZL = src->input0x01.left_trigger > (m_trigger_threshold * UINT8_MAX);
}
void MocuteController::MapInputReport0x04(const MocuteReportData *src) {
this->MapAnalogSticks(&src->input0x04.left_stick, &src->input0x04.right_stick);
this->MapButtons(&src->input0x04.buttons, 1);
m_buttons.ZR = src->input0x04.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.ZL = src->input0x04.left_trigger > (m_trigger_threshold * UINT8_MAX);
}
void MocuteController::MapAnalogSticks(const MocuteStickData *left_stick, const MocuteStickData *right_stick) {
@ -103,9 +109,7 @@ namespace ams::controller {
m_buttons.Y = buttons->X;
m_buttons.R = buttons->R1;
m_buttons.ZR = buttons->R2;
m_buttons.L = buttons->L1;
m_buttons.ZL = buttons->L2;
m_buttons.minus = buttons->select;
m_buttons.plus = buttons->start;

View file

@ -66,9 +66,9 @@ namespace ams::controller {
m_buttons.Y = src->input0x01.buttons.X;
m_buttons.R = src->input0x01.buttons.RB;
m_buttons.ZR = src->input0x01.right_trigger > 0;
m_buttons.ZR = src->input0x01.right_trigger > (m_trigger_threshold * UINT16_MAX);
m_buttons.L = src->input0x01.buttons.LB;
m_buttons.ZL = src->input0x01.left_trigger > 0;
m_buttons.ZL = src->input0x01.left_trigger > (m_trigger_threshold * UINT16_MAX);
m_buttons.minus = src->input0x01.back;
m_buttons.plus = src->input0x01.buttons.start;

View file

@ -63,9 +63,9 @@ namespace ams::controller {
m_buttons.Y = src->input0x07.buttons.U;
m_buttons.R = src->input0x07.buttons.RB;
m_buttons.ZR = src->input0x07.buttons.RT;
m_buttons.ZR = src->input0x07.right_trigger > (m_trigger_threshold * UINT16_MAX);
m_buttons.L = src->input0x07.buttons.LB;
m_buttons.ZL = src->input0x07.buttons.LT;
m_buttons.ZL = src->input0x07.left_trigger > (m_trigger_threshold * UINT16_MAX);
m_buttons.minus = 0;
m_buttons.plus = 0;

View file

@ -64,9 +64,9 @@ namespace ams::controller {
m_buttons.Y = src->input0x01.buttons.X;
m_buttons.R = src->input0x01.buttons.R1;
m_buttons.ZR = src->input0x01.right_trigger > 0;
m_buttons.ZR = src->input0x01.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.L = src->input0x01.buttons.L1;
m_buttons.ZL = src->input0x01.left_trigger > 0;
m_buttons.ZL = src->input0x01.left_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.minus = src->input0x01.buttons.select;
m_buttons.plus = src->input0x01.buttons.start;

View file

@ -160,9 +160,9 @@ namespace ams::controller {
m_buttons.Y = src->input0xc4.buttons.X;
m_buttons.R = src->input0xc4.buttons.R1;
m_buttons.ZR = src->input0xc4.buttons.R2;
m_buttons.ZR = src->input0xc4.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.L = src->input0xc4.buttons.L1;
m_buttons.ZL = src->input0xc4.buttons.L2;
m_buttons.ZL = src->input0xc4.left_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.lstick_press = src->input0xc4.buttons.L3;
m_buttons.rstick_press = src->input0xc4.buttons.R3;

View file

@ -298,9 +298,9 @@ namespace ams::controller {
m_buttons.X = !extension_data->buttons.X;
m_buttons.Y = !extension_data->buttons.Y;
m_buttons.L = !extension_data->buttons.L | (((extension_data->left_trigger_43 << 3) | (extension_data->left_trigger_20)) > 0x0f);
m_buttons.L = !extension_data->buttons.L | (((extension_data->left_trigger_43 << 3) | (extension_data->left_trigger_20)) > (m_trigger_threshold * 0x1f));
m_buttons.ZL = !extension_data->buttons.ZL;
m_buttons.R = !extension_data->buttons.R | (extension_data->right_trigger > 0x0f);
m_buttons.R = !extension_data->buttons.R | (extension_data->right_trigger > (m_trigger_threshold * 0x1f));
m_buttons.ZR = !extension_data->buttons.ZR;
m_buttons.minus |= !extension_data->buttons.minus;
@ -474,9 +474,9 @@ namespace ams::controller {
m_buttons.X = !extension_data->buttons.X;
m_buttons.Y = !extension_data->buttons.Y;
m_buttons.L = !extension_data->buttons.L | (((extension_data->left_trigger_43 << 3) | (extension_data->left_trigger_20)) > 0x0f);
m_buttons.L = !extension_data->buttons.L | (((extension_data->left_trigger_43 << 3) | (extension_data->left_trigger_20)) > (m_trigger_threshold * 0x1f));
m_buttons.ZL = !extension_data->buttons.ZL;
m_buttons.R = !extension_data->buttons.R | (extension_data->right_trigger > 0x0f);
m_buttons.R = !extension_data->buttons.R | (extension_data->right_trigger > (m_trigger_threshold * 0x1f));
m_buttons.ZR = !extension_data->buttons.ZR;
m_buttons.minus |= !extension_data->buttons.minus;

View file

@ -63,8 +63,8 @@ namespace ams::controller {
static_cast<u16>(stick_scale_factor * (UINT16_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
);
m_buttons.ZR = src->input0x01.right_trigger > 0;
m_buttons.ZL = src->input0x01.left_trigger > 0;
m_buttons.ZR = src->input0x01.right_trigger > (m_trigger_threshold * 0x3ff);
m_buttons.ZL = src->input0x01.left_trigger > (m_trigger_threshold * 0x3ff);
if (new_format) {
m_buttons.dpad_down = (src->input0x01.buttons.dpad == XboxOneDPad_S) ||

View file

@ -81,9 +81,9 @@ namespace ams::controller {
m_buttons.Y = src->input0x04.buttons.X;
m_buttons.R = src->input0x04.buttons.R1;
m_buttons.ZR = src->input0x04.buttons.R2;
m_buttons.ZR = src->input0x04.right_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.L = src->input0x04.buttons.L1;
m_buttons.ZL = src->input0x04.buttons.L2;
m_buttons.ZL = src->input0x04.left_trigger > (m_trigger_threshold * UINT8_MAX);
m_buttons.minus = src->input0x04.buttons.back;
m_buttons.plus = src->input0x04.buttons.menu;

View file

@ -97,7 +97,6 @@ namespace ams::controller {
private:
void MapInputReport0x04(const XiaomiReportData *src);
};
}

View file

@ -30,6 +30,7 @@ namespace ams::mitm {
.enable_motion = true
},
.misc = {
.analog_trigger_activation_threshold = 50,
.dualshock3_led_mode = 0,
.dualshock4_polling_rate = 8,
.dualshock4_lightbar_brightness = 5,
@ -92,7 +93,9 @@ namespace ams::mitm {
ParseBluetoothAddress(value, &config->bluetooth.host_address);
}
} else if (strcasecmp(section, "misc") == 0) {
if (strcasecmp(name, "dualshock3_led_mode") == 0) {
if (strcasecmp(name, "analog_trigger_activation_threshold") == 0) {
ParseInt(value, &config->misc.analog_trigger_activation_threshold, 0, 100);
} else if (strcasecmp(name, "dualshock3_led_mode") == 0) {
ParseInt(value, &config->misc.dualshock3_led_mode, 0, 2);
} else if (strcasecmp(name, "dualshock4_polling_rate") == 0) {
ParseInt(value, &config->misc.dualshock4_polling_rate, 0, 16);

View file

@ -29,6 +29,7 @@ namespace ams::mitm {
} bluetooth;
struct {
int analog_trigger_activation_threshold;
int dualshock3_led_mode;
int dualshock4_polling_rate;
int dualshock4_lightbar_brightness;