Updated nx_power.c for latest libnx & changed nx_power psm prefix to 'power'.
This commit is contained in:
parent
29caa76884
commit
1e3f057b23
@ -1,10 +1,11 @@
|
|||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include "../common/common.h"
|
#include "../common/common.h"
|
||||||
|
|
||||||
static bool psmInitialized;
|
static bool powerInitialized;
|
||||||
static bool psmCacheInitialized;
|
static bool powerCacheInitialized;
|
||||||
static uint32_t psmCacheCharge;
|
static uint32_t powerCacheCharge;
|
||||||
static bool psmCacheIsCharging;
|
static bool powerCacheIsCharging;
|
||||||
|
static PsmSession powerSession;
|
||||||
|
|
||||||
bool powerGetDetails(uint32_t *batteryCharge, bool *isCharging) {
|
bool powerGetDetails(uint32_t *batteryCharge, bool *isCharging) {
|
||||||
ChargerType charger = ChargerType_None;
|
ChargerType charger = ChargerType_None;
|
||||||
@ -15,9 +16,9 @@ bool powerGetDetails(uint32_t *batteryCharge, bool *isCharging) {
|
|||||||
*isCharging = false;
|
*isCharging = false;
|
||||||
*batteryCharge = 0;
|
*batteryCharge = 0;
|
||||||
|
|
||||||
if (psmInitialized) {
|
if (powerInitialized) {
|
||||||
if (psmCacheInitialized) {
|
if (powerCacheInitialized) {
|
||||||
rc = psmWaitStateChangeEvent(0);
|
rc = psmWaitStateChangeEvent(&powerSession, 0);
|
||||||
|
|
||||||
if (R_FAILED(rc)) use_cache = true;
|
if (R_FAILED(rc)) use_cache = true;
|
||||||
}
|
}
|
||||||
@ -25,7 +26,7 @@ bool powerGetDetails(uint32_t *batteryCharge, bool *isCharging) {
|
|||||||
rc = psmGetBatteryChargePercentage(batteryCharge);
|
rc = psmGetBatteryChargePercentage(batteryCharge);
|
||||||
hwReadsSucceeded = R_SUCCEEDED(rc);
|
hwReadsSucceeded = R_SUCCEEDED(rc);
|
||||||
if (use_cache) {
|
if (use_cache) {
|
||||||
*isCharging = psmCacheIsCharging;
|
*isCharging = powerCacheIsCharging;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rc = psmGetChargerType(&charger);
|
rc = psmGetChargerType(&charger);
|
||||||
@ -33,9 +34,9 @@ bool powerGetDetails(uint32_t *batteryCharge, bool *isCharging) {
|
|||||||
*isCharging = (charger > ChargerType_None);
|
*isCharging = (charger > ChargerType_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
psmCacheCharge = *batteryCharge;
|
powerCacheCharge = *batteryCharge;
|
||||||
psmCacheIsCharging = *isCharging;
|
powerCacheIsCharging = *isCharging;
|
||||||
psmCacheInitialized = true;
|
powerCacheInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hwReadsSucceeded;
|
return hwReadsSucceeded;
|
||||||
@ -45,18 +46,18 @@ void powerInit(void) {
|
|||||||
uint32_t charge=0;
|
uint32_t charge=0;
|
||||||
bool isCharging=0;
|
bool isCharging=0;
|
||||||
|
|
||||||
psmCacheInitialized = false;
|
powerCacheInitialized = false;
|
||||||
psmCacheCharge = 0;
|
powerCacheCharge = 0;
|
||||||
psmCacheIsCharging = false;
|
powerCacheIsCharging = false;
|
||||||
|
|
||||||
if (!psmInitialized) {
|
if (!powerInitialized) {
|
||||||
Result rc = psmInitialize();
|
Result rc = psmInitialize();
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
rc = psmBindStateChangeEvent(1, 1, 1);
|
rc = psmBindStateChangeEvent(&powerSession, 1, 1, 1);
|
||||||
|
|
||||||
if (R_FAILED(rc)) psmExit();
|
if (R_FAILED(rc)) psmExit();
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
psmInitialized = true;
|
powerInitialized = true;
|
||||||
powerGetDetails(&charge, &isCharging);//Init the cache.
|
powerGetDetails(&charge, &isCharging);//Init the cache.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,9 +65,10 @@ void powerInit(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void powerExit(void) {
|
void powerExit(void) {
|
||||||
if (psmInitialized) {
|
if (powerInitialized) {
|
||||||
|
psmUnbindStateChangeEvent(&powerSession);
|
||||||
psmExit();
|
psmExit();
|
||||||
psmInitialized = false;
|
powerInitialized = false;
|
||||||
psmCacheInitialized = false;
|
powerCacheInitialized = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user