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 0000000..75936fa Binary files /dev/null and b/data/battery_icon.bin differ diff --git a/data/charging_icon.bin b/data/charging_icon.bin new file mode 100644 index 0000000..634fb12 Binary files /dev/null and b/data/charging_icon.bin differ diff --git a/nx_main/main.c b/nx_main/main.c index 0ccbd42..f78fc64 100644 --- a/nx_main/main.c +++ b/nx_main/main.c @@ -45,6 +45,7 @@ int main(int argc, char **argv) themeStartup((ThemePreset)theme); textInit(); + powerInit(); menuStartup(); launchInit(); @@ -101,6 +102,7 @@ int main(int argc, char **argv) fontExit(); launchExit(); + powerExit(); plExit(); setsysExit(); diff --git a/nx_main/nx_power.c b/nx_main/nx_power.c new file mode 100644 index 0000000..d5c1949 --- /dev/null +++ b/nx_main/nx_power.c @@ -0,0 +1,43 @@ +#include +#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 0000000..5c89f72 Binary files /dev/null and b/resources/battery_icon.png differ diff --git a/resources/charging_icon.png b/resources/charging_icon.png new file mode 100644 index 0000000..2229590 Binary files /dev/null and b/resources/charging_icon.png differ