-
Notifications
You must be signed in to change notification settings - Fork 0
/
power.sh
executable file
·47 lines (42 loc) · 1.06 KB
/
power.sh
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
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
DEVICE_BATTERY_DIR="/sys/class/power_supply/BAT0"
VOLTAGE="$DEVICE_BATTERY_DIR/voltage_now"
CURRENT="$DEVICE_BATTERY_DIR/current_now"
CHARGE="$DEVICE_BATTERY_DIR/charge_now"
CHARGE_FULL="$DEVICE_BATTERY_DIR/charge_full"
CHARGE_DESIGN="$DEVICE_BATTERY_DIR/charge_full_design"
STATUS="$DEVICE_BATTERY_DIR/status"
r () {
cat $1
}
c () {
echo "scale=3; $1" | bc -l
}
case $1 in
power)
echo $(c "$(r $VOLTAGE) * $(r $CURRENT) / 1000000000000")
;;
charge)
echo $(c "100 * $(r $CHARGE) / $(r $CHARGE_FULL)")
;;
current)
echo $(c "$(r $CURRENT) / 1000000")
;;
voltage)
echo $(c "$(r $VOLTAGE) / 1000000")
;;
status)
echo $(r $STATUS)
;;
annotate)
TIMESTAMP=$(date +"%s")
STATUS=$($0 status)
CHARGE=$($0 charge)
CURRENT=$($0 current)
VOLTAGE=$($0 voltage)
echo $TIMESTAMP,$STATUS,$CHARGE,$CURRENT,$VOLTAGE
;;
*)
echo "USAGE: $0 (power|charge|current|voltage|status|annotate FILE)"
;;
esac