new reworked fan handling, should be much more dynamic and able to go to 14 fans

This commit is contained in:
inxi-svn 2009-07-28 18:17:24 +00:00
parent 890293e9d1
commit fcf62e4d52

252
inxi
View file

@ -1,8 +1,8 @@
#!/bin/bash
########################################################################
#### Script Name: inxi
#### version: 1.0.98-b1
#### Date: 27 July 2009
#### version: 1.0.99-b1
#### Date: 28 July 2009
########################################################################
#### SPECIAL THANKS
########################################################################
@ -258,6 +258,7 @@ DEBUG_BUFFER_INDEX=0
# Defaults to 2, make this 1 for normal, 0 for no colorcodes at all. Set to any other valid scheme you like.
# Same as runtime parameter.
DEFAULT_SCHEME=2
# Default indentation level
INDENT=10
@ -277,6 +278,9 @@ KONVI=0
# This is a variable that controls how many parameters inxi will parse in a /proc/<pid>/cmdline file before stopping.
PARAMETER_LIMIT=30
SCHEME=0 # set default scheme
# this is set in user prefs file, to override dynamic temp1/temp2 determination of sensors output in case
# cpu runs colder than mobo
SENSORS_CPU_NO=''
# SHOW_IRC=1 to avoid showing the irc client version number, or SHOW_IRC=0 to disable client information completely.
SHOW_IRC=2
# Verbosity level defaults to 0, this can also be set with -v0, -v2, -v3, etc as a parameter.
@ -2354,7 +2358,8 @@ get_graphics_x_data()
# new method added since radeon and X.org and the disappearance of <X server name> version : ...etc
# Later on, the normal textual version string returned, e.g. like: X.Org version: 6.8.2
# A failover mechanism is in place. (if $x_version is empty, the release number is parsed instead)
x_version=$( xdpyinfo | gawk '/version:/ {
x_version=$( xdpyinfo | gawk '
/version:/ {
print $NF
}' )
if [[ -z $x_version ]];then
@ -3010,7 +3015,8 @@ get_sensors_data()
IFS=","
if [[ $B_SENSORS == 'true' ]];then
# note: non-configured sensors gives error message, which we need to redirect to stdout
A_SENSORS_DATA=( $( sensors | gawk '
A_SENSORS_DATA=( $(
sensors | gawk -v userCpuNo="$SENSORS_CPU_NO" '
BEGIN {
IGNORECASE=1
moboTemp=""
@ -3020,12 +3026,11 @@ get_sensors_data()
tempUnit=""
temp1=""
temp2=""
cpuFan=""
psFan=""
sysFan1=""
sysFan2=""
sysFan3=""
cpuFanReal=""
indexCountaFanReal=0
indexCountaFanWorking=0
i=""
j=""
sysFanString=""
tempFanType="" # set to 1 or 2
}
# dumping the extra + signs, nobody has negative temps
@ -3060,63 +3065,66 @@ get_sensors_data()
# note: can be cpu fan:, cpu fan speed:, etc
/^CPU Fan(.*):/ {
if ( $3 ~ /(.+):/ ){
cpuFan=$4
aFanReal[1]=$4
}
else {
cpuFan=$3
aFanReal[1]=$3
}
}
/^fan1:|FAN1 Speed:|CHASSIS(1)? FAN Speed:/ {
if ( $1 == "fan1:" ){
sysFan1=$2
/^(M\/B|MB|SYS) Fan(.*):/ {
if ( $3 ~ /(.+):/ ){
aFanReal[2]=$4
}
else if ( $2 == "Speed:" ) {
sysFan1=$3
}
else if ( $3 == "Speed:" ) {
sysFan1=$4
}
}
/^fan2:|FAN2 Speed:|CHASSIS2 FAN Speed:/ {
if ( $1 == "fan2:" ){
sysFan2=$2
}
else if ( $2 == "Speed:" ) {
sysFan2=$3
}
else if ( $3 == "Speed:" ) {
sysFan2=$4
}
}
/^fan3:|FAN3 Speed:|CHASSIS3 FAN Speed:/ {
if ( $1 == "fan3:" ){
sysFan3=$2
}
else if ( $2 == "Speed:" ) {
sysFan3=$3
}
else if ( $3 == "Speed:" ) {
sysFan3=$4
else {
aFanReal[2]=$3
}
}
/Power_FAN Speed:|P\/S Fan:/ {
psFan=$3
aFanReal[3]=$3
}
/POWER FAN Speed:/ {
psFan=$4
aFanReal[3]=$4
}
/^FAN1 Speed:|CHASSIS(1)? FAN Speed:/ {
if ( $2 == "Speed:" ) {
aFanReal[4]=$3
}
else if ( $3 == "Speed:" ) {
aFanReal[4]=$4
}
}
/^FAN([2-9]) Speed:|CHASSIS([2-9]) FAN Speed:/ {
sysFanNu=gensub( /(FAN|CHASSIS)([2-9])( FAN)? Speed:/, "\\2", 1, $0 )
if ( sysFanNu ~ /([2-9])/ ) {
sysFanNu = sysFanNu + 3
if ( $2 == "Speed:" ) {
aFanReal[sysFanNu]=$3
}
else if ( $3 == "Speed:" ) {
aFanReal[sysFanNu]=$4
}
}
}
/^fan([0-9]+):/ {
sysFanNu=gensub( /fan([0-9]+):/, "\\1", 1, $1 )
if ( sysFanNu ~ /([0-9]+)/ ) {
aFanWorking[sysFanNu]=$2
}
}
END {
# first we need to handle the case where we have to determine which temp/fan to use for cpu and mobo:
# note, for rare cases of weird cool cpus, user can override in their prefs and force the assignment
if ( temp1 != "" && temp2 != "" ){
if ( temp1 >= temp2 ){
if ( temp1 >= temp2 || userCpuNo == 1 ){
tempFanType=1
}
else {
tempFanType=2
}
}
# then get the real cpu temp
# then get the real cpu temp, best guess is hottest is real
if ( cpuTemp != "" ){
cpuTempReal=cpuTemp
}
@ -3131,6 +3139,7 @@ get_sensors_data()
else {
cpuTempReal=temp1
}
# then the real mobo temp
if ( moboTemp != "" ){
moboTempReal=moboTemp
@ -3148,25 +3157,48 @@ get_sensors_data()
}
# then the cpu fan speed
if ( cpuFan != "" ) {
cpuFanReal=cpuFan
if ( aFanReal[0] != "" ) {
if ( tempFanType == 1 && aFanWorking[1] != "" ) {
aFanReal[0]=aFanWorking[1]
}
else if ( tempFanType == 2 && aFanWorking[2] != "" ) {
aFanReal[0]=aFanWorking[2]
}
}
else if ( tempFanType == 1 && sysFan1 != "" ) {
cpuFanReal=sysFan1
# then set mobo fan if missing
if ( ! 2 in aFanReal ) {
aFanReal[2] = ""
}
else if ( tempFanType == 2 && sysFan2 != "" ) {
cpuFanReal=sysFan2
# then set psu fan if missing
if ( ! 3 in aFanReal ) {
aFanReal[3] = ""
}
# then double check the sys fans for duplication
if ( cpuFanReal == sysFan1 && cpuFanReal != 0 ) {
sysFan1 = ""
# then we need to get the actual numeric max array count for both fan arrays
for (i = 0; i <= 14; i++) {
if ( i in aFanReal && i > indexCountaFanReal ) {
indexCountaFanReal=i
}
}
if ( cpuFanReal == sysFan2 && cpuFanReal != 0 ) {
sysFan2 = ""
for (i = 0; i <= 14; i++) {
if ( i in aFanWorking && i > indexCountaFanWorking ) {
indexCountaFanWorking=i
}
}
if ( cpuFanReal == sysFan3 && cpuFanReal != 0 ) {
sysFan3 = ""
# clear out any duplicates. Primary fan real trumps fan working always if same speed
for (i = 1; i <= indexCountaFanReal; i++) {
if ( i in aFanReal && aFanReal[i] != "" && aFanReal[i] != 0 ) {
for (j = 1; j <= indexCountaFanWorking; j++) {
if ( j in aFanWorking && aFanReal[i] == aFanWorking[j] ) {
aFanWorking[j] = ""
}
}
}
}
# then construct the sys_fan string for echo
for (j = 1; j <= indexCountaFanWorking; j++) {
sysFanString = sysFanString "," aFanWorking[j]
}
# and then build the temps:
@ -3178,11 +3210,12 @@ get_sensors_data()
}
# if they are ALL null, print error message. psFan is not used in output currently
if ( cpuTempReal == "" && moboTempReal == "" && cpuFanReal == "" && sysFan1Real == "" && sysFan2Real == "" && sysFan3Real == "" ) {
if ( cpuTempReal == "" && moboTempReal == "" && sysFanString == "" ) {
print "No active sensors found. Have you configured your sensors yet?"
}
else {
print cpuTempReal "," moboTempReal "," cpuFanReal "," sysFan1 "," sysFan2 "," sysFan3 "," psFan
# then build it: afanreals: 1 - cpu; 2 - mobo; 3 - psu
print cpuTempReal "," moboTempReal "," aFanReal[1] "," aFanReal[2] "," aFanReal[3] sysFanString
}
}
'
@ -4052,8 +4085,8 @@ print_partition_data()
print_sensors_data()
{
eval $LOGFS
local mobo_temp='' cpu_temp='' cpu_fan='' sys_fan1='' sys_fan2='' sys_fan3=''
local ps_fan='' temp_data='' fan_data='' b_is_error='false'
local mobo_temp='' cpu_temp='' cpu_fan='' mobo_fan='' ps_fan='' sys_fans=''
local temp_data='' fan_data='' b_is_error='false'
get_sensors_data
# initial error cases, for missing app or unconfigured sensors
@ -4061,50 +4094,67 @@ print_sensors_data()
cpu_temp=${A_SENSORS_DATA[0]}
b_is_error='true'
else
if [[ -n ${A_SENSORS_DATA[0]} ]];then
cpu_temp=${A_SENSORS_DATA[0]}
else
cpu_temp='N/A'
fi
cpu_temp="${C1}System Temperatures: cpu:${C2} $cpu_temp "
if [[ -n ${A_SENSORS_DATA[1]} ]];then
mobo_temp=${A_SENSORS_DATA[1]}
else
mobo_temp='N/A'
fi
mobo_temp="${C1}mobo:${C2} $mobo_temp "
# we need to make sure it's either cpu fan OR cpu fan and sys fan 1
if [[ -n ${A_SENSORS_DATA[2]} ]];then
cpu_fan="${A_SENSORS_DATA[2]}"
elif [[ -z ${A_SENSORS_DATA[2]} && -n ${A_SENSORS_DATA[3]} ]];then
cpu_fan="${A_SENSORS_DATA[3]}"
else
cpu_fan='N/A'
fi
cpu_fan="${C1}Fan Speeds (in rpm): cpu:${C2} $cpu_fan "
# then set the sys fans, if present or 0. sys fan 1 only if cpu fan is present,
# otherwise fan1: is cpu fan
if [[ -n ${A_SENSORS_DATA[2]} && -n ${A_SENSORS_DATA[3]} ]];then
sys_fan1="${C1}sys-1:${C2} ${A_SENSORS_DATA[3]} "
fi
if [[ -n ${A_SENSORS_DATA[4]} ]];then
sys_fan2="${C1}sys-2:${C2} ${A_SENSORS_DATA[4]} "
fi
if [[ -n ${A_SENSORS_DATA[5]} ]];then
sys_fan3="${C1}sys-3:${C2} ${A_SENSORS_DATA[5]} "
fi
if [[ -n ${A_SENSORS_DATA[6]} ]];then
ps_fan="${C1}ps:${C2} ${A_SENSORS_DATA[6]} "
fi
for (( i=0; i < ${#A_SENSORS_DATA[@]}; i++ ))
do
case $i in
0)
if [[ -n ${A_SENSORS_DATA[0]} ]];then
cpu_temp=${A_SENSORS_DATA[0]}
else
cpu_temp='N/A'
fi
cpu_temp="${C1}System Temperatures: cpu:${C2} $cpu_temp "
;;
1)
if [[ -n ${A_SENSORS_DATA[1]} ]];then
mobo_temp=${A_SENSORS_DATA[1]}
else
mobo_temp='N/A'
fi
mobo_temp="${C1}mobo:${C2} $mobo_temp "
;;
2)
# we need to make sure it's either cpu fan OR cpu fan and sys fan 1
if [[ -n ${A_SENSORS_DATA[2]} ]];then
cpu_fan="${A_SENSORS_DATA[2]}"
elif [[ -z ${A_SENSORS_DATA[2]} && -n ${A_SENSORS_DATA[3]} ]];then
cpu_fan="${A_SENSORS_DATA[3]}"
else
cpu_fan='N/A'
fi
cpu_fan="${C1}Fan Speeds (in rpm): cpu:${C2} $cpu_fan "
;;
3)
if [[ -n ${A_SENSORS_DATA[3]} ]];then
mobo_fan="${C1}mobo:${C2} ${A_SENSORS_DATA[3]} "
fi
;;
4)
if [[ -n ${A_SENSORS_DATA[4]} ]];then
ps_fan="${C1}ps:${C2} ${A_SENSORS_DATA[4]} "
fi
;;
[5-9]|10|11|12|13|14)
if [[ -n ${A_SENSORS_DATA[$i]} ]];then
fan_number=$(( $i - 4 )) # sys fans start on array key 5
sys_fans="$sys_fans${C1}sys-$fan_number:${C2} ${A_SENSORS_DATA[$i]} "
fi
;;
# # then set the sys fans, if present or 0. sys fan 1 only if cpu fan is present,
# # otherwise fan1: is cpu fan
# if [[ -n ${A_SENSORS_DATA[2]} && -n ${A_SENSORS_DATA[3]} ]];then
# sys_fan1="${C1}sys-1:${C2} ${A_SENSORS_DATA[3]} "
# fi
esac
done
fi
temp_data="$cpu_temp$mobo_temp"
temp_data=$( create_print_line "Sensors:" "$temp_data" )
print_screen_output "$temp_data"
# don't print second or subsequent lines if error data
if [[ $b_is_error != 'true' ]];then
fan_data="$cpu_fan$sys_fan1$sys_fan2$sys_fan3$ps_fan"
fan_data="$cpu_fan$mobo_fan$ps_fan$sys_fans"
fan_data=$( create_print_line " " "$fan_data" )
print_screen_output "$fan_data"
fi