Skip to content

Commit

Permalink
Add battery percentage (psm) to switch
Browse files Browse the repository at this point in the history
  • Loading branch information
lifajucejo committed Sep 28, 2018
1 parent 4ad6a5f commit a1aec9a
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions frontend/drivers/platform_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ static uint64_t frontend_switch_get_mem_used(void);
// Splash
static uint32_t *splashData = NULL;

static bool psmInitialized = false;

#endif // HAVE_LIBNX

static void get_first_valid_core(char *path_return)
Expand Down Expand Up @@ -163,6 +165,9 @@ static void frontend_switch_deinit(void *data)
splashData = NULL;
}

if (psmInitialized)
psmExit();

#ifndef HAVE_OPENGL
gfxExit();
#endif
Expand Down Expand Up @@ -582,6 +587,17 @@ static void frontend_switch_init(void *data)
#endif // IS_SALAMANDER
#endif // NXLINK

Result rc;
rc = psmInitialize();
if (R_SUCCEEDED(rc))
{
psmInitialized = true;
}
else
{
RARCH_WARN("Error initializing psm\n");
}

rarch_system_info_t *sys_info = runloop_get_system_info();
retro_get_system_info(sys_info);

Expand Down Expand Up @@ -681,8 +697,34 @@ static uint64_t frontend_switch_get_mem_used(void)

static enum frontend_powerstate frontend_switch_get_powerstate(int *seconds, int *percent)
{
// This is fine monkaS
return FRONTEND_POWERSTATE_CHARGED;
if (!psmInitialized)
return FRONTEND_POWERSTATE_NONE;

uint32_t pct;
ChargerType ct;
Result rc;

rc = psmGetBatteryChargePercentage(&pct);
if (!R_SUCCEEDED(rc))
return FRONTEND_POWERSTATE_NONE;

rc = psmGetChargerType(&ct);
if (!R_SUCCEEDED(rc))
return FRONTEND_POWERSTATE_NONE;

*percent = (int)pct;

if (*percent >= 100)
return FRONTEND_POWERSTATE_CHARGED;

switch (ct)
{
case ChargerType_Charger:
case ChargerType_Usb:
return FRONTEND_POWERSTATE_CHARGING;
}

return FRONTEND_POWERSTATE_NO_SOURCE;
}

static void frontend_switch_get_os(char *s, size_t len, int *major, int *minor)
Expand Down

0 comments on commit a1aec9a

Please sign in to comment.