Last active
August 15, 2023 00:46
-
-
Save ItsVixano/77358f86567c954c14f552b716c73a6f to your computer and use it in GitHub Desktop.
Battery Charging Checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /vendor/bin/sh | |
# Copyright (C) 2023 Giovanni Ricca | |
# SPDX-License-Identifier: GPL-3.0-or-later | |
# vars | |
BATTERY_LEVEL_NODE="/sys/class/power_supply/battery/capacity" | |
TIME_TO_FULL_NODE="/sys/class/power_supply/battery/time_to_full_now" | |
POWER_NOW_NODE="/sys/class/power_supply/battery/power_now" | |
CURRENT_NOW_NODE="/sys/class/power_supply/battery/current_now" | |
OUTPUT_FILE="battery_chart.txt" | |
# functions | |
battery_data() { | |
local unix_timestamp=$(date +%s) | |
local battery_level=$(cat "$BATTERY_LEVEL_NODE") | |
local time_to_full=$(cat "$TIME_TO_FULL_NODE") | |
local power_now=$(cat "$POWER_NOW_NODE") | |
local current_now=$(cat "$CURRENT_NOW_NODE") | |
echo "$unix_timestamp | $battery_level | $time_to_full | $power_now | $current_now" | |
} | |
# Clear the output file | |
echo -e "# Timestamp | Battery Level | Time to Full | Power Now | Current Now\n" > "$OUTPUT_FILE" | |
while true; do | |
battery_data >> "$OUTPUT_FILE" | |
sleep 5 | |
if [ "$(cat $TIME_TO_FULL_NODE)" -eq 0 ]; then | |
# Log battery stats for the last time | |
battery_data >> "$OUTPUT_FILE" | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment