From 77957493caadbbed7d45d2a82ca7e5d84f765708 Mon Sep 17 00:00:00 2001 From: robshape Date: Sun, 23 Apr 2023 14:36:58 +0200 Subject: [PATCH] perf: Adjust battery capacity readings for differnt batteries --- README.md | 11 +++--- .../SYSTEM/rg35xx/paks/MinUI.pak/launch.sh | 2 +- src/common/api.c | 38 +++++++++++++------ src/common/defines.h | 1 + 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 2454ea3..4e585d6 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ You can [grab the latest version here](https://github.com/shauninman/union-minui - Add to Favorites - Clear Recently Played +- Adjusted battery readings for 2100, 2600 and 3500 mAh batteries - All extras included in default installation - Improved developer onboarding @@ -121,13 +122,13 @@ Run `./start-toolchain.sh` and then `make all` in the Docker container shell. - ~~Add Clear Recent setting~~ - ~~Refactor Tools to Settings~~ - ~~Add to Favorites~~ -- Improve battery capacity readings (2100 mAh, 2600 mAh, 3500 mAh) -- Adjust overclocking and CPU usage (to maximize battery life) -- Update Installation instructions for microSD cards of all sizes +- ~~Adjust battery capacity readings (2100 mAh, 2600 mAh, 3500 mAh)~~ - Automate installation and update - Update visible MinUI strings and boot logo (show that it is the FinUI fork) - Release using GitHub Actions -- [...Things in the old todo?...](./todo.txt) +- Adjust overclocking and CPU usage (to maximize battery life) +- Improve battery capacity reading accuracy +- [...things in the old todo?...](./todo.txt) ## Disclaimer @@ -140,4 +141,4 @@ Use at your own risk. ## Contributors -robshape, guiburi +@robshape @guiburi diff --git a/skeleton/SYSTEM/rg35xx/paks/MinUI.pak/launch.sh b/skeleton/SYSTEM/rg35xx/paks/MinUI.pak/launch.sh index a6d7ddc..ea9b5ba 100755 --- a/skeleton/SYSTEM/rg35xx/paks/MinUI.pak/launch.sh +++ b/skeleton/SYSTEM/rg35xx/paks/MinUI.pak/launch.sh @@ -39,7 +39,7 @@ cd $(dirname "$0") ####################################### keymon.elf & # &> $LOGS_PATH/keymon.txt & -./batmon.sh &> /mnt/sdcard/batmon.txt & +# ./batmon.sh &> /mnt/sdcard/batmon.txt & ####################################### diff --git a/src/common/api.c b/src/common/api.c index 80051ea..aedfbc1 100644 --- a/src/common/api.c +++ b/src/common/api.c @@ -1388,21 +1388,35 @@ static void POW_quitOverlay(void) { ioctl(gfx.fd_fb, OWLFB_OVERLAY_DISABLE, &pow.oargs); } +static int POW_readBatteryStatus(void) { + #define BATTERY_2100MAH 1 + #define BATTERY_2600MAH 2 + #define BATTERY_3500MAH 3 + + int battery = BATTERY_2600MAH; // Default + int battery_txt = getInt(BATTERY_PATH); + if (battery_txt > 0) { + battery = battery_txt; + } + + int voltage_now = getInt("/sys/class/power_supply/battery/voltage_now"); + + if (battery == BATTERY_2100MAH) { + return ((voltage_now / 10000) - 310); // 310-410 + } else if (battery == BATTERY_2600MAH) { + return ((voltage_now / 10000) - 308); // 308-413? Seems incorrect... + } else if (battery == BATTERY_3500MAH) { + // ???-??? + } + + // Fallback + return getInt("/sys/class/power_supply/battery/capacity"); +} + static void POW_updateBatteryStatus(void) { pow.is_charging = getInt("/sys/class/power_supply/battery/charger_online"); - - // TODO: newer batteries have a different range, ???-??? - // int i = getInt("/sys/class/power_supply/battery/voltage_now") / 10000; // 310-410 - // i -= 310; // ~0-100 - - // Battery ramp is wrong for bigger batteries. Need to log drain for 2600 mAh, 3500 mAh, and - // update range. Reading /capacity seems more accurate for 2600 mAh. - int i = getInt("/sys/class/power_supply/battery/capacity"); - if (i == 0) { // Initial reading is incorrect... - pow.charge = 100; - return; - } + int i = POW_readBatteryStatus(); // worry less about battery and more about the game you're playing if (i>80) pow.charge = 100; diff --git a/src/common/defines.h b/src/common/defines.h index bfc8f2f..457bb70 100644 --- a/src/common/defines.h +++ b/src/common/defines.h @@ -59,6 +59,7 @@ #define FAVORITE_PATH USERDATA_PATH "/.minui/favorite.txt" #define FAUX_FAVORITE_PATH SDCARD_PATH "/Favorites" #define COLLECTIONS_PATH SDCARD_PATH "/Collections" +#define BATTERY_PATH SDCARD_PATH "/battery.txt" #define LAST_PATH "/tmp/last.txt" // transient #define CHANGE_DISC_PATH "/tmp/change_disc.txt"