diff --git a/nx/include/switch/services/hid.h b/nx/include/switch/services/hid.h index 1c0467d9..4d3c77b7 100644 --- a/nx/include/switch/services/hid.h +++ b/nx/include/switch/services/hid.h @@ -1539,6 +1539,48 @@ NX_CONSTEXPR bool hidKeyboardStateGetKey(const HidKeyboardState *state, HidKeybo ///@} +///@name HomeButton +///@{ + +/** + * @brief Gets \ref HidHomeButtonState. + * @note Home button shmem must be activated with \ref hidsysActivateHomeButton + * @param[out] states Output array of \ref HidHomeButtonState. + * @param[in] count Size of the states array in entries. + * @return Total output entries. + */ +size_t hidGetHomeButtonStates(HidHomeButtonState *states, size_t count); + +///@} + +///@name SleepButton +///@{ + +/** + * @brief Gets \ref HidSleepButtonState. + * @note Sleep button shmem must be activated with \ref hidsysActivateSleepButton + * @param[out] states Output array of \ref HidSleepButtonState. + * @param[in] count Size of the states array in entries. + * @return Total output entries. + */ +size_t hidGetSleepButtonStates(HidSleepButtonState *states, size_t count); + +///@} + +///@name CaptureButton +///@{ + +/** + * @brief Gets \ref HidCaptureButtonState. + * @note Capture button shmem must be activated with \ref hidsysActivateCaptureButton + * @param[out] states Output array of \ref HidCaptureButtonState. + * @param[in] count Size of the states array in entries. + * @return Total output entries. + */ +size_t hidGetCaptureButtonStates(HidCaptureButtonState *states, size_t count); + +///@} + ///@name Npad ///@{ diff --git a/nx/source/services/hid.c b/nx/source/services/hid.c index 60e9d00d..31d73951 100644 --- a/nx/source/services/hid.c +++ b/nx/source/services/hid.c @@ -275,6 +275,33 @@ size_t hidGetKeyboardStates(HidKeyboardState *states, size_t count) { return total; } +size_t hidGetHomeButtonStates(HidHomeButtonState *states, size_t count) { + HidSharedMemory *sharedmem = (HidSharedMemory*)hidGetSharedmemAddr(); + if (sharedmem == NULL) + diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized)); + + size_t total = _hidGetStates(&sharedmem->home_button.lifo.header, sharedmem->home_button.lifo.storage, 17, offsetof(HidHomeButtonStateAtomicStorage,state), offsetof(HidHomeButtonState,sampling_number), states, sizeof(HidHomeButtonState), count); + return total; +} + +size_t hidGetSleepButtonStates(HidSleepButtonState *states, size_t count) { + HidSharedMemory *sharedmem = (HidSharedMemory*)hidGetSharedmemAddr(); + if (sharedmem == NULL) + diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized)); + + size_t total = _hidGetStates(&sharedmem->sleep_button.lifo.header, sharedmem->sleep_button.lifo.storage, 17, offsetof(HidSleepButtonStateAtomicStorage,state), offsetof(HidSleepButtonState,sampling_number), states, sizeof(HidSleepButtonState), count); + return total; +} + +size_t hidGetCaptureButtonStates(HidCaptureButtonState *states, size_t count) { + HidSharedMemory *sharedmem = (HidSharedMemory*)hidGetSharedmemAddr(); + if (sharedmem == NULL) + diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized)); + + size_t total = _hidGetStates(&sharedmem->capture_button.lifo.header, sharedmem->capture_button.lifo.storage, 17, offsetof(HidCaptureButtonStateAtomicStorage,state), offsetof(HidCaptureButtonState,sampling_number), states, sizeof(HidCaptureButtonState), count); + return total; +} + void hidInitializeNpad(void) { Result rc = _hidActivateNpad(); if (R_FAILED(rc)) diagAbortWithResult(rc);