From 8b86b36393fe6b14d830a3c9d36ae7004f29bdbd Mon Sep 17 00:00:00 2001 From: Daniel Bernard Date: Tue, 9 Oct 2018 17:27:43 -0500 Subject: [PATCH] Add support to display current charge, and indicate whether or not device is charging (#67) * Add support to display current charge, and indicate whether or not device is charging. Updated Makefile.pc to incorporate new icon binaries * Refactored power-related code, added drawIcon Added common power interface * Add battery icon and shift charge text as required --- Makefile.pc | 11 +++++++++ common/common.h | 1 + common/menu.c | 41 ++++++++++++++++++++++++++++++++++ common/power.h | 8 +++++++ data/battery_icon.bin | Bin 0 -> 600 bytes data/charging_icon.bin | Bin 0 -> 540 bytes nx_main/main.c | 2 ++ nx_main/nx_power.c | 43 ++++++++++++++++++++++++++++++++++++ pc_main/pc_power.c | 15 +++++++++++++ resources/battery_icon.png | Bin 0 -> 188 bytes resources/charging_icon.png | Bin 0 -> 380 bytes 11 files changed, 121 insertions(+) create mode 100644 common/power.h create mode 100644 data/battery_icon.bin create mode 100644 data/charging_icon.bin create mode 100644 nx_main/nx_power.c create mode 100644 pc_main/pc_power.c create mode 100644 resources/battery_icon.png create mode 100644 resources/charging_icon.png diff --git a/Makefile.pc b/Makefile.pc index 1d5dc2f..dad81b1 100644 --- a/Makefile.pc +++ b/Makefile.pc @@ -26,6 +26,7 @@ test : pc_main/main.cpp pc_main/pc_launch.c \ build_pc/invalid_icon.bin.o build_pc/folder_icon.bin.o \ build_pc/hbmenu_logo_light.bin.o build_pc/hbmenu_logo_dark.bin.o \ build_pc/theme_icon_dark.bin.o build_pc/theme_icon_light.bin.o \ + build_pc/charging_icon.bin.o build_pc/battery_icon.bin.o \ #build_pc/tahoma24.o build_pc/tahoma12.o build_pc/interuimedium20.o build_pc/interuimedium30.o build_pc/interuiregular14.o build_pc/interuiregular18.o gcc -Wall -O2 -g -DVERSION=\"v$(APP_VERSION)\" $(EXTRA_CFLAGS) `pkg-config freetype2 --cflags` $^ -lsfml-graphics -lsfml-window -lsfml-system -lstdc++ `pkg-config freetype2 --libs` -lm -lz -lconfig -lturbojpeg $(EXTRA_LDFLAGS) -I. -iquote $(DEVKITPRO)/libnx/include -Ibuild_pc -g -o $@ @@ -89,6 +90,16 @@ build_pc/theme_icon_dark.bin.o : data/theme_icon_dark.bin @echo $(notdir $<) @$(bin2o) +build_pc/charging_icon.bin.o : data/charging_icon.bin + mkdir -p $(dir $@) + @echo $(notdir $<) + @$(bin2o) + +build_pc/battery_icon.bin.o : data/battery_icon.bin + mkdir -p $(dir $@) + @echo $(notdir $<) + @$(bin2o) + clean: rm -rf build_pc/ test test.* diff --git a/common/common.h b/common/common.h index fa11c5e..b4cb2b4 100644 --- a/common/common.h +++ b/common/common.h @@ -58,6 +58,7 @@ typedef union { #include "math.h" #include "theme.h" #include "message-box.h" +#include "power.h" void menuStartupPath(void); void menuStartup(void); diff --git a/common/menu.c b/common/menu.c index d9970d6..307b18c 100644 --- a/common/menu.c +++ b/common/menu.c @@ -6,6 +6,8 @@ #include "folder_icon_bin.h" #include "theme_icon_dark_bin.h" #include "theme_icon_light_bin.h" +#include "charging_icon_bin.h" +#include "battery_icon_bin.h" char rootPathBase[PATH_MAX]; char rootPath[PATH_MAX+8]; @@ -107,6 +109,21 @@ static void drawImage(int x, int y, int width, int height, const uint8_t *image, } } +//Draws an RGBA8888 image masked by the passed color. +static void drawIcon(int x, int y, int width, int height, const uint8_t *image, color_t color) { + int tmpx, tmpy; + int pos; + color_t current_color; + + for (tmpy=0; tmpy 100) ? 100 : batteryCharge; + + sprintf(chargeString, "%d%%", batteryCharge); + + int tmpX = GetTextXCoordinate(interuiregular14, 1180, chargeString, 'r'); + + DrawText(interuiregular14, tmpX - 15, 0 + 47 + 10 + 21, themeCurrent.textColor, chargeString); + drawIcon(1180 - 11, 0 + 47 + 10 + 6, 10, 15, battery_icon_bin, themeCurrent.textColor); + if (isCharging) + drawIcon(tmpX - 32, 0 + 47 + 10 + 6, 9, 15, charging_icon_bin, themeCurrent.textColor); + } +} + void drawBackBtn(menu_s* menu, bool emptyDir) { int x_image = 1280 - 252 - 30 - 32; int x_text = 1280 - 216 - 30 - 32; @@ -462,6 +502,7 @@ void menuLoop(void) { #endif drawTime(); + drawCharge(); if (menu->nEntries==0 || hbmenu_state == HBMENU_NETLOADER_ACTIVE) { diff --git a/common/power.h b/common/power.h new file mode 100644 index 0000000..d9a9d34 --- /dev/null +++ b/common/power.h @@ -0,0 +1,8 @@ +#pragma once +#include "common.h" + +void powerInit(void); + +bool powerGetDetails(uint32_t *batteryCharge, bool *isCharging); + +void powerExit(void); \ No newline at end of file diff --git a/data/battery_icon.bin b/data/battery_icon.bin new file mode 100644 index 0000000000000000000000000000000000000000..75936fade2be697638ca5fa98bfbaa6fe14aa17a GIT binary patch literal 600 scmZQzfP>XQ)_*h%5<>@s)XfEI0O9*UjBXxC3?`2*H_FEhuOS;I0MOuyTL1t6 literal 0 HcmV?d00001 diff --git a/data/charging_icon.bin b/data/charging_icon.bin new file mode 100644 index 0000000000000000000000000000000000000000..634fb1227c5a1cf7160988fe86efbcc4816437ec GIT binary patch literal 540 zcmZQzzz#}FOLJRVTBNbdGBA{tm09TO>VC#0-_Xz?prfPn#lgYh2`)8mZf>`La{nVD zB6ea^6B84&4kQo4xw*MD=xVaEvT|5hSitfiHI8pvv@tE(+UL`43Aw{qmk05~!^3xj)BwZh4mNp^n60htGYt)mZ$LkY;8FvUFE1~*!zB+4ANl +#include "../common/common.h" + +static bool psmInitialized; + +bool powerGetDetails(uint32_t *batteryCharge, bool *isCharging) { + ChargerType charger = ChargerType_None; + bool hwReadsSucceeded = false; + Result rc = 0; + + *isCharging = false; + *batteryCharge = 0; + + if (psmInitialized) + { + rc = psmGetBatteryChargePercentage(batteryCharge); + hwReadsSucceeded = R_SUCCEEDED(rc); + rc = psmGetChargerType(&charger); + hwReadsSucceeded &= R_SUCCEEDED(rc); + *isCharging = (charger > ChargerType_None); + } + + return hwReadsSucceeded; +} + +void powerInit(void) { + if (!psmInitialized) + { + Result rc = psmInitialize(); + if (R_SUCCEEDED(rc)) + { + psmInitialized = true; + } + } +} + +void powerExit(void) { + if (psmInitialized) + { + psmExit(); + psmInitialized = false; + } +} \ No newline at end of file diff --git a/pc_main/pc_power.c b/pc_main/pc_power.c new file mode 100644 index 0000000..b16faa9 --- /dev/null +++ b/pc_main/pc_power.c @@ -0,0 +1,15 @@ +#include "../common/common.h" + +void powerInit(void) { + +} + +void powerExit(void) { + +} + +bool powerGetDetails(uint32_t *batteryCharge, bool *isCharging) + *isCharging = false; + *batteryCharge = 100; + return false; +} \ No newline at end of file diff --git a/resources/battery_icon.png b/resources/battery_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..5c89f729081c6e9519bb40e9b9cb17f8ad138627 GIT binary patch literal 188 zcmeAS@N?(olHy`uVBq!ia0vp^AT~b-8<4#FKaLMbu@pObhHwBu4M$1`kk47*5n0T@ zAlMGVjE?b1r9eT+64!{5;QX|b^2DN4hVt@qz0ADq;^f4FRK5J7^x5xhq=1SnJzX3_ zG$tk|I5b@4;o literal 0 HcmV?d00001 diff --git a/resources/charging_icon.png b/resources/charging_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..22295906675708e3b4b52cd165ce3203c8c046a9 GIT binary patch literal 380 zcmeAS@N?(olHy`uVBq!ia0vp^oIuRa!3HGFPCVrWQY^(zo*^7SP{WbZ0a8%l5m^kR z#@pXU!8_%Oe*@nL;x>Qc6@ zrdO}BxCI3#?l)jPapUUMuX@hT&dm*dedok;xW0V(vhU0H@7x9zRaN&6EprG7`I7JI z+N#+#6$qjXSl6ss^S`*b__Kk`yt#8@nS(`yg*Qt%Gcq$XJ6BZv$YWz``=6JWSAOB? zgNI+<+%(SR