-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvolts
More file actions
executable file
·63 lines (53 loc) · 1.79 KB
/
volts
File metadata and controls
executable file
·63 lines (53 loc) · 1.79 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
#######################################################################
# Made by : Ewoud Dronkert
# Licence : GNU GPL v3
# Platform : Raspberry Pi
# Requires : Raspbian, bash, vcgencmd
# Location : ~/bin/
# Name : volts
# Version : 1.1.0
# Date : 2022-10-06
# Purpose : Print formatted list of voltage measurements on the RPi
# Parameters : none
# Settings : none
# Exit : no exit codes used
#######################################################################
# Look up decimal separator for given locale
function GetSep() {
[ -z "$1" ] && return 1
DEFFILE="/usr/share/i18n/locales/$1"
[ ! -f "$DEFFILE" ] && return 2
[ ! -r "$DEFFILE" ] && return 3
SYMBOL=$(cat "$DEFFILE" | grep ^decimal_point | awk '{print $2}' | sed -E 's/^"|"$//g')
if [ "${SYMBOL:0:2}" == "<U" ]; then
UNICODE=$(echo "$SYMBOL" | sed -E 's/^<|>$//g')
echo -ne "\\$UNICODE"
else
echo -n "$SYMBOL"
fi
return 0
}
# Determine POSIX decimal separator which 'vcgencmd' uses in output
# TODO: check error code return
DOT=$(GetSep 'POSIX')
# Determine current locale decimal separator which 'printf' expects as input
LCN="$LC_ALL"
[ -z "$LCN" ] && LCN="$LC_NUMERIC"
[ -z "$LCN" ] && LCN=$(locale | grep ^LC_NUMERIC | cut -d= -f2 | sed -e 's/"//g')
# Use only the part of LCN before the dot
# TODO: check error code return
SEP=$(GetSep "${LCN%%.*}")
[ -z "$SEP" ] && SEP=$DOT
# Measure voltage at different points
for PROBE in core sdram_c sdram_i sdram_p; do
# Get measurement, select part after '='
VOLT=$(vcgencmd measure_volts $PROBE | cut -d= -f2)
# Remove trailing 'V', result is float #.#####
VOLT=${VOLT%V}
# Replace decimal separator if needed
[ "$SEP" != "$DOT" ] && VOLT=${VOLT/$DOT/$SEP}
# Formatted output
printf '%-8s:%6.3f\n' "$PROBE" "$VOLT"
done
exit 0