-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpine64-battery.sh
More file actions
executable file
·34 lines (28 loc) · 947 Bytes
/
pine64-battery.sh
File metadata and controls
executable file
·34 lines (28 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
if [ -e "/sys/class/power_supply/battery" ]; then
BATT_PATH="/sys/class/power_supply/battery"
else
BATT_PATH="/sys/class/power_supply/axp20x-battery"
fi
BATT_PRESENT=$(<${BATT_PATH}/present)
if [ "$BATT_PRESENT" = "1" ]; then
BATT_STATUS=$(<${BATT_PATH}/status)
if command -v "bc" >/dev/null 2>&1 ; then
BATT_VOLTAGE=$(<${BATT_PATH}/voltage_now)
BATT_VOLTAGE=$(echo " (($BATT_VOLTAGE/10000)*0.01 ) "|bc)
else
BATT_VOLTAGE=$(awk '{printf ("%0.2f",$1/1000000); }' <${BATT_PATH}/voltage_now)
fi
BATT_CURRENT=$(<${BATT_PATH}/current_now)
((BATT_CURRENT = BATT_CURRENT / 1000))
BATT_CAPACITY=$(<${BATT_PATH}/capacity)
BATT_HEALTH=$(<${BATT_PATH}/health)
echo "Pine64 reports battery detected!"
echo "Status:" $BATT_STATUS
echo "Voltage:" $BATT_VOLTAGE"v"
echo "Current:" $BATT_CURRENT"ma"
echo "Capacity:" $BATT_CAPACITY"%"
echo "Health:" $BATT_HEALTH
else
echo "Pine64 reports battery not detected!"
fi