Skip to content

Commit

Permalink
rosalina: always try to display battery percentage
Browse files Browse the repository at this point in the history
Even when apps like 3dsident and mGBA open but never relinquish their
mcu::HWC handle.
  • Loading branch information
TuxSH committed Jan 31, 2023
1 parent 777b43b commit faa4a0d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions sysmodules/rosalina/source/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,14 @@ static Result menuUpdateMcuInfo(void)
if (!isServiceUsable("mcu::HWC"))
return -1;

res = mcuHwcInit();
Handle *mcuHwcHandlePtr = mcuHwcGetSessionHandle();
*mcuHwcHandlePtr = 0;

res = srvGetServiceHandle(mcuHwcHandlePtr, "mcu::HWC");
// Try to steal the handle if some other process is using the service (custom SVC)
if (R_FAILED(res))
res = svcControlService(SERVICEOP_STEAL_CLIENT_SESSION, mcuHwcHandlePtr, "mcu::HWC");
if (res != 0)
return res;

// Read single-byte mcu regs 0x0A to 0x0D directly
Expand Down Expand Up @@ -217,7 +223,7 @@ static Result menuUpdateMcuInfo(void)
mcuFwVersion = SYSTEM_VERSION(major - 0x10, minor, 0);
}

mcuHwcExit();
svcCloseHandle(*mcuHwcHandlePtr);
return res;
}

Expand Down Expand Up @@ -365,7 +371,7 @@ static void menuDraw(Menu *menu, u32 selected)
else
Draw_DrawFormattedString(SCREEN_BOT_WIDTH - 10 - SPACING_X * 15, 10, COLOR_WHITE, "%15s", "");

if(R_SUCCEEDED(mcuInfoRes))
if(mcuInfoRes == 0)
{
u32 voltageInt = (u32)batteryVoltage;
u32 voltageFrac = (u32)(batteryVoltage * 100.0f) % 100u;
Expand Down

0 comments on commit faa4a0d

Please sign in to comment.