Skip to content

Commit 9f40c15

Browse files
author
crcerror
committed
add: batocera-info, user can manually add temperature sensors
batocera-info - aligned script - added "option" menu and a small help text - users will see a list of thermal inputs by using --temp arg - users can set the detected devices to HOME/user-thermaldev.txt batocera-version, changes will be made later
1 parent 9f4fccd commit 9f40c15

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

package/batocera/core/batocera-scripts/scripts/batocera-info

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
#!/bin/bash
22

3-
### full version (not on login, otherwise you can't log when OpenGL/Vulkan are out of order)
4-
if test "$1" = "--full"; then
5-
FULL_DISPLAY=1
6-
else
7-
FULL_DISPLAY=0
8-
fi
9-
###
3+
##### Options selection #####
104

11-
if test -z "${DISPLAY}"; then
12-
export DISPLAY=$(getLocalXDisplay)
13-
fi
5+
### full version (not on login, otherwise you can't log when OpenGL/Vulkan are out of order)
6+
FULL_DISPLAY=false
7+
OSD_DISPLAY=false
8+
TEMP_DEVICES=false
9+
10+
for i in "$@"; do
11+
i=${i,,}
12+
[ ${i} == "--full" ] && FULL_DISPLAY=true
13+
[ ${i} == "--short" ] && OSD_DISPLAY=true
14+
[ ${i} == "--temp" ] && TEMP_DEVICES=true
15+
[ ${i} == "--help" ] && { echo "$(basename $0) --full --short --temp --help"; exit 0; }
16+
done
1417

18+
###### Functions #######
1519
getCpu() {
1620
test -e "${1}/cpufreq/scaling_max_freq" || return 0
1721

@@ -22,6 +26,30 @@ getCpu() {
2226
cat "${CPU}/cpufreq/scaling_max_freq"
2327
}
2428

29+
###
30+
31+
# export Display
32+
if test -z "${DISPLAY}"; then
33+
export DISPLAY=$(getLocalXDisplay || echo :0.0)
34+
fi
35+
36+
37+
# get temperature or sensors list by --temp arg
38+
# Unit: millidegree Celsius
39+
USER_TEMP=/userdata/system/user_temp.txt
40+
if ${TEMP_DEVICES}; then
41+
printf "%s\t%s\t%s\n" ">Name" "|T m°C" "||Device Path"
42+
while read TEMPS; do
43+
printf "%s\t%s\t%s\n" $(cat $(dirname $TEMPS)/name) $(cat "$TEMPS") ${TEMPS}
44+
done < <(find /sys/class/hwmon/hwmon*/temp*_input /sys/devices/virtual/thermal/thermal_zone*/temp 2>/dev/null)
45+
echo;echo "To pick a sensor manually, copy the 'Device Path' to '${USER_TEMP}'"
46+
exit 0
47+
fi
48+
# check if user setted a sensor device manually
49+
test -s ${USER_TEMP} && TEMPE=$(cat $(<$_) 2>/dev/null) || TEMPE=$(cat /sys/class/hwmon/hwmon*/temp*_input /sys/devices/virtual/thermal/thermal_zone*/temp 2>/dev/null)
50+
TEMPE=$(printf "%s\n" ${TEMPE} | sort -rn | head -1 | sed -e s+"[0-9][0-9][0-9]$"++)
51+
52+
2553
# Detect battery
2654
BATTERY_DIR=$(ls -d /sys/class/power_supply/*{BAT,bat}* 2>/dev/null | head -1)
2755
BATT=$(cat ${BATTERY_DIR}/uevent 2>/dev/null | grep -E "^POWER_SUPPLY_CAPACITY=" | sed -e s+'^POWER_SUPPLY_CAPACITY='++ | sort -rn | head -1)
@@ -60,7 +88,7 @@ if [ -n "${BATTERY_DIR}" ]; then
6088
fi
6189

6290
### short version (for osd)
63-
if test "$1" = "--short"; then
91+
if ${OSD_DISPLAY}; then
6492
DT=$(date +%H:%M)
6593
if test -n "${BATT}"; then
6694
echo "Battery: ${BATT}%${BATTREMAINING} - ${DT}"
@@ -132,9 +160,7 @@ if ! [ -z "$CPU_TDP" ]; then
132160
echo "Ryzen Mobile TDP: ${MAX_TDP}W"
133161
fi
134162

135-
# temperature
136-
# Unit: millidegree Celsius
137-
TEMPE=$(cat /sys/devices/virtual/thermal/thermal_zone*/temp /sys/class/hwmon/hwmon*/temp*_input 2>/dev/null | sort -rn | head -1 | sed -e s+"[0-9][0-9][0-9]$"++)
163+
# output temperature if available
138164
if test -n "${TEMPE}"; then
139165
echo "Temperature: ${TEMPE}°C"
140166
fi
@@ -193,7 +219,7 @@ else
193219
done
194220
fi
195221

196-
if [[ "${FULL_DISPLAY}" != 0 ]]; then
222+
if ${FULL_DISPLAY}; then
197223
# OPENGL
198224
if test "${V_BOARD}" = "x86" -o "${V_BOARD}" = "x86_64"; then
199225
V_OPENGLVERSION=$(DISPLAY=$(getLocalXDisplay) glxinfo 2>/dev/null | grep -E '^OpenGL core profile version string:' | sed -e s+'^OpenGL core profile version string:[ ]*'++)
@@ -234,15 +260,15 @@ else
234260
fi
235261
fi
236262

237-
if [[ "${FULL_DISPLAY}" != 0 ]]; then
263+
if ${FULL_DISPLAY}; then
238264
MACADDR=$(ip a | grep -b1 "$PREFSRC" | awk '/link\/ether/ {print $3}' | sed 's/:/-/g')
239265
if [ -n "$MACADDR" ]; then
240266
echo "Corresponding MAC Address: $MACADDR"
241267
fi
242268
fi
243269

244270
# Boot information
245-
if [[ "${FULL_DISPLAY}" != 0 ]]; then
271+
if ${FULL_DISPLAY}; then
246272
if [ -d /sys/firmware/efi ]; then
247273
echo "UEFI Boot: Yes"
248274
if [ -x /usr/bin/mokutil ]; then

0 commit comments

Comments
 (0)