switch: fix power interface

This commit is contained in:
cpasjuste 2021-06-24 14:32:27 +02:00
parent 8249883616
commit 84f61daaab
2 changed files with 14 additions and 8 deletions

View File

@ -29,11 +29,10 @@
SDL_bool SDL_bool
SDL_GetPowerInfo_SWITCH(SDL_PowerState *state, int *seconds, SDL_GetPowerInfo_SWITCH(SDL_PowerState *state, int *seconds,
int *percent) int *percent) {
{
PsmChargerType chargerType; PsmChargerType chargerType;
u32 charge; u32 charge;
double age; //double age;
Result rc; Result rc;
rc = psmGetChargerType(&chargerType); rc = psmGetChargerType(&chargerType);
@ -47,13 +46,16 @@ SDL_GetPowerInfo_SWITCH(SDL_PowerState * state, int *seconds,
psmGetBatteryChargePercentage(&charge); psmGetBatteryChargePercentage(&charge);
*percent = (int) charge; *percent = (int) charge;
psmGetBatteryAgePercentage(&age); // TODO: use approximation for now, ~6h00 for a fully charged battery
*seconds = (int) age; *seconds = ((int) charge * 21600) / 100;
//psmGetBatteryAgePercentage(&age);
//*seconds = (int) age;
if(chargerType == PsmChargerType_EnoughPower) { if (chargerType == PsmChargerType_Unconnected) {
*state = SDL_POWERSTATE_ON_BATTERY;
} else if (chargerType == PsmChargerType_EnoughPower) {
*state = SDL_POWERSTATE_CHARGED; *state = SDL_POWERSTATE_CHARGED;
} else { } else {
// TODO: check if device charging...
*state = SDL_POWERSTATE_CHARGING; *state = SDL_POWERSTATE_CHARGING;
} }

View File

@ -139,6 +139,8 @@ SWITCH_VideoInit(_THIS)
display.driverdata = NULL; display.driverdata = NULL;
SDL_AddVideoDisplay(&display, SDL_FALSE); SDL_AddVideoDisplay(&display, SDL_FALSE);
// init psm service
psmInitialize();
// init touch // init touch
SWITCH_InitTouch(); SWITCH_InitTouch();
// init keyboard // init keyboard
@ -169,6 +171,8 @@ SWITCH_VideoQuit(_THIS)
SWITCH_QuitMouse(); SWITCH_QuitMouse();
// exit software keyboard // exit software keyboard
SWITCH_QuitSwkb(); SWITCH_QuitSwkb();
// exit psm service
psmExit();
} }
void void