hid: add functions for getting the state of the home, sleep and capture buttons from shmem

This commit is contained in:
ndeadly 2024-06-26 19:35:39 +02:00
parent 0fcf131cb2
commit 69b94f06b6
2 changed files with 69 additions and 0 deletions

View File

@ -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
///@{

View File

@ -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);