Skip to content

Commit 38cd64c

Browse files
committed
dietpi-config: move CPU temp sensor to performance options
And simplify menu/code by using the path itself as index
1 parent 6c83035 commit 38cd64c

1 file changed

Lines changed: 39 additions & 48 deletions

File tree

dietpi/dietpi-config

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,6 @@
134134
# Brightness
135135
G_WHIP_MENU_ARRAY+=('16' ': Display Brightness')
136136

137-
# CPU Temp Sensor
138-
local cpu_temp_sensor_current=$(sed -n 's/^CONFIG_CPU_TEMP_PATH=//p' /boot/dietpi.txt)
139-
[[ -z "$cpu_temp_sensor_current" || "$cpu_temp_sensor_current" == 'auto' ]] && cpu_temp_sensor_current='auto'
140-
G_WHIP_MENU_ARRAY+=('19' ": CPU Temp Sensor : [$cpu_temp_sensor_current]")
141-
142137
# X11 DPI
143138
local xorg_dpi_current=$(sed -n '/^[[:blank:]]*SOFTWARE_XORG_DPI=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
144139
G_WHIP_MENU_ARRAY+=('17' ": X.Org DPI: [${xorg_dpi_current:-N/A}]")
@@ -505,49 +500,6 @@ A long (or insufficiently manufactured) cable may required a higher boost settin
505500
echo "xrandr --dpi $G_WHIP_RETURNED_VALUE" > /etc/X11/Xsession.d/99-dietpi-dpi
506501
REBOOT_REQUIRED=1
507502
fi
508-
elif (( $G_WHIP_RETURNED_VALUE == 19 ))
509-
then
510-
local current_sensor=$(sed -n 's/^CONFIG_CPU_TEMP_PATH=//p' /boot/dietpi.txt)
511-
[[ $current_sensor == 'auto' ]] && current_sensor=''
512-
513-
G_WHIP_MENU_ARRAY=()
514-
local apaths=() aidx=0
515-
local sfile stemp smark
516-
517-
for sfile in /sys/class/thermal/thermal_zone*/temp /sys/class/hwmon/hwmon*/temp*_input
518-
do
519-
[[ -f "$sfile" ]] || continue
520-
stemp=$(cat "$sfile" 2>/dev/null)
521-
[[ "$stemp" =~ ^[0-9]+$ && "$stemp" -gt 0 ]] || continue
522-
(( stemp > 1000 )) && stemp=$((stemp/1000))
523-
524-
smark=""
525-
[[ "$sfile" == "$current_sensor" ]] && smark=" [*]"
526-
527-
G_WHIP_MENU_ARRAY+=("$aidx" "${sfile##/sys/class/} = ${stemp}C${smark}")
528-
apaths+=("$sfile")
529-
((aidx++))
530-
done
531-
532-
G_WHIP_MENU_ARRAY+=('auto' 'Auto-detect (default)')
533-
G_WHIP_MENU_ARRAY+=('custom' 'Enter custom path')
534-
535-
G_WHIP_DEFAULT_ITEM=${current_sensor:-auto}
536-
G_WHIP_MENU "Select CPU temperature sensor:\n\nCurrent: ${current_sensor:-auto}" || return 0
537-
538-
if [[ $G_WHIP_RETURNED_VALUE == 'custom' ]]
539-
then
540-
G_WHIP_DEFAULT_ITEM=$current_sensor
541-
G_WHIP_INPUTBOX 'Enter full sensor path:\n\nExample: /sys/class/hwmon/hwmon1/temp1_input' || return 0
542-
[[ -f "$G_WHIP_RETURNED_VALUE" ]] || { G_WHIP_MSG "Path not found:\n\n$G_WHIP_RETURNED_VALUE"; return 0; }
543-
544-
elif [[ $G_WHIP_RETURNED_VALUE =~ ^[0-9]+$ ]]
545-
then
546-
G_WHIP_RETURNED_VALUE=${apaths[$G_WHIP_RETURNED_VALUE]}
547-
fi
548-
549-
G_CONFIG_INJECT 'CONFIG_CPU_TEMP_PATH=' "CONFIG_CPU_TEMP_PATH=$G_WHIP_RETURNED_VALUE" /boot/dietpi.txt
550-
unset -v G_HW_CPU_TEMP_PATH
551503
fi
552504
}
553505

@@ -1334,6 +1286,10 @@ Latest release notes: https://github.com/starfive-tech/VisionFive2/releases
13341286
G_WHIP_MENU_ARRAY+=('CPU Frequency Limits' ": Max = [$user_frequency_max_text] | Min = [$user_frequency_min_text]")
13351287
fi
13361288

1289+
# CPU Temp Sensor
1290+
local cpu_temp_sensor=$(sed -n 's/^[[:blank:]]*CONFIG_CPU_TEMP_PATH=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
1291+
G_WHIP_MENU_ARRAY+=('CPU Temp Sensor' ": [${cpu_temp_sensor:=auto}]")
1292+
13371293
# RPi extras
13381294
if (( $G_HW_MODEL < 10 ))
13391295
then
@@ -1578,6 +1534,41 @@ If unsure, set any value, 'Ondemand Down Factor' option on the next screen will
15781534
fi
15791535
;;
15801536

1537+
'CPU Temp Sensor')
1538+
1539+
G_WHIP_MENU_ARRAY=(
1540+
'auto' 'Auto-detect (default)'
1541+
'custom' 'Enter custom path'
1542+
'' '●─ Detected sensors '
1543+
)
1544+
1545+
local sfile stemp smark
1546+
for sfile in /sys/devices/platform/coretemp.*/hwmon/hwmon*/temp*_input /sys/class/hwmon/hwmon*/temp*_input /sys/class/thermal/thermal_zone*/temp
1547+
do
1548+
[[ -f $sfile ]] || continue
1549+
read -r stemp < "$sfile" || continue
1550+
disable_error=1 G_CHECK_VALIDINT "$stemp" 1 || continue # trust only positive temperatures
1551+
(( $stemp > 200 )) && stemp=$(( $stemp / 1000 )) # m°C => °C
1552+
1553+
# Mark currently selected sensor node
1554+
[[ $sfile == "$cpu_temp_sensor" ]] && smark=' [*]' || smark=''
1555+
1556+
G_WHIP_MENU_ARRAY+=("$sfile" "$stemp °C$smark")
1557+
done
1558+
1559+
G_WHIP_DEFAULT_ITEM=$cpu_temp_sensor
1560+
G_WHIP_MENU "Select CPU temperature sensor:\n\nCurrent: $cpu_temp_sensor" || return 0
1561+
1562+
if [[ $G_WHIP_RETURNED_VALUE == 'custom' ]]
1563+
then
1564+
G_WHIP_DEFAULT_ITEM=$cpu_temp_sensor
1565+
G_WHIP_INPUTBOX 'Enter full sensor path:\n\nExample: /sys/class/hwmon/hwmon1/temp1_input' || return 0
1566+
[[ -f $G_WHIP_RETURNED_VALUE ]] || { G_WHIP_MSG "Path not found:\n\n$G_WHIP_RETURNED_VALUE"; return 0; }
1567+
fi
1568+
1569+
G_CONFIG_INJECT 'CONFIG_CPU_TEMP_PATH=' "CONFIG_CPU_TEMP_PATH=$G_WHIP_RETURNED_VALUE" /boot/dietpi.txt
1570+
;;
1571+
15811572
*) :;;
15821573
esac
15831574
}

0 commit comments

Comments
 (0)