Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ These are miscellaneous controller-specific settings etc.
- `dualsense_lightbar_brightness` Set LED lightbar brightness for Sony Dualsense controllers. Valid range [0-9] where 0=off, 1=min, 2-9=12.5-100% in 12.5% increments.
- `dualsense_enable_player_leds` Enable/disable the white player indicator LEDs below the Dualsense touchpad.
- `dualsense_vibration_intensity` Set Dualsense vibration intensity, 12.5% per increment. Valid range [1-8] where 1=12.5%, 8=100%.
- `dualsense_enable_adaptive_triggers` Enable/disable adaptive triggers for Dualsense.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for an additional enable option. You can just make the numbers run 0-10, where 0 is disabled.

- `dualsense_adaptive_triggers_resistance` Set Dualsense adaptive triggers resistance. Valid range [0-9] where 0=light, 9=heavy.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify this to dualsense_trigger_resistance, since we are not using them in an "adaptive" manner.


### Removal

Expand Down
4 changes: 4 additions & 0 deletions mc_mitm/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@
;dualsense_enable_player_leds=false
; Set Dualsense vibration intensity, 12.5% per increment. Valid range [1-8] where 1=12.5%, 8=100% [default 4(50%)]
;dualsense_vibration_intensity=4
; Enable adaptive triggers [default true]
;dualsense_enable_adaptive_triggers=true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to what I wrote above about using a single config option, this option should be disabled by default (i.e. set to 0)

; Set resistance of the DualSense adaptive triggers. Valid range [0-9] where 0=light, 9=heavy [default 0(light)]
;dualsense_adaptive_triggers_resistance=0
133 changes: 129 additions & 4 deletions mc_mitm/source/controllers/dualsense_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ 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);
m_buttons.ZR = src->input0x01.right_trigger > (std::min(m_trigger_threshold * UINT8_MAX, UINT8_MAX - 1.0f));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to wrap a function call in parethesis

m_buttons.ZL = src->input0x01.left_trigger > (std::min(m_trigger_threshold * UINT8_MAX, UINT8_MAX - 1.0f));
}

void DualsenseController::MapInputReport0x31(const DualsenseReportData *src) {
Expand Down Expand Up @@ -190,8 +190,8 @@ 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);
m_buttons.ZR = src->input0x31.right_trigger > (std::min(m_trigger_threshold * UINT8_MAX, UINT8_MAX - 1.0f));
m_buttons.ZL = src->input0x31.left_trigger > (std::min(m_trigger_threshold * UINT8_MAX, UINT8_MAX - 1.0f));

if (src->input0x31.buttons.touchpad) {
for (int i = 0; i < 2; ++i) {
Expand Down Expand Up @@ -310,6 +310,131 @@ namespace ams::controller {
report.output0x31.data[2] = 0x54;
report.output0x31.data[3] = m_rumble_state.amp_motor_right;
report.output0x31.data[4] = m_rumble_state.amp_motor_left;

if (config->misc.dualsense_enable_adaptive_triggers) {
// Magic numbers that work best after some trial & error
float trigger_threshold = (std::min(m_trigger_threshold * UINT8_MAX, UINT8_MAX - 1.0f));
float adaptive_trigger_threshold_end = (std::max(trigger_threshold - 80.0f, 0.0f));
float adaptive_trigger_threshold_start = (std::max(adaptive_trigger_threshold_end - 10.0f, 0.0f));

u8 force1 = static_cast<u8>(adaptive_trigger_threshold_start);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to cast these, you can just assign them as u8 above

u8 force2 = static_cast<u8>(adaptive_trigger_threshold_end);

u8 force3 = static_cast<u8>(config->misc.dualsense_adaptive_triggers_resistance / 9.0f * 255.0f);

// --- Control flags ---
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments don't match the project style. Dont use things like --- to separate sections. I usually label sections with a comment and separate them by blank lines

report.output0x31.data[1] = 0x01 | 0x02 | 0x04 | 0x08;
report.output0x31.data[2] = 0x01 | 0x04 | 0x10 | 0x40;

// --- Right trigger ---

// [Mode]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise with these. Don't use [ ]. Prefer single line and/or inline comments if you must add them. I don't like multi-line comments within code blocks decreasing the amount of actual code I can fit on the screen. In this case a self-documenting enum might be a better choice. Or even just a url to where you found this info documented, in the event it might be needed in the future.

// 0x00 = Off
// 0x01 = Rigid
// 0x02 = Pulse
// 0x20 = Extra A
// 0x04 = Extra B
// 0xFC = Calibration
report.output0x31.data[11] = 0x02;

// [Force 1]
// Start of resistance section
// 0x00 = 0%
// 0xFF = 100%
report.output0x31.data[12] = force1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assign these directly, rather than creating intermediate force variables


// [Force 2]
// (Mode Rigid = Amount of force exerted)
// (Mode Pulse = End of resistance section)
// 0x00 = 0%
// 0xFF = 100%
report.output0x31.data[13] = force2;

// [Force 3]
// (Mode Pulse = Force exerted in range)
// 0x00 = 0%
// 0xFF = 100%
report.output0x31.data[14] = force3;

// [Force 4]
// (Mode Extra A & Extra B = Strength of effect near release state)
// 0x00 = 0%
// 0xFF = 100%
report.output0x31.data[15] = 0x00;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to assign unused fields, report is zero-initialised


// [Force 5]
// (Mode Extra A & Extra B = Strength of effect near middle)
// 0x00 = 0%
// 0xFF = 100%
report.output0x31.data[16] = 0x00;

// [Force 6]
// (Mode Extra A & Extra B = Strength of effect at pressed state)
// 0x00 = 0%
// 0xFF = 100%
report.output0x31.data[17] = 0x00;

// [Force 7]
// (Mode Extra A & Extra B = Effect actuation frequency in Hz)
// 0x00 = 0%
// 0xFF = 100%
report.output0x31.data[20] = 0x00;

// --- Left trigger ---

// [Mode]
// 0x00 = Off
// 0x01 = Rigid
// 0x02 = Pulse
// 0x20 = Extra A
// 0x04 = Extra B
// 0xFC = Calibration
report.output0x31.data[22] = 0x02;

// [Force 1]
// Start of resistance section
// 0x00 = 0%
// 0xFF = 100%
report.output0x31.data[23] = force1;

// [Force 2]
// (Mode Rigid = Amount of force exerted)
// (Mode Pulse = End of resistance section)
// 0x00 = 0%
// 0xFF = 100%
report.output0x31.data[24] = force2;

// [Force 3]
// (Mode Pulse = Force exerted in range)
// 0x00 = 0%
// 0xFF = 100%
report.output0x31.data[25] = force3;

// [Force 4]
// (Mode Extra A & Extra B = Strength of effect near release state)
// 0x00 = 0%
// 0xFF = 100%
report.output0x31.data[26] = 0x00;

// [Force 5]
// (Mode Extra A & Extra B = Strength of effect near middle)
// 0x00 = 0%
// 0xFF = 100%
report.output0x31.data[27] = 0x00;

// [Force 6]
// (Mode Extra A & Extra B = Strength of effect at pressed state)
// 0x00 = 0%
// 0xFF = 100%
report.output0x31.data[28] = 0x00;

// [Force 7]
// (Mode Extra A & Extra B = Effect actuation frequency in Hz)
// 0x00 = 0%
// 0xFF = 100%
report.output0x31.data[31] = 0x00;
}

report.output0x31.data[37] = 0x08 - config->misc.dualsense_vibration_intensity; // User setting is inverse of how the controller sets intensity
report.output0x31.data[39] = 0x02 | 0x01;
report.output0x31.data[42] = 0x02;
Expand Down
8 changes: 7 additions & 1 deletion mc_mitm/source/mcmitm_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ namespace ams::mitm {
.dualshock4_lightbar_brightness = 5,
.dualsense_lightbar_brightness = 5,
.dualsense_enable_player_leds = true,
.dualsense_vibration_intensity = 4
.dualsense_vibration_intensity = 4,
.dualsense_enable_adaptive_triggers = true,
.dualsense_adaptive_triggers_resistance = 0
}
};

Expand Down Expand Up @@ -107,6 +109,10 @@ namespace ams::mitm {
ParseBoolean(value, &config->misc.dualsense_enable_player_leds);
} else if (strcasecmp(name, "dualsense_vibration_intensity") == 0) {
ParseInt(value, &config->misc.dualsense_vibration_intensity, 1, 8);
} else if (strcasecmp(name, "dualsense_enable_adaptive_triggers") == 0) {
ParseBoolean(value, &config->misc.dualsense_enable_adaptive_triggers);
} else if (strcasecmp(name, "dualsense_adaptive_triggers_resistance") == 0) {
ParseInt(value, &config->misc.dualsense_adaptive_triggers_resistance, 0, 9);
}
} else {
return 0;
Expand Down
2 changes: 2 additions & 0 deletions mc_mitm/source/mcmitm_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace ams::mitm {
int dualsense_lightbar_brightness;
bool dualsense_enable_player_leds;
int dualsense_vibration_intensity;
bool dualsense_enable_adaptive_triggers;
int dualsense_adaptive_triggers_resistance;
} misc;
};

Expand Down