From 4fa878f4b199017141da3803dd3c2b3177e58ef2 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Mon, 29 Jul 2019 18:22:46 -0400 Subject: [PATCH] Added hidGetSupportedNpadStyleSet. Moved hidSetSupportedNpadStyleSet to match cmd order. Added hidsysGetSupportedNpadStyleSetOfCallerApplet. --- nx/include/switch/services/hid.h | 9 +- nx/include/switch/services/hidsys.h | 7 ++ nx/source/services/hid.c | 175 ++++++++++++++++++---------- nx/source/services/hidsys.c | 50 ++++++++ 4 files changed, 175 insertions(+), 66 deletions(-) diff --git a/nx/include/switch/services/hid.h b/nx/include/switch/services/hid.h index 8d34305b..06f80809 100644 --- a/nx/include/switch/services/hid.h +++ b/nx/include/switch/services/hid.h @@ -705,13 +705,16 @@ u32 hidSixAxisSensorValuesRead(SixAxisSensorValues *values, HidControllerID id, /// Returns 0 when CONTROLLER_PLAYER_1 is connected, otherwise returns 1 for handheld-mode. bool hidGetHandheldMode(void); +/// Sets which controller types are supported. This is automatically called with all types in \ref hidInitialize. +Result hidSetSupportedNpadStyleSet(HidControllerType type); + +/// Gets which controller types are supported. +Result hidGetSupportedNpadStyleSet(HidControllerType *type); + /// This is automatically called with CONTROLLER_PLAYER_{1-8} and CONTROLLER_HANDHELD in \ref hidInitialize. /// count must be <=10. Each entry in buf must be CONTROLLER_PLAYER_{1-8} or CONTROLLER_HANDHELD. Result hidSetSupportedNpadIdType(HidControllerID *buf, size_t count); -/// Sets which controller types are supported. This is automatically called with all types in \ref hidInitialize. -Result hidSetSupportedNpadStyleSet(HidControllerType type); - /// Gets an event with the specified autoclear for the input controller. /// The user *must* close the event when finished with it / before the app exits. /// This is signaled when the \ref hidGetControllerType output is updated for the controller. diff --git a/nx/include/switch/services/hidsys.h b/nx/include/switch/services/hidsys.h index 850f6177..c5942b75 100644 --- a/nx/include/switch/services/hidsys.h +++ b/nx/include/switch/services/hidsys.h @@ -47,6 +47,13 @@ Result hidsysActivateHomeButton(void); Result hidsysActivateSleepButton(void); Result hidsysActivateCaptureButton(void); +/** + * @brief Gets the SupportedNpadStyleSet for the CallerApplet. applet must be initialized in order to use this (uses \ref appletGetAppletResourceUserIdOfCallerApplet). + * @note Only available on [6.0.0+]. + * @param[out] out \ref HidControllerType + */ +Result hidsysGetSupportedNpadStyleSetOfCallerApplet(HidControllerType *out); + /** * @brief Gets the UniquePadIds for the specified controller. * @note Only available on [3.0.0+]. diff --git a/nx/source/services/hid.c b/nx/source/services/hid.c index 9c74a5cb..6c88b4d1 100644 --- a/nx/source/services/hid.c +++ b/nx/source/services/hid.c @@ -723,69 +723,6 @@ static Result _hidGetSharedMemoryHandle(Service* srv, Handle* handle_out) { return rc; } -Result hidSetSupportedNpadIdType(HidControllerID *buf, size_t count) { - Result rc; - u64 AppletResourceUserId; - size_t i; - u32 tmpval=0; - u32 tmpbuf[10]; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; - - if (count > 10) - return MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); - - memset(tmpbuf, 0, sizeof(tmpbuf)); - for (i=0; i= CONTROLLER_UNKNOWN) { - return MAKERESULT(Module_Libnx, LibnxError_BadInput); - } - - tmpbuf[i] = tmpval; - } - - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - u64 AppletResourceUserId; - } *raw; - - ipcSendPid(&c); - - ipcAddSendStatic(&c, tmpbuf, sizeof(u32)*count, 0); - - raw = ipcPrepareHeader(&c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 102; - raw->AppletResourceUserId = AppletResourceUserId; - - 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; -} - static Result _hidCmdWithInputU32(u64 cmd_id, u32 inputval) { Result rc; u64 AppletResourceUserId; @@ -830,6 +767,51 @@ static Result _hidCmdWithInputU32(u64 cmd_id, u32 inputval) { return rc; } +static Result _hidCmdOutU32(u64 cmd_id, u32 *out) { + Result rc; + u64 AppletResourceUserId; + + rc = appletGetAppletResourceUserId(&AppletResourceUserId); + if (R_FAILED(rc)) + AppletResourceUserId = 0; + + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u64 AppletResourceUserId; + } *raw; + + ipcSendPid(&c); + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = cmd_id; + raw->AppletResourceUserId = AppletResourceUserId; + + rc = serviceIpcDispatch(&g_hidSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + u32 out; + } *resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc) && out) *out = resp->out; + } + + return rc; +} + static Result _hidCmdWithInputU64(u64 cmd_id, u64 inputval) { Result rc; u64 AppletResourceUserId; @@ -920,6 +902,73 @@ Result hidSetSupportedNpadStyleSet(HidControllerType type) { return _hidCmdWithInputU32(100, type); } +Result hidGetSupportedNpadStyleSet(HidControllerType *type) { + return _hidCmdOutU32(101, type); +} + +Result hidSetSupportedNpadIdType(HidControllerID *buf, size_t count) { + Result rc; + u64 AppletResourceUserId; + size_t i; + u32 tmpval=0; + u32 tmpbuf[10]; + + rc = appletGetAppletResourceUserId(&AppletResourceUserId); + if (R_FAILED(rc)) + AppletResourceUserId = 0; + + if (count > 10) + return MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); + + memset(tmpbuf, 0, sizeof(tmpbuf)); + for (i=0; i= CONTROLLER_UNKNOWN) { + return MAKERESULT(Module_Libnx, LibnxError_BadInput); + } + + tmpbuf[i] = tmpval; + } + + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u64 AppletResourceUserId; + } *raw; + + ipcSendPid(&c); + + ipcAddSendStatic(&c, tmpbuf, sizeof(u32)*count, 0); + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 102; + raw->AppletResourceUserId = AppletResourceUserId; + + 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; +} + static Result _hidActivateNpad(void) { return _hidCmdWithNoInput(103); } diff --git a/nx/source/services/hidsys.c b/nx/source/services/hidsys.c index 72041798..f7bb7218 100644 --- a/nx/source/services/hidsys.c +++ b/nx/source/services/hidsys.c @@ -186,6 +186,56 @@ Result hidsysActivateCaptureButton(void) { return _hidsysCmdWithResIdAndPid(151); } +static Result _hidsysGetMaskedSupportedNpadStyleSet(u64 AppletResourceUserId, HidControllerType *out) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u64 AppletResourceUserId; + } *raw; + + raw = serviceIpcPrepareHeader(&g_hidsysSrv, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 310; + raw->AppletResourceUserId = g_hidsysAppletResourceUserId; + + Result rc = serviceIpcDispatch(&g_hidsysSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + struct { + u64 magic; + u64 result; + u32 out; + } *resp; + + serviceIpcParse(&g_hidsysSrv, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc) && out) *out = resp->out; + } + + return rc; +} + +Result hidsysGetSupportedNpadStyleSetOfCallerApplet(HidControllerType *out) { + u64 AppletResourceUserId=0; + Result rc=0; + + rc = appletGetAppletResourceUserIdOfCallerApplet(&AppletResourceUserId); + if (R_FAILED(rc) && rc != MAKERESULT(128, 82)) return rc; + + return _hidsysGetMaskedSupportedNpadStyleSet(AppletResourceUserId, out); +} + Result hidsysGetUniquePadsFromNpad(HidControllerID id, u64 *UniquePadIds, size_t count, size_t *total_entries) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);