From cbaa0e359bee299e96c0fc04f7f0730671d87f99 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 6 Mar 2018 23:38:33 -0500 Subject: [PATCH] Added hidPermitVibration() and hidIsVibrationPermitted(). --- nx/include/switch/services/hid.h | 6 +++ nx/source/services/hid.c | 68 ++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/nx/include/switch/services/hid.h b/nx/include/switch/services/hid.h index 0450afa1..f024480d 100644 --- a/nx/include/switch/services/hid.h +++ b/nx/include/switch/services/hid.h @@ -590,3 +590,9 @@ Result hidSetNpadJoyAssignmentModeDual(HidControllerID id); Result hidInitializeVibrationDevice(u32 *VibrationDeviceHandle, HidControllerID id, HidControllerLayoutType type); Result hidSendVibrationValue(u32 *VibrationDeviceHandle, HidVibrationValue *VibrationValue); + +/// Sets whether vibration is allowed, this also affects the config displayed by System Settings. +Result hidPermitVibration(bool flag); + +/// Gets whether vibration is allowed. +Result hidIsVibrationPermitted(bool *flag); diff --git a/nx/source/services/hid.c b/nx/source/services/hid.c index 993deac5..818b8a42 100644 --- a/nx/source/services/hid.c +++ b/nx/source/services/hid.c @@ -654,6 +654,74 @@ Result hidSendVibrationValue(u32 *VibrationDeviceHandle, HidVibrationValue *Vibr return rc; } +Result hidPermitVibration(bool flag) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u8 flag; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 204; + raw->flag = !!flag; + + Result rc = serviceIpcDispatch(&g_hidSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + +Result hidIsVibrationPermitted(bool *flag) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 205; + + Result rc = serviceIpcDispatch(&g_hidSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + u8 flag; + } *resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc) && flag) + *flag = resp->flag & 1; + } + + return rc; +} + Result hidInitializeVibrationDevice(u32 *VibrationDeviceHandle, HidControllerID id, HidControllerLayoutType type) { Result rc=0; Service srv;