diff --git a/nx/include/switch/services/bpc.h b/nx/include/switch/services/bpc.h index cbddcdde..3a67fcbe 100644 --- a/nx/include/switch/services/bpc.h +++ b/nx/include/switch/services/bpc.h @@ -24,4 +24,5 @@ Service* bpcGetServiceSession(void); Result bpcShutdownSystem(void); Result bpcRebootSystem(void); -Result bpcGetSleepButtonState(BpcSleepButtonState *out); ///< [2.0.0+] +Result bpcGetSleepButtonState(BpcSleepButtonState *out); ///< [2.0.0-13.2.1] +Result bpcGetPowerButton(bool* out_is_pushed); ///< [6.0.0+] diff --git a/nx/source/services/bpc.c b/nx/source/services/bpc.c index ea462cdb..e5884f80 100644 --- a/nx/source/services/bpc.c +++ b/nx/source/services/bpc.c @@ -23,6 +23,10 @@ static Result _bpcCmdNoIO(Service *srv, u32 cmd_id) { return serviceDispatch(srv, cmd_id); } +static Result _bpcCmdOutU8(Service* srv, u32 cmd_id, u8* out) { + return serviceDispatchOut(&g_bpcSrv, cmd_id, out); +} + Result bpcShutdownSystem(void) { return _bpcCmdNoIO(&g_bpcSrv, 0); } @@ -32,13 +36,25 @@ Result bpcRebootSystem(void) { } Result bpcGetSleepButtonState(BpcSleepButtonState *out) { - if (hosversionBefore(2,0,0)) + if (!hosversionBetween(2, 14)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); u8 tmp = 0; - Result rc = serviceDispatchOut(&g_bpcSrv, 6, tmp); + Result rc = _bpcCmdOutU8(&g_bpcSrv, 6, &tmp); if (R_SUCCEEDED(rc) && out) *out = tmp; return rc; } + +Result bpcGetPowerButton(bool* out_is_pushed) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + u8 tmp = 0; + Result rc = _bpcCmdOutU8(&g_bpcSrv, 14, &tmp); + + if (out_is_pushed) *out_is_pushed = R_SUCCEEDED(rc) && tmp != 0; + + return rc; +} \ No newline at end of file