-
-
Save brianredbeard/d52c9ba95d9f7c2bc79ff7378b490d33 to your computer and use it in GitHub Desktop.
Colourful Battery Status script for Pine64 SOC board
This file contains hidden or 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 | |
| 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" | |
| # The path to the battery seems to have changed at some point. In the 4.19.x | |
| # kernel the path is now "axp20x-battery". This makes the path configurable. | |
| #BATT_PATH="/sys/class/power_supply/battery/present" | |
| BATT_PATH="/sys/class/power_supply/axp20x-battery" | |
| BATT_PRESENT=$(<${BATT_PATH}/present) | |
| if [ "$BATT_PRESENT" = "1" ]; then | |
| BATT_STATUS=$(<${BATT_PATH}/status) | |
| BATT_VOLTAGE=$(<${BATT_PATH}/voltage_now) | |
| BATT_VOLTAGE=$(echo " (($BATT_VOLTAGE/10000)*0.01 ) "|bc) | |
| BATT_CURRENT=$(<${BATT_PATH}/current_now) | |
| ((BATT_CURRENT = BATT_CURRENT / 1000)) | |
| BATT_CAPACITY=$(<${BATT_PATH}/capacity) | |
| BATT_HEALTH=$(<${BATT_PATH}/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment