Make use of xGetServiceSession functions and fix up travis builds

This commit is contained in:
Joel16 2019-07-20 00:22:07 -04:00
parent e89d192ac9
commit 80c008aa9e
4 changed files with 16 additions and 48 deletions

View File

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

View File

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

View File

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

View File

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