From 8cc4e180267c348744230fc0fa6489f945ce71e3 Mon Sep 17 00:00:00 2001 From: robshape Date: Sun, 28 May 2023 21:30:18 +0200 Subject: [PATCH] test: Add battery time monitor (credits: zoli0726) --- .../SYSTEM/rg35xx/paks/MinUI.pak/launch.sh | 1 + .../SYSTEM/rg35xx/paks/MinUI.pak/timemon.sh | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100755 skeleton/SYSTEM/rg35xx/paks/MinUI.pak/timemon.sh diff --git a/skeleton/SYSTEM/rg35xx/paks/MinUI.pak/launch.sh b/skeleton/SYSTEM/rg35xx/paks/MinUI.pak/launch.sh index dd81e83..23f7200 100755 --- a/skeleton/SYSTEM/rg35xx/paks/MinUI.pak/launch.sh +++ b/skeleton/SYSTEM/rg35xx/paks/MinUI.pak/launch.sh @@ -46,6 +46,7 @@ cd $(dirname "$0") keymon.elf & # &> $LOGS_PATH/keymon.txt & # ./batmon.sh &> /mnt/sdcard/batmon.txt & +# ./timemon.sh & ####################################### diff --git a/skeleton/SYSTEM/rg35xx/paks/MinUI.pak/timemon.sh b/skeleton/SYSTEM/rg35xx/paks/MinUI.pak/timemon.sh new file mode 100755 index 0000000..a1e2095 --- /dev/null +++ b/skeleton/SYSTEM/rg35xx/paks/MinUI.pak/timemon.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +incrementValueInFile() { + local filename="$1" + local current_value new_value + + # Check if the file exists + if [ -f "$filename" ]; then + # Read the current value from the file + current_value=$(cat "$filename") + + # Increment the value by 30 seconds + new_value=$((current_value + 30)) + + # Write the new value back to the file + echo "$new_value" > "$filename" + fi +} + +# File paths +charger_file="/sys/class/power_supply/battery/charger_online" +capacity_file="/sys/class/power_supply/battery/capacity" +stats_file="/mnt/sdcard/timemon.txt" + +touch "$stats_file" +while true; do + # Read the content of charger_online.txt and capacity.txt + charger_status=$(cat "$charger_file") + capacity=$(cat "$capacity_file") + + if [ "$charger_status" -eq 1 ] && [ "$capacity" -eq 300 ]; then + # Reset the value of timemon.txt to 0 seconds + echo 0 > "$stats_file" + elif [ "$charger_status" -eq 0 ]; then + # Increment the value of timemon.txt by 30 seconds + incrementValueInFile "$stats_file" + fi + + sleep 30 +done