diff --git a/include/arm11/menu/battery.h b/include/arm11/menu/battery.h
new file mode 100644
index 0000000..ddb915f
--- /dev/null
+++ b/include/arm11/menu/battery.h
@@ -0,0 +1,32 @@
+#pragma once
+
+/*
+ * This file is part of fastboot 3DS
+ * Copyright (C) 2017 derrek, profi200, d0k3
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+
+#include "types.h"
+
+ /**
+ * @brief Battery state description struct.
+ */
+typedef struct {
+ u32 percent; ///< Current percent.
+ bool charging; ///< True if charging.
+} BatteryState;
+
+void getBatteryState(BatteryState *battery);
diff --git a/source/arm11/menu/battery.c b/source/arm11/menu/battery.c
new file mode 100644
index 0000000..ce2c6c0
--- /dev/null
+++ b/source/arm11/menu/battery.c
@@ -0,0 +1,29 @@
+#pragma once
+
+/*
+ * This file is part of fastboot 3DS
+ * Copyright (C) 2017 derrek, profi200, d0k3
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+
+#include "arm11/hardware/i2c.h"
+#include "arm11/menu/battery.h"
+
+void getBatteryState(BatteryState *battery)
+{
+ battery->percent = I2C_readReg(I2C_DEV_MCU, 0x0B);
+ battery->charging = (I2C_readReg(I2C_DEV_MCU, 0x0F) & (1<<4));
+}
diff --git a/source/arm11/menu/menu.c b/source/arm11/menu/menu.c
index ca09a4f..9e03eeb 100644
--- a/source/arm11/menu/menu.c
+++ b/source/arm11/menu/menu.c
@@ -21,6 +21,7 @@
#include
#include
#include "types.h"
+#include "arm11/menu/battery.h"
#include "arm11/menu/bootinfo.h"
#include "arm11/menu/bootslot.h"
#include "arm11/menu/menu.h"
@@ -35,7 +36,7 @@
#include "hardware/gfx.h"
#include "fs.h" // for drive names
-
+static BatteryState battery;
void menuBuildDescString(char* desc, u32 flags, u32 index, const char* desc_raw)
{
@@ -124,7 +125,10 @@
// print bootinfo
consoleSetCursor(desc_con, 0, 4);
ee_printf(" Model: %s\n", bootinfo.model);
- ee_printf(" %s\n\n", bootinfo.bootEnv);
+ ee_printf(" %s\n", bootinfo.bootEnv);
+ ee_printf(" Battery: %s%lu%s %%" ESC_RESET "\n\n",
+ ((battery.percent <= 20) && !battery.charging) ? ESC_SCHEME_BAD : ESC_SCHEME_GOOD,
+ battery.percent, (battery.charging) ? "+" : "");
for (u32 i = 0; i < sizeof(mount_paths) / sizeof(const char*); i++)
{
ee_printf(" " ESC_SCHEME_WEAK "%s" ESC_RESET " %s\n", mount_paths[i],
@@ -297,6 +301,9 @@
u32 index = 0;
u32 last_index = (u32) -1;
+ u64 n_vblanks = 0;
+ getBatteryState(&battery);
+
// main menu processing loop
while (!g_startFirmLaunch)
{
@@ -304,8 +311,12 @@
if(hidGetPowerButton(false))
break; // deinits & poweroff outside of this function
+ // handle battery state
+ if ((++n_vblanks % 250) == 0)
+ getBatteryState(&battery);
+
// update menu and description (on demand)
- if ((index != last_index) || (curr_menu != last_menu)) {
+ if ((index != last_index) || (curr_menu != last_menu) || (n_vblanks % 250 == 0)) {
menuDraw(curr_menu, menu_con, index);
menuShowDesc(curr_menu, desc_con, index);
last_index = index;