summaryrefslogtreecommitdiffstats
path: root/src/skel
diff options
context:
space:
mode:
authorAdrian Graber <adrian@adriangraber.com>2021-07-04 20:51:16 +0200
committerAdrian Graber <adrian@adriangraber.com>2021-07-13 00:50:45 +0200
commit02ec56e8f70ab0fda5092d3455f76dcbb8825cff (patch)
tree2a0fb7358d75e23e1e6f4bc3d097f91fad4babd3 /src/skel
parentEnable Gamepad Menu on Switch (diff)
downloadre3-02ec56e8f70ab0fda5092d3455f76dcbb8825cff.tar
re3-02ec56e8f70ab0fda5092d3455f76dcbb8825cff.tar.gz
re3-02ec56e8f70ab0fda5092d3455f76dcbb8825cff.tar.bz2
re3-02ec56e8f70ab0fda5092d3455f76dcbb8825cff.tar.lz
re3-02ec56e8f70ab0fda5092d3455f76dcbb8825cff.tar.xz
re3-02ec56e8f70ab0fda5092d3455f76dcbb8825cff.tar.zst
re3-02ec56e8f70ab0fda5092d3455f76dcbb8825cff.zip
Diffstat (limited to '')
-rw-r--r--src/skel/glfw/glfw.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp
index c7f92d34..754c43be 100644
--- a/src/skel/glfw/glfw.cpp
+++ b/src/skel/glfw/glfw.cpp
@@ -329,6 +329,78 @@ psNativeTextureSupport(void)
/*
*****************************************************************************
*/
+
+#ifdef GTA_SWITCH
+
+static HidVibrationValue SwitchVibrationValues[2];
+static HidVibrationDeviceHandle SwitchVibrationDeviceHandles[2][2];
+static HidVibrationDeviceHandle SwitchVibrationDeviceGC;
+
+static PadState SwitchPad;
+
+Result HidInitializationResult[2];
+Result HidInitializationGCResult;
+
+void _psInitializeVibration()
+{
+ HidInitializationResult[0] = hidInitializeVibrationDevices(SwitchVibrationDeviceHandles[0], 2, HidNpadIdType_Handheld, HidNpadStyleTag_NpadHandheld);
+ if(R_FAILED(HidInitializationResult[0])) {
+ printf("Failed to initialize VibrationDevice for Handheld Mode\n");
+ }
+ HidInitializationResult[1] = hidInitializeVibrationDevices(SwitchVibrationDeviceHandles[1], 2, HidNpadIdType_No1, HidNpadStyleSet_NpadFullCtrl);
+ if(R_FAILED(HidInitializationResult[1])) {
+ printf("Failed to initialize VibrationDevice for Detached Mode\n");
+ }
+ HidInitializationGCResult = hidInitializeVibrationDevices(&SwitchVibrationDeviceGC, 1, HidNpadIdType_No1, HidNpadStyleTag_NpadGc);
+ if(R_FAILED(HidInitializationResult[1])) {
+ printf("Failed to initialize VibrationDevice for GC Mode\n");
+ }
+
+ SwitchVibrationValues[0].freq_low = 160.0f;
+ SwitchVibrationValues[0].freq_high = 320.0f;
+
+ padConfigureInput(1, HidNpadStyleSet_NpadFullCtrl);
+ padInitializeDefault(&SwitchPad);
+}
+
+void _psHandleVibration()
+{
+ padUpdate(&SwitchPad);
+
+ uint8 target_device = padIsHandheld(&SwitchPad) ? 0 : 1;
+
+ if(R_SUCCEEDED(HidInitializationResult[target_device])) {
+ CPad* pad = CPad::GetPad(0);
+
+ // value conversion based on SDL2 switch port
+ SwitchVibrationValues[0].amp_high = SwitchVibrationValues[0].amp_low = pad->ShakeFreq == 0 ? 0.0f : 320.0f;
+ SwitchVibrationValues[0].freq_low = pad->ShakeFreq == 0.0 ? 160.0f : (float)pad->ShakeFreq * 1.26f;
+ SwitchVibrationValues[0].freq_high = pad->ShakeFreq == 0.0 ? 320.0f : (float)pad->ShakeFreq * 1.26f;
+
+ if (pad->ShakeDur < CTimer::GetTimeStepInMilliseconds())
+ pad->ShakeDur = 0;
+ else
+ pad->ShakeDur -= CTimer::GetTimeStepInMilliseconds();
+ if (pad->ShakeDur == 0) pad->ShakeFreq = 0;
+
+
+ if(target_device == 1 && R_SUCCEEDED(HidInitializationGCResult)) {
+ // gamecube rumble
+ hidSendVibrationGcErmCommand(SwitchVibrationDeviceGC, pad->ShakeFreq > 0 ? HidVibrationGcErmCommand_Start : HidVibrationGcErmCommand_Stop);
+ }
+
+ memcpy(&SwitchVibrationValues[1], &SwitchVibrationValues[0], sizeof(HidVibrationValue));
+ hidSendVibrationValues(SwitchVibrationDeviceHandles[target_device], SwitchVibrationValues, 2);
+ }
+}
+#else
+void _psInitializeVibration() {}
+void _psHandleVibration() {}
+#endif
+
+/*
+ *****************************************************************************
+ */
RwBool
psInitialize(void)
{
@@ -409,6 +481,8 @@ psInitialize(void)
#endif
#endif
+
+ _psInitializeVibration();
gGameState = GS_START_UP;
TRACE("gGameState = GS_START_UP");
@@ -2459,6 +2533,8 @@ void CapturePad(RwInt32 padID)
if ( Abs(rightStickPos.y) > 0.3f )
pad->PCTempJoyState.RightStickY = (int32)(rightStickPos.y * 128.0f);
}
+
+ _psHandleVibration();
return;
}