diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index c5c38c7c..3c6ce3df 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -263,6 +263,23 @@ Result appletGetCradleStatus(u8 *status); */ Result appletGetBootMode(PmBootMode *mode); +/** + * @brief Request to AcquireSleepLock. + * @note On success, this then uses cmd GetAcquiredSleepLockEvent and waits on that event. + */ +Result appletRequestToAcquireSleepLock(void); + +/** + * @brief Release the SleepLock. + */ +Result appletReleaseSleepLock(void); + +/** + * @brief Release the SleepLock transiently. + * @note On success, this then uses cmd GetAcquiredSleepLockEvent and waits on that event. + */ +Result appletReleaseSleepLockTransiently(void); + /** * @brief Pushes a storage to the general channel. Used for sending requests to qlaunch. * @note This is not usable under an Application, however it is usable under a LibraryApplet. diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index 300bd96d..abb24115 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -1272,6 +1272,36 @@ static Result _appletGetCurrentFocusState(u8 *out) { return rc; } +static Result _appletGetAcquiredSleepLockEvent(Event *out_event) { + return _appletGetEvent(&g_appletICommonStateGetter, out_event, 13, false); +} + +static Result _appletWaitAcquiredSleepLockEvent(void) { + Result rc=0; + Event tmpevent={0}; + + rc = _appletGetAcquiredSleepLockEvent(&tmpevent); + if (R_SUCCEEDED(rc)) rc = eventWait(&tmpevent, U64_MAX); + eventClose(&tmpevent); + return rc; +} + +Result appletRequestToAcquireSleepLock(void) { + Result rc = _appletCmdNoIO(&g_appletICommonStateGetter, 10); + if (R_SUCCEEDED(rc)) rc = _appletWaitAcquiredSleepLockEvent(); + return rc; +} + +Result appletReleaseSleepLock(void) { + return _appletCmdNoIO(&g_appletICommonStateGetter, 11); +} + +Result appletReleaseSleepLockTransiently(void) { + Result rc = _appletCmdNoIO(&g_appletICommonStateGetter, 12); + if (R_SUCCEEDED(rc)) rc = _appletWaitAcquiredSleepLockEvent(); + return rc; +} + Result appletPushToGeneralChannel(AppletStorage *s) { return _appletCmdInStorage(&g_appletICommonStateGetter, s, 20); }