From 9442afb6087f40d21516bbab69a4a535415fbbe8 Mon Sep 17 00:00:00 2001 From: Alex Taber Date: Sat, 2 Sep 2017 10:05:42 -0400 Subject: [PATCH] Change stuff with MCUHWC, reboot functionality --- include/common.h | 3 +++ source/draw.c | 18 ++++++++---------- source/main.c | 12 +++++++++--- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/include/common.h b/include/common.h index 9238c03..da740ec 100644 --- a/include/common.h +++ b/include/common.h @@ -41,6 +41,9 @@ static const int THEMES_PER_SCREEN = 4; +Handle mcuhwc_handle; +bool mcuhwc_on; + enum TextureID { TEXTURE_FONT_RESERVED = 0, //used by pp2d for the font TEXTURE_ARROW, diff --git a/source/draw.c b/source/draw.c index ad6c697..0d324fd 100644 --- a/source/draw.c +++ b/source/draw.c @@ -56,17 +56,12 @@ void exit_screens(void) static Result MCUHWC_GetBatteryLevel(u8 *out) // Code taken from daedreth's fork of lpp-3ds { - #define TRY(expr) if(R_FAILED(res = (expr))) { svcCloseHandle(mcuhwcHandle); return res; } - Result res; - Handle mcuhwcHandle; - TRY(srvGetServiceHandle(&mcuhwcHandle, "mcu::HWC")); u32 *cmdbuf = getThreadCommandBuffer(); cmdbuf[0] = 0x50000; - TRY(svcSendSyncRequest(mcuhwcHandle)); + svcSendSyncRequest(mcuhwc_handle); *out = (u8) cmdbuf[2]; - svcCloseHandle(mcuhwcHandle); + svcCloseHandle(mcuhwc_handle); return cmdbuf[1]; - #undef TRY } static int theme_vertical_scroll = 0; @@ -84,9 +79,12 @@ void draw_base_interface(void) pp2d_draw_text(28, 2, 0.6, 0.6, COLOR_WHITE, (tm.tm_sec % 2 == 1) ? ":" : " "); pp2d_draw_textf(34, 2, 0.6, 0.6, COLOR_WHITE, "%.2i", tm.tm_min); - u8 battery_val = 0; - MCUHWC_GetBatteryLevel(&battery_val); - pp2d_draw_textf(350, 2, 0.6, 0.6, COLOR_WHITE, "%i%%", battery_val); + if (mcuhwc_on) + { + u8 battery_val = 0; + MCUHWC_GetBatteryLevel(&battery_val); + pp2d_draw_textf(350, 2, 0.6, 0.6, COLOR_WHITE, "%i%%", battery_val); + } pp2d_draw_on(GFX_BOTTOM); pp2d_draw_rectangle(0, 0, 320, 24, COLOR_ACCENT); diff --git a/source/main.c b/source/main.c index 0cae356..61285cc 100644 --- a/source/main.c +++ b/source/main.c @@ -28,12 +28,17 @@ #include "themes.h" #include "splashes.h" #include "draw.h" +#include "common.h" int init_services(void) { cfguInit(); open_archives(); - ptmSysmInit(); + if (R_FAILED(srvGetServiceHandle(&mcuhwc_handle, "mcu::HWC"))) + { + mcuhwc_on = false; + ptmuInit(); + } else mcuhwc_on = true; return 0; } @@ -41,6 +46,8 @@ int exit_services(void) { close_archives(); cfguExit(); + if (mcuhwc_on) svcCloseHandle(mcuhwc_handle); + else ptmuExit(); return 0; } @@ -88,8 +95,7 @@ int main(void) { exit_screens(); exit_services(); - PTMSYSM_RebootAsync(0); - ptmSysmExit(); + APT_HardwareResetAsync(); } else if (kDown & KEY_L) {