Skip to content

Commit

Permalink
Merge pull request #542 from streetpea/configure_dualsense_effects_in…
Browse files Browse the repository at this point in the history
…tensity

Configure dualsense effects intensity
  • Loading branch information
streetpea authored Feb 2, 2025
2 parents 3a3b621 + 4407c6a commit b54fe66
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 93 deletions.
4 changes: 3 additions & 1 deletion gui/include/controllermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class Controller : public QObject
bool is_dualsense_edge;
bool has_led;
bool micbutton_push;
uint16_t firmware_version;

#ifdef CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER
QMap<QPair<Sint64, Sint64>, uint8_t> touch_ids;
Expand Down Expand Up @@ -117,7 +118,8 @@ class Controller : public QObject
QString GetGUIDString();
ChiakiControllerState GetState();
void SetRumble(uint8_t left, uint8_t right);
void SetTriggerEffects(uint8_t type_left, const uint8_t *data_left, uint8_t type_right, const uint8_t *data_right);
void SetDualSenseRumble(uint8_t left, uint8_t right, uint8_t strength);
void SetTriggerEffects(uint8_t type_left, const uint8_t *data_left, uint8_t type_right, const uint8_t *data_right, uint8_t trigger_intensity);
void SetDualsenseMic(bool on);
void SetHapticRumble(uint16_t left, uint16_t right, int ms);
void StartUpdatingMapping();
Expand Down
5 changes: 5 additions & 0 deletions gui/include/qmlsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class QmlSettings : public QObject
Q_PROPERTY(int noiseSuppressLevel READ noiseSuppressLevel WRITE setNoiseSuppressLevel NOTIFY noiseSuppressLevelChanged)
Q_PROPERTY(int echoSuppressLevel READ echoSuppressLevel WRITE setEchoSuppressLevel NOTIFY echoSuppressLevelChanged)
#endif
Q_PROPERTY(float hapticOverride READ hapticOverride WRITE setHapticOverride NOTIFY hapticOverrideChanged)
Q_PROPERTY(int displayTargetContrast READ displayTargetContrast WRITE setDisplayTargetContrast NOTIFY displayTargetContrastChanged)
Q_PROPERTY(int displayTargetPeak READ displayTargetPeak WRITE setDisplayTargetPeak NOTIFY displayTargetPeakChanged)
Q_PROPERTY(int displayTargetPrim READ displayTargetPrim WRITE setDisplayTargetPrim NOTIFY displayTargetPrimChanged)
Expand Down Expand Up @@ -212,6 +213,9 @@ class QmlSettings : public QObject
bool hideCursor() const;
void setHideCursor(bool enabled);

float hapticOverride() const;
void setHapticOverride(float override);

int fpsLocalPS4() const;
void setFpsLocalPS4(int fps);
int fpsRemotePS4() const;
Expand Down Expand Up @@ -540,6 +544,7 @@ class QmlSettings : public QObject
void remotePlayAskChanged();
void addSteamShortcutAskChanged();
void hideCursorChanged();
void hapticOverrideChanged();
void audioVideoDisabledChanged();
void fpsLocalPS4Changed();
void fpsRemotePS4Changed();
Expand Down
3 changes: 3 additions & 0 deletions gui/include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ class Settings : public QObject
bool GetFullscreenDoubleClickEnabled() const { return settings.value("settings/fullscreen_doubleclick", false).toBool(); }
void SetFullscreenDoubleClickEnabled(bool enabled) { settings.setValue("settings/fullscreen_doubleclick", enabled); }

float GetHapticOverride() const { return settings.value("settings/haptic_override", 1.0).toFloat(); }
void SetHapticOverride(float override) { settings.setValue("settings/haptic_override", override); }

ChiakiVideoResolutionPreset GetResolutionLocalPS4() const;
ChiakiVideoResolutionPreset GetResolutionRemotePS4() const;
ChiakiVideoResolutionPreset GetResolutionLocalPS5() const;
Expand Down
7 changes: 6 additions & 1 deletion gui/include/streamsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ struct StreamSessionConnectInfo
bool enable_keyboard;
bool enable_dualsense;
bool auto_regist;
float trigger_override;
float haptic_override;
ChiakiDisableAudioVideo audio_video_disabled;
RumbleHapticsIntensity rumble_haptics_intensity;
bool buttons_by_pos;
Expand Down Expand Up @@ -166,7 +168,8 @@ class StreamSession : public QObject
bool cant_display = false;
int haptics_handheld;
float ps5_haptic_intensity;
float ps5_trigger_intensity;
int ps5_rumble_intensity;
int ps5_trigger_intensity;
uint8_t led_color[3];
QHash<int, Controller *> controllers;
#if CHIAKI_GUI_ENABLE_SETSU
Expand Down Expand Up @@ -202,6 +205,8 @@ class StreamSession : public QObject
int8_t mouse_touch_id;
ChiakiControllerState dpad_touch_state;
uint16_t dpad_touch_increment;
float trigger_override;
float haptic_override;
bool dpad_regular;
bool dpad_regular_touch_switched;
uint dpad_touch_shortcut1;
Expand Down
33 changes: 29 additions & 4 deletions gui/src/controllermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typedef struct
Uint8 rgucRightTriggerEffect[11]; /* 10 */
Uint8 rgucLeftTriggerEffect[11]; /* 21 */
Uint8 rgucUnknown1[6]; /* 32 */
Uint8 ucLedFlags; /* 38 */
Uint8 ucEnableBits3; /* 38 */
Uint8 rgucUnknown2[2]; /* 39 */
Uint8 ucLedAnim; /* 41 */
Uint8 ucLedBrightness; /* 42 */
Expand Down Expand Up @@ -318,7 +318,7 @@ void ControllerManager::ControllerClosed(Controller *controller)

Controller::Controller(int device_id, ControllerManager *manager)
: QObject(manager), ref(0), last_motion_timestamp(0), micbutton_push(false), is_dualsense(false),
is_dualsense_edge(false), has_led(false), updating_mapping_button(false), is_handheld(false),
is_dualsense_edge(false), has_led(false), firmware_version(0), updating_mapping_button(false), is_handheld(false),
is_steam_virtual(false), is_steam_virtual_unmasked(false), enable_analog_stick_mapping(false)
{
this->id = device_id;
Expand Down Expand Up @@ -346,6 +346,7 @@ Controller::Controller(int device_id, ControllerManager *manager)
is_dualsense = chiaki_dualsense_controller_ids.contains(controller_id);
is_handheld = chiaki_handheld_controller_ids.contains(controller_id);
is_dualsense_edge = chiaki_dualsense_edge_controller_ids.contains(controller_id);
firmware_version = SDL_GameControllerGetFirmwareVersion(controller);
SDL_Joystick *js = SDL_GameControllerGetJoystick(controller);
SDL_JoystickGUID guid = SDL_JoystickGetGUID(js);
auto guid_controller_id = QPair<uint16_t, uint16_t>(0, 0);
Expand All @@ -372,7 +373,7 @@ Controller::~Controller()
{
// Clear trigger effects, SDL doesn't do it automatically
const uint8_t clear_effect[10] = { 0 };
this->SetTriggerEffects(0x05, clear_effect, 0x05, clear_effect);
this->SetTriggerEffects(0x05, clear_effect, 0x05, clear_effect, 0x07);
SDL_GameControllerClose(controller);
}
#endif
Expand Down Expand Up @@ -854,6 +855,28 @@ void Controller::SetRumble(uint8_t left, uint8_t right)
#endif
}

void Controller::SetDualSenseRumble(uint8_t left, uint8_t right, uint8_t strength)
{
DS5EffectsState_t state;
SDL_zero(state);
if(firmware_version < 0x0224)
{
state.ucEnableBits1 |= 0x01;
state.ucRumbleLeft = left >> 1;
state.ucRumbleRight = right >> 1;
}
else
{
state.ucEnableBits3 |= 0x04;
state.ucRumbleLeft = left;
state.ucRumbleRight = right;
}
state.rgucUnknown1[4] = strength;
state.ucEnableBits1 |= 0x02;
state.ucEnableBits2 |= 0x40;
SDL_GameControllerSendEffect(controller, &state, sizeof(state));
}

void Controller::ChangeLEDColor(const uint8_t *led_color)
{
#ifdef CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER
Expand All @@ -863,14 +886,16 @@ void Controller::ChangeLEDColor(const uint8_t *led_color)
#endif
}

void Controller::SetTriggerEffects(uint8_t type_left, const uint8_t *data_left, uint8_t type_right, const uint8_t *data_right)
void Controller::SetTriggerEffects(uint8_t type_left, const uint8_t *data_left, uint8_t type_right, const uint8_t *data_right, uint8_t strength)
{
#ifdef CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER
if((!is_dualsense && !is_dualsense_edge) || !controller)
return;
DS5EffectsState_t state;
SDL_zero(state);
state.ucEnableBits1 |= (0x04 /* left trigger */ | 0x08 /* right trigger */);
state.rgucUnknown1[4] = strength;
state.ucEnableBits2 |= 0x40;
state.rgucLeftTriggerEffect[0] = type_left;
SDL_memcpy(state.rgucLeftTriggerEffect + 1, data_left, 10);
state.rgucRightTriggerEffect[0] = type_right;
Expand Down
66 changes: 53 additions & 13 deletions gui/src/qml/SettingsDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ DialogView {
from: 2
to: 50
stepSize: 1
value: Chiaki.settings.bitrateLocalPS4 / 1000 ? (Chiaki.settings.bitrateLocalPS4 / 1000).toFixed(0) : bitrate
value: Chiaki.settings.bitrateLocalPS4 / 1000 ? (Chiaki.settings.bitrateLocalPS4 / 1000) : bitrate
onMoved: Chiaki.settings.bitrateLocalPS4 = value * 1000;
KeyNavigation.up: fpsLocalPS4
KeyNavigation.down: bitrateLocalPS4
Expand All @@ -935,7 +935,7 @@ DialogView {
verticalCenter: parent.verticalCenter
leftMargin: 10
}
text: (parent.value) + qsTr(" Mbps") + qsTr(" (%1 Mbps)").arg(parent.bitrate)
text: (parent.value) + qsTr(" Mbps") + qsTr(" (%1 Mbps)").arg(parent.bitrate.toFixed(0))
}
}

Expand All @@ -956,7 +956,7 @@ DialogView {
from: 2
to: 50
stepSize: 1
value: Chiaki.settings.bitrateRemotePS4 / 1000 ? (Chiaki.settings.bitrateRemotePS4 / 1000).toFixed(0) : bitrate
value: Chiaki.settings.bitrateRemotePS4 / 1000 ? (Chiaki.settings.bitrateRemotePS4 / 1000) : bitrate
onMoved: Chiaki.settings.bitrateRemotePS4 = value * 1000;
KeyNavigation.up: fpsRemotePS4
KeyNavigation.down: bitrateRemotePS4
Expand All @@ -969,7 +969,7 @@ DialogView {
verticalCenter: parent.verticalCenter
leftMargin: 10
}
text: (parent.value) + qsTr(" Mbps") + qsTr(" (%1 Mbps)").arg(parent.bitrate)
text: (parent.value) + qsTr(" Mbps") + qsTr(" (%1 Mbps)").arg(parent.bitrate.toFixed(0))
}
}

Expand All @@ -990,7 +990,7 @@ DialogView {
from: 2
to: 50
stepSize: 1
value: Chiaki.settings.bitrateLocalPS5 / 1000 ? (Chiaki.settings.bitrateLocalPS5 / 1000).toFixed(0) : bitrate
value: Chiaki.settings.bitrateLocalPS5 / 1000 ? (Chiaki.settings.bitrateLocalPS5 / 1000) : bitrate
onMoved: Chiaki.settings.bitrateLocalPS5 = value * 1000;
KeyNavigation.up: fpsLocalPS5
KeyNavigation.down: codecLocalPS5
Expand All @@ -1002,7 +1002,7 @@ DialogView {
verticalCenter: parent.verticalCenter
leftMargin: 10
}
text: (parent.value) + qsTr(" Mbps") + qsTr(" (%1 Mbps)").arg(parent.bitrate)
text: (parent.value) + qsTr(" Mbps") + qsTr(" (%1 Mbps)").arg(parent.bitrate.toFixed(0))
}
}

Expand All @@ -1023,7 +1023,7 @@ DialogView {
from: 2
to: 50
stepSize: 1
value: Chiaki.settings.bitrateRemotePS5 / 1000 ? (Chiaki.settings.bitrateRemotePS5 / 1000).toFixed(0) : bitrate
value: Chiaki.settings.bitrateRemotePS5 / 1000 ? (Chiaki.settings.bitrateRemotePS5 / 1000) : bitrate
onMoved: Chiaki.settings.bitrateRemotePS5 = value * 1000;
KeyNavigation.up: fpsRemotePS5
KeyNavigation.down: codecRemotePS5
Expand All @@ -1036,7 +1036,7 @@ DialogView {
verticalCenter: parent.verticalCenter
leftMargin: 10
}
text: (parent.value) + qsTr(" Mbps") + qsTr(" (%1 Mbps)").arg(parent.bitrate)
text: (parent.value) + qsTr(" Mbps") + qsTr(" (%1 Mbps)").arg(parent.bitrate.toFixed(0))
}
}

Expand Down Expand Up @@ -1220,7 +1220,7 @@ DialogView {
from: 1
to: 10
stepSize: 1
value: Chiaki.settings.audioBufferSize / 1920 ? (Chiaki.settings.audioBufferSize / 1920).toFixed(0) : 5
value: Chiaki.settings.audioBufferSize / 1920 ? (Chiaki.settings.audioBufferSize / 1920) : 5
onMoved: Chiaki.settings.audioBufferSize = value * 1920;
sendOutput: true

Expand All @@ -1231,7 +1231,7 @@ DialogView {
leftMargin: 10
}
text: {
(parent.value * 10) + qsTr(" ms")
(parent.value * 10).toFixed(0) + qsTr(" ms")
}
}
}
Expand Down Expand Up @@ -1909,7 +1909,7 @@ DialogView {
}

Item {
// Controller Mapping
// Controllers
ColumnLayout {
anchors {
top: parent.top
Expand Down Expand Up @@ -2103,17 +2103,57 @@ DialogView {
else
dpadTouch;
}
KeyNavigation.down: posButtons
KeyNavigation.down: hapticOverride
KeyNavigation.left: posButtons
KeyNavigation.right: posButtons
lastInFocusChain: true
}

Label {
Layout.alignment: Qt.AlignRight
text: qsTr("(Unchecked)")
}
}
RowLayout {
spacing: 10
Layout.alignment: Qt.AlignHCenter
Label {
Layout.alignment: Qt.AlignRight
text: qsTr("True Haptics Intensity:")
}

C.Slider {
id: hapticOverride
Layout.preferredWidth: 250
from: 0
to: 2
stepSize: 0.1
value: Chiaki.settings.hapticOverride
onMoved: Chiaki.settings.hapticOverride = value;
KeyNavigation.left: hapticOverride
KeyNavigation.right: hapticOverride
lastInFocusChain: true
KeyNavigation.up: posButtons
Label {
anchors {
left: parent.right
verticalCenter: parent.verticalCenter
leftMargin: 10
}
text: {
if(parent.value > 0.99 && parent.value < 1.01)
qsTr("console setting")
else
(parent.value * 100).toFixed(0) + qsTr(" %")
}
}
}

Label {
Layout.alignment: Qt.AlignRight
Layout.leftMargin: 200
text: qsTr("(console setting)")
}
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions gui/src/qmlsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ void QmlSettings::setHideCursor(bool enabled)
emit hideCursorChanged();
}

float QmlSettings::hapticOverride() const
{
return settings->GetHapticOverride();
}

void QmlSettings::setHapticOverride(float override)
{
settings->SetHapticOverride(override);
emit hapticOverrideChanged();
}

int QmlSettings::audioVideoDisabled() const
{
return static_cast<int>(settings->GetAudioVideoDisabled());
Expand Down Expand Up @@ -1519,6 +1530,7 @@ void QmlSettings::refreshAllKeys()
emit disconnectActionChanged();
emit suspendActionChanged();
emit logVerboseChanged();
emit hapticOverrideChanged();
emit rumbleHapticsIntensityChanged();
emit buttonsByPositionChanged();
emit startMicUnmutedChanged();
Expand Down
Loading

0 comments on commit b54fe66

Please sign in to comment.