Skip to content

Commit b35000b

Browse files
committed
Implement a custom option for DS4 polling rate
1 parent 5d4be97 commit b35000b

5 files changed

+19
-7
lines changed

common/controller_profiles.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct ControllerProfileConfig {
2424
struct {
2525
bool use_western_layout;
2626
uint32_t sony_led_brightness;
27+
uint32_t dualshock_reportrate;
2728
bool swap_dpad_lstick;
2829
bool invert_lstick_xaxis;
2930
bool invert_lstick_yaxis;
@@ -41,6 +42,7 @@ constexpr ControllerProfileConfig g_cp_global_config = {
4142
.misc = {
4243
.use_western_layout = false,
4344
.sony_led_brightness = 8,
45+
.dualshock_reportrate = 8,
4446
.swap_dpad_lstick = false,
4547
.invert_lstick_xaxis = false,
4648
.invert_lstick_yaxis = false,

mc_mitm/default.ini

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
;use_western_layout=false
1010
; Specify the LED lightbar brightness on Sony controllers (range 0(off)-63(max)) [default 8]
1111
;sony_led_brightness=8
12+
; Specifies a different polling rate value for DualShock 4 controllers (see https://github.com/ndeadly/MissionControl/blob/master/mc_mitm/source/controllers/dualshock4_controller.hpp#L21 for a list of valid values) [default 8(125hz)]
13+
;dualshock_reportrate=8
1214
; Map the dpad of the controller to the left stick and viceversa [default false]
1315
;swap_dpad_lstick=false
1416
; A series of stick axis reversal settings [default false]

mc_mitm/source/controllers/controller_profiles_management.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ namespace ams::controller {
3232
else *out = 8;
3333
}
3434

35+
void ValidateReportRate(const char *value, uint32_t *out){
36+
uint32_t temp=8;
37+
utils::ParseUInt32(value, &temp);
38+
if(temp <= 16)
39+
*out = temp;
40+
else *out = 8;
41+
}
42+
3543
int ControllerProfileIniHandler(void *user, const char *section, const char *name, const char *value) {
3644
auto config = reinterpret_cast<ControllerProfileConfig *>(user);
3745

@@ -46,6 +54,8 @@ namespace ams::controller {
4654
utils::ParseBoolean(value, &config->misc.use_western_layout);
4755
else if (strcasecmp(name, "sony_led_brightness") == 0)
4856
ValidateBrightness(value, &config->misc.sony_led_brightness);
57+
else if (strcasecmp(name, "dualshock_reportrate") == 0)
58+
ValidateReportRate(value, &config->misc.dualshock_reportrate);
4959
else if (strcasecmp(name, "swap_dpad_lstick") == 0)
5060
utils::ParseBoolean(value, &config->misc.swap_dpad_lstick);
5161
else if (strcasecmp(name, "invert_lstick_xaxis") == 0)

mc_mitm/source/controllers/dualshock4_controller.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ namespace ams::controller {
164164
}
165165

166166
Result Dualshock4Controller::PushRumbleLedState(void) {
167-
Dualshock4OutputReport0x11 report = {0xa2, 0x11, static_cast<uint8_t>(0xc0 | (m_report_rate & 0xff)), 0x20, 0xf3, 0x04, 0x00,
167+
Dualshock4OutputReport0x11 report = {0xa2, 0x11, static_cast<uint8_t>(0xc0 | (static_cast<Dualshock4ReportRate>(m_profile.misc.dualshock_reportrate) & 0xff)), 0x20, 0xf3, 0x04, 0x00,
168168
m_rumble_state.amp_motor_right, m_rumble_state.amp_motor_left,
169169
m_led_colour.r, m_led_colour.g, m_led_colour.b
170170
};

mc_mitm/source/controllers/dualshock4_controller.hpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace ams::controller {
6767
uint8_t cross : 1;
6868
uint8_t circle : 1;
6969
uint8_t triangle : 1;
70-
70+
7171
uint8_t L1 : 1;
7272
uint8_t R1 : 1;
7373
uint8_t L2 : 1;
@@ -76,7 +76,7 @@ namespace ams::controller {
7676
uint8_t options : 1;
7777
uint8_t L3 : 1;
7878
uint8_t R3 : 1;
79-
79+
8080
uint8_t ps : 1;
8181
uint8_t tpad : 1;
8282
uint8_t counter : 6;
@@ -151,7 +151,6 @@ namespace ams::controller {
151151

152152
Dualshock4Controller(const bluetooth::Address *address, HardwareID id)
153153
: EmulatedSwitchController(address, id)
154-
, m_report_rate(Dualshock4ReportRate_125Hz)
155154
, m_led_colour({0, 0, 0})
156155
, m_rumble_state({0, 0}) { }
157156

@@ -168,11 +167,10 @@ namespace ams::controller {
168167
void HandleInputReport0x11(const Dualshock4ReportData *src);
169168

170169
void MapButtons(const Dualshock4ButtonData *buttons);
171-
170+
172171
Result PushRumbleLedState(void);
173172

174-
Dualshock4ReportRate m_report_rate;
175-
RGBColour m_led_colour;
173+
RGBColour m_led_colour;
176174
Dualshock4RumbleData m_rumble_state;
177175
};
178176

0 commit comments

Comments
 (0)