Skip to content

Commit bfbfd40

Browse files
committed
Improvements and fixes for Nintendo Switch controllers
1 parent 62b7a6c commit bfbfd40

File tree

3 files changed

+70
-29
lines changed

3 files changed

+70
-29
lines changed

README.RU.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
Для изменения яркости 2 раза нажмите на область яркости. Если изменение яркости заблокировано, то подстветка будет выключаться по двойному клику.
2222

2323

24-
Кнопка `PS` открывает "Xbox Game Bar" (нажимая `Win + G`), `PS + □` - уменьшить громкость, `PS + ○` - увеличить громкость, `PS + △` - увеличивает, а затем уменьшает чувствительность прицеливания (сброс на `PS + R3`), `PS + X` - кнопка микрофона (скриншот / нажатие сконфигурированной кнопки клавиатуры).
24+
Кнопка `PS` или `Capture + Home` открывает "Xbox Game Bar" (нажимая `Win + G`), `PS + □` или `CAPTURE + Y` - уменьшить громкость, `PS + ○` или `PS + A` - увеличить громкость, `PS + △` или `CAPTURE + X` - увеличивает, а затем уменьшает чувствительность прицеливания (сброс на `PS + R3` или `CAPTURE + R3`), `PS + X` или `CAPTURE + B` - кнопка микрофона (скриншот или нажатие сконфигурированной кнопки клавиатуры).
2525

2626

27-
По умолчанию кнопка микрофона делает скриншот `Win + Alt + PrtScr` (для DualShock 4 нажимаем `PS + X`). Изменив параметр `MicCustomKey` на [нужное значение кнопки](https://github.com/r57zone/DSAdvance/blob/master/BINDINGS.RU.md) будет производится её нажатие.
27+
По умолчанию кнопка микрофона делает скриншот `Win + Alt + PrtScr` (для DualShock 4 `PS + X`, а для Nintendo контроллеров `CAPTURE + B`). Изменив параметр `MicCustomKey` на [нужное значение кнопки](https://github.com/r57zone/DSAdvance/blob/master/BINDINGS.RU.md) будет производится её нажатие.
2828

2929

30-
Для эмуляции клавиатуры и мыши, для старых игр, переключите режим работы на `ALT + Q` или `PS + ←` и `PS + →` и выберите нужный профиль или [создайте новый профиль](https://github.com/r57zone/DSAdvance/blob/master/BINDINGS.RU.md). Профили переключаются на клавиши `ALT + ↑` и `ALT + ↓`, если окно активно или на геймпаде, с помощью `PS + ↑` и `PS + ↓`. Профиль по умолчанию позволяет работать в Windows.
30+
Для эмуляции клавиатуры и мыши, для старых игр, переключите режим работы на `ALT + Q` или `PS + ←` и `PS + →`, или `HOME + ←` и `HOME + →`, и выберите нужный профиль или [создайте новый профиль](https://github.com/r57zone/DSAdvance/blob/master/BINDINGS.RU.md). Профили переключаются на клавиши `ALT + ↑` и `ALT + ↓`, если окно активно или на геймпаде, с помощью `PS + ↑` и `PS + ↓` или `HOME + ↑` и `HOME + ↓`. Профиль по умолчанию позволяет работать в Windows.
3131

3232

3333
Для подключения [внешних педалей (DInput)](https://github.com/r57zone/XboxExternalPedals#setup-dinput-pedals-mh-et-live-board) измените параметр `DInput` на `1`, в разделе `ExternalPedals`. Для поключения [внешних педалей на Arduino](https://github.com/r57zone/XboxExternalPedals#setup-arduino-pedals) измените номер COM-порта, изменив параметр `COMPort`.
@@ -63,7 +63,7 @@
6363

6464

6565
**Не работают адаптивые триггеры или световая панель в игре**<br>
66-
Добавьте игру в список исключений программы "HidHide" и изменить режим "DSAdvance" на "Only mouse".
66+
Добавьте игру в список исключений программы "HidHide" и измените режим "DSAdvance" на "Only mouse".
6767

6868

6969

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ To exit the stick emulation mode on the touchpad, need to switch to the default
1919
By clicking on the default profile on DualSense the white LEDs display the current battery status (1 - 0..25%, 2 - 26..50%, 3 - 51..75%, 4 - 76..100%), also on DualSense and DualShock 4 the battery status is shown on the lightbar (green - 100..30%, yellow - 29..10%, red - 9..1%), can be disabled in the config, parameter `ShowBatteryStatusOnLightBar`. For DualSense and DualShock 4 the current charge is displayed in the program itself.
2020

2121

22-
The `PS` button opens the "Xbox Game Bar", `PS + □` - decrease the volume, `PS + ○` - increase the volume, `PS + △` - increases and then decreases aiming sensitivity (reset to `PS + R3`), `PS + X` - microphone button (screenshot / pressing configured keyboard button).
22+
`PS` or `Capture + Home` button opens "Xbox Game Bar" (press `Win + G`), `PS + □` or `CAPTURE + Y` - decrease volume, `PS + ○` or `PS + A` - increase volume, `PS + △` or `CAPTURE + X` - increases and then decreases aiming sensitivity (reset to `PS + R3` or `CAPTURE + R3`), `PS + X` or `CAPTURE + B` - microphone button (screenshot or pressing configured keyboard button).
2323

2424

25-
By default, the microphone button takes a screenshot of `Win + Alt + PrtScr` (for DualShock 4 press `PS + X`). By changing the `MicCustomKey` parameter to the [desired button value](https://github.com/r57zone/DSAdvance/blob/master/BINDINGS.md), it will be pressed.
25+
By default, the microphone button takes a screenshot of `Win + Alt + PrtScr` (for DualShock 4 `PS + X`, and for Nintendo controllers `CAPTURE + B`). By changing the `MicCustomKey` parameter to the [desired button value](https://github.com/r57zone/DSAdvance/blob/master/BINDINGS.md), it will be pressed.
2626

2727

28-
To emulate the keyboard and mouse for older games, switch the mode to `ALT + Q` or `PS + ←` and `PS + →` and select the desired profile or [create the desired profile](https://github.com/r57zone/DSAdvance/blob/master/BINDINGS.md). Profiles are switched to the `ALT + ↑` and `ALT + ↓` keys if the window is active or on a gamepad using `PS + ↑` and `PS + ↓`. The default profile allows to work in Windows.
28+
To emulate keyboard and mouse, for old games, switch the operating mode to `ALT + Q` or `PS + ←` and `PS + →`, or `HOME + ←` and `HOME + →`, and select the desired profile or [create the desired profile](https://github.com/r57zone/DSAdvance/blob/master/BINDINGS.md). Profiles are switched to the `ALT + ↑` and `ALT + ↓` keys if the window is active or on a gamepad using `PS + ↑` and `PS + ↓` or `HOME + ↑` and `HOME + ↓`. The default profile allows to work in Windows.
2929

3030

3131
To connect [external pedals (DInput)](https://github.com/r57zone/XboxExternalPedals#setup-dinput-pedals-mh-et-live-board), change the `DInput` parameter to `1`, in the `ExternalPedals` section. To connect [external pedals on Arduino](https://github.com/r57zone/XboxExternalPedals#setup-arduino-pedals), change the COM port number by changing the `COMPort` parameter.

Source/DSAdvance/DSAdvance.cpp

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ void ExternalPedalsDInputSearch() {
271271
for (int JoyID = 0; JoyID < 4; ++JoyID) { // JOYSTICKID4 - 3
272272
if (joyGetPosEx(JoyID, &AppStatus.ExternalPedalsJoyInfo) == JOYERR_NOERROR && // JoyID - JOYSTICKID1..4
273273
joyGetDevCaps(JoyID, &AppStatus.ExternalPedalsJoyCaps, sizeof(AppStatus.ExternalPedalsJoyCaps)) == JOYERR_NOERROR &&
274+
(AppStatus.ExternalPedalsJoyCaps.wMid != 1406 ||
275+
(AppStatus.ExternalPedalsJoyCaps.wPid != 8198 && AppStatus.ExternalPedalsJoyCaps.wPid != 8199)) && // Exclude Pro Controller и JoyCon
274276
AppStatus.ExternalPedalsJoyCaps.wNumButtons == 16) { // DualSense - 15, DigiJoy - 16
275277
AppStatus.ExternalPedalsJoyIndex = JoyID;
276278
AppStatus.ExternalPedalsDInputConnected = true;
@@ -525,7 +527,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
525527

526528
int main(int argc, char **argv)
527529
{
528-
SetConsoleTitle("DSAdvance 0.9.8");
530+
SetConsoleTitle("DSAdvance 0.9.9");
529531

530532
WNDCLASS AppWndClass = {};
531533
AppWndClass.lpfnWndProc = WindowProc;
@@ -699,16 +701,45 @@ int main(int argc, char **argv)
699701
}
700702

701703
XUSB_REPORT_INIT(&report);
702-
InputState = JslGetSimpleState(CurGamepad.deviceID[0]);
704+
705+
if (JslGetControllerType(CurGamepad.deviceID[0]) == JS_TYPE_DS || JslGetControllerType(CurGamepad.deviceID[0]) == JS_TYPE_DS4 || JslGetControllerType(CurGamepad.deviceID[0]) == JS_TYPE_PRO_CONTROLLER) {
706+
InputState = JslGetSimpleState(CurGamepad.deviceID[0]);
707+
MotionState = JslGetMotionState(CurGamepad.deviceID[0]);
708+
709+
} else if (JslGetControllerType(CurGamepad.deviceID[0]) == JS_TYPE_JOYCON_LEFT || JslGetControllerType(CurGamepad.deviceID[0]) == JS_TYPE_JOYCON_RIGHT) { // The state of the joycons is the same for both
710+
memset(&InputState, 0, sizeof(JOY_SHOCK_STATE));
711+
memset(&MotionState, 0, sizeof(MOTION_STATE));
712+
713+
for (int i = 0; i < AppStatus.ControllerCount; i++) {
714+
715+
if (JslGetControllerType(CurGamepad.deviceID[i]) != JS_TYPE_JOYCON_LEFT && JslGetControllerType(CurGamepad.deviceID[i]) != JS_TYPE_JOYCON_RIGHT) continue;
716+
JOY_SHOCK_STATE tempState = JslGetSimpleState(CurGamepad.deviceID[i]);
717+
718+
InputState.buttons |= tempState.buttons;
719+
720+
721+
722+
if (JslGetControllerType(CurGamepad.deviceID[i]) == JS_TYPE_JOYCON_LEFT) {
723+
InputState.stickLX = tempState.stickLX;
724+
InputState.stickLY = tempState.stickLY;
725+
InputState.lTrigger = tempState.lTrigger;
726+
} else if (JslGetControllerType(CurGamepad.deviceID[i]) == JS_TYPE_JOYCON_RIGHT) {
727+
MotionState = JslGetMotionState(CurGamepad.deviceID[i]);
728+
InputState.stickRX = tempState.stickRX;
729+
InputState.stickRY = tempState.stickRY;
730+
InputState.rTrigger = tempState.rTrigger;
731+
}
732+
}
733+
}
734+
703735
if (AppStatus.ControllerCount < 1) { // We do not process anything during idle time
704736
//InputState = { 0, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
705737
report.sThumbLX = 1; // Maybe the crash is due to power saving? temporary test
706738
ret = vigem_target_x360_update(client, x360, report); // Vigem always mode only
707739
Sleep(AppStatus.SleepTimeOut);
708740
continue;
709741
}
710-
711-
MotionState = JslGetMotionState(CurGamepad.deviceID[0]);
742+
712743
MotionAngles = QuaternionToEulerAngle(MotionState.quatW, MotionState.quatZ, MotionState.quatX, MotionState.quatY);
713744

714745
// Stick dead zones
@@ -918,7 +949,7 @@ int main(int argc, char **argv)
918949

919950
report.bLeftTrigger = DeadZoneAxis(InputState.lTrigger, CurGamepad.Triggers.DeadZoneLeft) * 255;
920951
report.bRightTrigger = DeadZoneAxis(InputState.rTrigger, CurGamepad.Triggers.DeadZoneRight) * 255;
921-
952+
922953
// External pedals
923954
if (AppStatus.ExternalPedalsDInputConnected) {
924955
if (joyGetPosEx(AppStatus.ExternalPedalsJoyIndex, &AppStatus.ExternalPedalsJoyInfo) == JOYERR_NOERROR) {
@@ -946,7 +977,7 @@ int main(int argc, char **argv)
946977
report.wButtons |= InputState.buttons & JSMASK_PLUS ? XINPUT_GAMEPAD_START : 0;
947978
}
948979

949-
if (!(InputState.buttons & JSMASK_PS)) { // During special functions, nothing is pressed in the game
980+
if (!(InputState.buttons & JSMASK_PS && InputState.buttons & JSMASK_CAPTURE && InputState.buttons & JSMASK_CAPTURE)) { // During special functions, nothing is pressed in the game
950981
report.wButtons |= InputState.buttons & JSMASK_L ? XINPUT_GAMEPAD_LEFT_SHOULDER : 0;
951982
report.wButtons |= InputState.buttons & JSMASK_R ? XINPUT_GAMEPAD_RIGHT_SHOULDER : 0;
952983
if (AppStatus.LeftStickMode != LeftStickInvertPressMode) // Invert stick mode
@@ -968,27 +999,37 @@ int main(int argc, char **argv)
968999
if (JslGetControllerType(CurGamepad.deviceID[0]) == JS_TYPE_PRO_CONTROLLER || JslGetControllerType(CurGamepad.deviceID[0]) == JS_TYPE_JOYCON_LEFT || JslGetControllerType(CurGamepad.deviceID[0]) == JS_TYPE_JOYCON_RIGHT) {
9691000
if (SkipPollCount == 0 && InputState.buttons & JSMASK_CAPTURE) { if (GamepadActionMode == 1) GamepadActionMode = 0; else { GamepadActionMode = 1; AnglesOffset = MotionAngles; } SkipPollCount = SkipPollTimeOut; }
9701001
if (SkipPollCount == 0 && InputState.buttons & JSMASK_HOME) { if (GamepadActionMode == 0 || GamepadActionMode == 1) GamepadActionMode = LastAIMProCtrlMode; else if (GamepadActionMode == 2) { GamepadActionMode = 3; LastAIMProCtrlMode = 3; } else { GamepadActionMode = 2; LastAIMProCtrlMode = 2; } SkipPollCount = SkipPollTimeOut; }
971-
}
1002+
1003+
// Sony
1004+
} else {
9721005

973-
// GameBar & multi keys
974-
// PS without any keys
975-
if (PSReleasedCount == 0 && InputState.buttons == JSMASK_PS) { PSOnlyCheckCount = 20; PSOnlyPressed = true; }
976-
if (PSOnlyCheckCount > 0) {
977-
if (PSOnlyCheckCount == 1 && PSOnlyPressed)
978-
PSReleasedCount = PSReleasedTimeOut; // Timeout to release the PS button and don't execute commands
979-
PSOnlyCheckCount--;
980-
if (InputState.buttons != JSMASK_PS && InputState.buttons != 0) { PSOnlyPressed = false; PSOnlyCheckCount = 0; }
1006+
// GameBar & multi keys
1007+
// PS without any keys
1008+
if (PSReleasedCount == 0 && InputState.buttons == JSMASK_PS) { PSOnlyCheckCount = 20; PSOnlyPressed = true; }
1009+
if (PSOnlyCheckCount > 0) {
1010+
if (PSOnlyCheckCount == 1 && PSOnlyPressed)
1011+
PSReleasedCount = PSReleasedTimeOut; // Timeout to release the PS button and don't execute commands
1012+
PSOnlyCheckCount--;
1013+
if (InputState.buttons != JSMASK_PS && InputState.buttons != 0) { PSOnlyPressed = false; PSOnlyCheckCount = 0; }
1014+
}
1015+
if (InputState.buttons & JSMASK_PS && InputState.buttons != JSMASK_PS) PSReleasedCount = PSReleasedTimeOut; // printf("PS + any button\n"); }
1016+
if (PSReleasedCount > 0) PSReleasedCount--;
1017+
}
1018+
1019+
KeyPress(VK_GAMEBAR, (PSOnlyCheckCount == 1 && PSOnlyPressed) || (InputState.buttons & JSMASK_CAPTURE && InputState.buttons & JSMASK_HOME), &ButtonsStates.PS);
1020+
1021+
if (JslGetControllerType(CurGamepad.deviceID[0]) == JS_TYPE_PRO_CONTROLLER || JslGetControllerType(CurGamepad.deviceID[0]) == JS_TYPE_JOYCON_LEFT || JslGetControllerType(CurGamepad.deviceID[0]) == JS_TYPE_JOYCON_RIGHT) {
1022+
KeyPress(VK_VOLUME_DOWN2, InputState.buttons & JSMASK_CAPTURE && InputState.buttons & JSMASK_W, &ButtonsStates.VolumeDown);
1023+
KeyPress(VK_VOLUME_UP2, InputState.buttons & JSMASK_CAPTURE && InputState.buttons & JSMASK_E, &ButtonsStates.VolumeUP);
1024+
} else {
1025+
KeyPress(VK_VOLUME_DOWN2, InputState.buttons & JSMASK_PS && InputState.buttons & JSMASK_W, &ButtonsStates.VolumeDown);
1026+
KeyPress(VK_VOLUME_UP2, InputState.buttons & JSMASK_PS && InputState.buttons & JSMASK_E, &ButtonsStates.VolumeUP);
9811027
}
982-
if (InputState.buttons & JSMASK_PS && InputState.buttons != JSMASK_PS) PSReleasedCount = PSReleasedTimeOut; // printf("PS + any button\n"); }
983-
if (PSReleasedCount > 0) PSReleasedCount--;
9841028

985-
KeyPress(VK_GAMEBAR, PSOnlyCheckCount == 1 && PSOnlyPressed, &ButtonsStates.PS);
986-
KeyPress(VK_VOLUME_DOWN2, InputState.buttons & JSMASK_PS && InputState.buttons & JSMASK_W, &ButtonsStates.VolumeDown);
987-
KeyPress(VK_VOLUME_UP2, InputState.buttons & JSMASK_PS && InputState.buttons & JSMASK_E, &ButtonsStates.VolumeUP);
988-
KeyPress(AppStatus.ScreenShotKey, InputState.buttons & JSMASK_MIC || (InputState.buttons & JSMASK_PS && InputState.buttons & JSMASK_S), &ButtonsStates.Mic); // + DualShock 4
1029+
KeyPress(AppStatus.ScreenShotKey, InputState.buttons & JSMASK_MIC || ((InputState.buttons & JSMASK_PS || InputState.buttons & JSMASK_CAPTURE) && InputState.buttons & JSMASK_S), &ButtonsStates.Mic); // + DualShock 4
9891030

9901031
// Custom sens
991-
if (SkipPollCount == 0 && InputState.buttons & JSMASK_PS && InputState.buttons & JSMASK_N) {
1032+
if (SkipPollCount == 0 && (InputState.buttons & JSMASK_PS || InputState.buttons & JSMASK_CAPTURE) && InputState.buttons & JSMASK_N) {
9921033
CurGamepad.Motion.CustomMulSens += 0.2;
9931034
if (CurGamepad.Motion.CustomMulSens > 2.4)
9941035
CurGamepad.Motion.CustomMulSens = 0.2;

0 commit comments

Comments
 (0)