diff --git a/.travis/.build.sh b/.travis/.build.sh index 4353042..d24edc3 100644 --- a/.travis/.build.sh +++ b/.travis/.build.sh @@ -4,4 +4,4 @@ set -x make clean && make rm .gitattributes .travis.yml devkitpro-pacman.deb icon.jpg LICENSE Makefile README.md -rm -rf .travis build common include romfs source +rm -rf .travis build common include romfs source SwitchIdent.elf SwitchIdent.nacp SwitchIdent.nso SwitchIdent.pfs0 diff --git a/common/power.c b/common/power.c index deda3d6..ae34dfb 100644 --- a/common/power.c +++ b/common/power.c @@ -3,10 +3,7 @@ #include "setcal.h" -static bool psm_initialized = false; -PsmSession psm_session; - -static Result psmIsBatteryChargingEnabled(Service *srv, bool *out) { +static Result psmIsBatteryChargingEnabled(bool *out) { IpcCommand c; ipcInitialize(&c); @@ -20,7 +17,7 @@ static Result psmIsBatteryChargingEnabled(Service *srv, bool *out) { raw->magic = SFCI_MAGIC; raw->cmd_id = 4; - Result rc = serviceIpcDispatch(srv); + Result rc = serviceIpcDispatch(psmGetServiceSession()); if(R_SUCCEEDED(rc)) { IpcParsedCommand r; @@ -42,7 +39,7 @@ static Result psmIsBatteryChargingEnabled(Service *srv, bool *out) { return rc; } -static Result psmGetRawBatteryChargePercentage(Service *srv, u64 *out) { +static Result psmGetRawBatteryChargePercentage(u64 *out) { IpcCommand c; ipcInitialize(&c); @@ -56,7 +53,7 @@ static Result psmGetRawBatteryChargePercentage(Service *srv, u64 *out) { raw->magic = SFCI_MAGIC; raw->cmd_id = 13; - Result rc = serviceIpcDispatch(srv); + Result rc = serviceIpcDispatch(psmGetServiceSession()); if(R_SUCCEEDED(rc)) { IpcParsedCommand r; @@ -78,7 +75,7 @@ static Result psmGetRawBatteryChargePercentage(Service *srv, u64 *out) { return rc; } -static Result psmIsEnoughPowerSupplied(Service *srv, bool *out) { +static Result psmIsEnoughPowerSupplied(bool *out) { IpcCommand c; ipcInitialize(&c); @@ -92,7 +89,7 @@ static Result psmIsEnoughPowerSupplied(Service *srv, bool *out) { raw->magic = SFCI_MAGIC; raw->cmd_id = 14; - Result rc = serviceIpcDispatch(srv); + Result rc = serviceIpcDispatch(psmGetServiceSession()); if(R_SUCCEEDED(rc)) { IpcParsedCommand r; @@ -114,7 +111,7 @@ static Result psmIsEnoughPowerSupplied(Service *srv, bool *out) { return rc; } -static Result psmGetBatteryAgePercentage(Service *srv, u64 *out) { +static Result psmGetBatteryAgePercentage(u64 *out) { IpcCommand c; ipcInitialize(&c); @@ -128,7 +125,7 @@ static Result psmGetBatteryAgePercentage(Service *srv, u64 *out) { raw->magic = SFCI_MAGIC; raw->cmd_id = 15; - Result rc = serviceIpcDispatch(srv); + Result rc = serviceIpcDispatch(psmGetServiceSession()); if(R_SUCCEEDED(rc)) { IpcParsedCommand r; @@ -150,33 +147,6 @@ static Result psmGetBatteryAgePercentage(Service *srv, u64 *out) { return rc; } -Result powerInitialize(void) { - Result rc = 0; - if (psm_initialized) { - return rc; - } - rc = psmInitialize(); - if (R_FAILED(rc)) { - return rc; - } - rc = psmBindStateChangeEvent(&psm_session, 1, 1, 1); - if (R_FAILED(rc)) { - psmExit(); - return rc; - } - psm_initialized = true; - return rc; -} - -void powerExit(void) { - if (!psm_initialized) { - return; - } - psmUnbindStateChangeEvent(&psm_session); - psmExit(); - psm_initialized = false; -} - u32 SwitchIdent_GetBatteryPercent(void) { Result ret = 0; u32 out = 0; @@ -221,7 +191,7 @@ bool SwitchIdent_IsChargingEnabled(void) { Result ret = 0; bool out = 0; - if (R_FAILED(ret = psmIsBatteryChargingEnabled(&psm_session.s, &out))) + if (R_FAILED(ret = psmIsBatteryChargingEnabled(&out))) return -1; return out; @@ -253,7 +223,7 @@ u64 SwitchIdent_GetRawBatteryChargePercentage(void) { Result ret = 0; u64 out = 0; - if (R_FAILED(ret = psmGetRawBatteryChargePercentage(&psm_session.s, &out))) + if (R_FAILED(ret = psmGetRawBatteryChargePercentage(&out))) return -1; return out; @@ -263,7 +233,7 @@ bool SwitchIdent_IsEnoughPowerSupplied(void) { Result ret = 0; bool out = 0; - if (R_FAILED(ret = psmIsEnoughPowerSupplied(&psm_session.s, &out))) + if (R_FAILED(ret = psmIsEnoughPowerSupplied(&out))) return -1; return out; @@ -273,7 +243,7 @@ u64 SwitchIdent_GetBatteryAgePercent(void) { Result ret = 0; u64 out = 0; - if (R_FAILED(ret = psmGetBatteryAgePercentage(&psm_session.s, &out))) + if (R_FAILED(ret = psmGetBatteryAgePercentage(&out))) return -1; return out; diff --git a/common/power.h b/common/power.h index 6f3ad6b..71e9419 100644 --- a/common/power.h +++ b/common/power.h @@ -1,8 +1,6 @@ #ifndef _SWITCHIDENT_POWER_H_ #define _SWITCHIDENT_POWER_H_ -Result powerInitialize(void); -void powerExit(void); u32 SwitchIdent_GetBatteryPercent(void); char *SwitchIdent_GetChargerType(void); bool SwitchIdent_IsCharging(void); diff --git a/source/main.c b/source/main.c index 64504f4..02cb94b 100644 --- a/source/main.c +++ b/source/main.c @@ -9,7 +9,7 @@ static void Term_Services(void) { wlaninfExit(); pcvExit(); - powerExit(); + psmExit(); nsExit(); apmExit(); appletExit(); @@ -56,8 +56,8 @@ static void Init_Services(void) { if (R_FAILED(ret = nsInitialize())) printf("nsInitialize() failed: 0x%x.\n\n", ret); - if (R_FAILED(ret = powerInitialize())) - printf("powerInitialize() failed: 0x%x.\n\n", ret); + if (R_FAILED(ret = psmInitialize())) + printf("psmInitialize() failed: 0x%x.\n\n", ret); if (R_FAILED(ret = pcvInitialize())) printf("pcvInitialize() failed: 0x%x.\n\n", ret);