diff --git a/nx/include/switch/services/hid.h b/nx/include/switch/services/hid.h index ed5725ce..e347379e 100644 --- a/nx/include/switch/services/hid.h +++ b/nx/include/switch/services/hid.h @@ -323,6 +323,13 @@ typedef enum { CONTROLLER_P1_AUTO = 10, ///< Not an actual HID-sysmodule ID. Only for hidKeys*()/hidJoystickRead()/hidSixAxisSensorValuesRead()/hidGetControllerType()/hidGetControllerColors()/hidIsControllerConnected(). Automatically uses CONTROLLER_PLAYER_1 when connected, otherwise uses CONTROLLER_HANDHELD. } HidControllerID; +/// GyroscopeZeroDriftMode +typedef enum { + HidGyroscopeZeroDriftMode_Loose = 0, ///< Loose + HidGyroscopeZeroDriftMode_Standard = 1, ///< Standard + HidGyroscopeZeroDriftMode_Tight = 2, ///< Tight +} HidGyroscopeZeroDriftMode; + /// JoyHoldType typedef enum { HidJoyHoldType_Default = 0, ///< Default / Joy-Con held vertically. @@ -769,6 +776,15 @@ Result hidGetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle, float *unk0, /// ResetSixAxisSensorFusionParameters Result hidResetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle); +/// Sets the ::HidGyroscopeZeroDriftMode for the specified SixAxisSensorHandle. +Result hidSetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle, HidGyroscopeZeroDriftMode mode); + +/// Gets the ::HidGyroscopeZeroDriftMode for the specified SixAxisSensorHandle. +Result hidGetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle, HidGyroscopeZeroDriftMode *mode); + +/// Resets the ::HidGyroscopeZeroDriftMode for the specified SixAxisSensorHandle to ::HidGyroscopeZeroDriftMode_Standard. +Result hidResetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle); + /// Sets which controller types are supported. This is automatically called with all types in \ref hidInitialize. Result hidSetSupportedNpadStyleSet(HidControllerType type); diff --git a/nx/source/services/hid.c b/nx/source/services/hid.c index bab1f175..c11ffffd 100644 --- a/nx/source/services/hid.c +++ b/nx/source/services/hid.c @@ -809,10 +809,55 @@ Result hidGetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle, float *unk0, return rc; } +Result hidSetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle, HidGyroscopeZeroDriftMode mode) { + Result rc; + u64 AppletResourceUserId; + + rc = appletGetAppletResourceUserId(&AppletResourceUserId); + if (R_FAILED(rc)) + AppletResourceUserId = 0; + + const struct { + u32 SixAxisSensorHandle; + u32 mode; + u64 AppletResourceUserId; + } in = { SixAxisSensorHandle, mode, AppletResourceUserId }; + + return serviceDispatchIn(&g_hidSrv, 79, in, + .in_send_pid = true, + ); +} + +Result hidGetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle, HidGyroscopeZeroDriftMode *mode) { + Result rc; + u64 AppletResourceUserId; + + rc = appletGetAppletResourceUserId(&AppletResourceUserId); + if (R_FAILED(rc)) + AppletResourceUserId = 0; + + const struct { + u32 SixAxisSensorHandle; + u32 pad; + u64 AppletResourceUserId; + } in = { SixAxisSensorHandle, 0, AppletResourceUserId }; + + u32 tmp=0; + rc = serviceDispatchInOut(&g_hidSrv, 80, in, tmp, + .in_send_pid = true, + ); + if (R_SUCCEEDED(rc) && mode) *mode = tmp; + return rc; +} + Result hidResetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle) { return _hidCmdWithInputU32(SixAxisSensorHandle, 72); } +Result hidResetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle) { + return _hidCmdWithInputU32(SixAxisSensorHandle, 81); +} + Result hidSetSupportedNpadStyleSet(HidControllerType type) { return _hidCmdWithInputU32(type, 100); }