Last active
August 24, 2019 03:43
-
-
Save pfeerick/05e5715733f00dcf303636c80abff598 to your computer and use it in GitHub Desktop.
Colourful Battery Status script for Pine64 SOC board
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
#!/bin/bash | |
# See https://github.com/pfeerick/pine64-scripts/blob/master/pine64-battery-colour.sh | |
# for updated versions of this script. | |
SWITCH="\033[" | |
NORMAL="${SWITCH}0m" | |
RED="${SWITCH}1;31m" | |
GREEN="${SWITCH}1;32m" | |
YELLOW="${SWITCH}1;33m" | |
PURPLE="${SWITCH}1;35m" | |
BLUE="${SWITCH}1;34m" | |
CYAN="${SWITCH}1;36m" | |
BATT_PRESENT=$(</sys/class/power_supply/battery/present) | |
if [ "$BATT_PRESENT" = "1" ]; then | |
BATT_STATUS=$(</sys/class/power_supply/battery/status) | |
BATT_VOLTAGE=$(</sys/class/power_supply/battery/voltage_now) | |
BATT_VOLTAGE=$(echo " (($BATT_VOLTAGE/10000)*0.01 ) "|bc) | |
BATT_CURRENT=$(</sys/class/power_supply/battery/current_now) | |
((BATT_CURRENT = BATT_CURRENT / 1000)) | |
BATT_CAPACITY=$(</sys/class/power_supply/battery/capacity) | |
BATT_HEALTH=$(</sys/class/power_supply/battery/health) | |
echo -e "${PURPLE}Pine64${NORMAL} reports ${GREEN}battery detected!${NORMAL}" | |
echo -e "${YELLOW}Status:${NORMAL}" $BATT_STATUS | |
echo -e "${YELLOW}Voltage:${NORMAL}" $BATT_VOLTAGE"v" | |
echo -e "${YELLOW}Current:${NORMAL}" $BATT_CURRENT"ma" | |
echo -e "${YELLOW}Capacity:${NORMAL}" $BATT_CAPACITY"%" | |
echo -e "${YELLOW}Health:${NORMAL}" $BATT_HEALTH | |
else | |
echo -e "${PURPLE}Pine64${NORMAL} reports ${RED}no battery connected!${NORMAL}" | |
fi |
FYI, I've got an updated fork in the tree which abstracts the battery path into a single variable (i noticed that in a 4.19.x kernel it used a different path).
Thanks for that. 😄 This script is now part of a collection hosted at https://github.com/pfeerick/pine64-scripts/, and I've just added path detection based on your comment. Please let me know if there are any other changes needed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great! It works perfectly. Thank you a lot