@@ -155,6 +155,15 @@ fan_run_thermal () {
155155 THERMAL_ABS_THRESH_HIGH=75
156156 fi
157157 THERMAL_ABS_THRESH=($THERMAL_ABS_THRESH_LOW $THERMAL_ABS_THRESH_HIGH )
158+ if [[ -z $THERMAL_ABS_THRESH_OFF ]]; then
159+ THERMAL_ABS_THRESH_OFF=0
160+ fi
161+ if [[ -z $THERMAL_ABS_THRESH_ON ]]; then
162+ THERMAL_ABS_THRESH_ON=1
163+ fi
164+ if [[ -z $FAN_ON_OFF_STATE ]]; then
165+ FAN_ON_OFF_STATE=1
166+ fi
158167 if [[ -z $DC_PERCENT_MIN ]]; then
159168 DC_PERCENT_MIN=25
160169 fi
@@ -174,28 +183,36 @@ fan_run_thermal () {
174183 if [[ ${# TEMPS[@]} -gt $TEMPS_SIZE ]]; then
175184 TEMPS=(${TEMPS[@]: 1} )
176185 fi
177- if [[ ${TEMPS[-1]} -le ${THERMAL_ABS_THRESH[0]} ]]; then
178- echo ${DC_ABS_THRESH[0]} 2> /dev/null > $CHANNEL_FOLDER ' duty_cycle'
179- elif [[ ${TEMPS[-1]} -ge ${THERMAL_ABS_THRESH[-1]} ]]; then
180- echo ${DC_ABS_THRESH[-1]} 2> /dev/null > $CHANNEL_FOLDER ' duty_cycle'
181- elif [[ ${# TEMPS[@]} -gt 1 ]]; then
182- TEMPS_SUM=0
183- for TEMP in ${TEMPS[@]} ; do
184- let TEMPS_SUM+=$TEMP
185- done
186- # moving mid-point
187- MEAN_TEMP=$(( TEMPS_SUM/ ${# TEMPS[@]} ))
188- DEV_MEAN_CRITICAL=$(( MEAN_TEMP- 100 ))
189- X0=${DEV_MEAN_CRITICAL# -}
190- # args: x, x0, L, a, b (k=a/b)
191- MODEL=$( function_logistic ${TEMPS[-1]} $X0 ${DC_ABS_THRESH[-1]} 1 10)
192- if [[ $MODEL -lt ${DC_ABS_THRESH[0]} ]]; then
193- echo ${DC_ABS_THRESH[0]} 2> /dev/null > $CHANNEL_FOLDER ' duty_cycle'
194- elif [[ $MODEL -gt ${DC_ABS_THRESH[-1]} ]]; then
195- echo ${DC_ABS_THRESH[-1]} 2> /dev/null > $CHANNEL_FOLDER ' duty_cycle'
196- else
197- echo $MODEL 2> /dev/null > $CHANNEL_FOLDER ' duty_cycle'
198- fi
186+ if [[ ${TEMPS[-1]} -le ${THERMAL_ABS_THRESH_OFF} ]]; then
187+ echo " 0" 2> /dev/null > $CHANNEL_FOLDER ' duty_cycle'
188+ FAN_ON_OFF_STATE=0
189+ elif [[ ${TEMPS[-1]} -ge ${THERMAL_ABS_THRESH_ON} ]]; then
190+ FAN_ON_OFF_STATE=1
191+ fi
192+ if [[ $FAN_ON_OFF_STATE -eq 1 ]]; then
193+ if [[ ${TEMPS[-1]} -le ${THERMAL_ABS_THRESH[0]} ]]; then
194+ echo ${DC_ABS_THRESH[0]} 2> /dev/null > $CHANNEL_FOLDER ' duty_cycle'
195+ elif [[ ${TEMPS[-1]} -ge ${THERMAL_ABS_THRESH[-1]} ]]; then
196+ echo ${DC_ABS_THRESH[-1]} 2> /dev/null > $CHANNEL_FOLDER ' duty_cycle'
197+ elif [[ ${# TEMPS[@]} -gt 1 ]]; then
198+ TEMPS_SUM=0
199+ for TEMP in ${TEMPS[@]} ; do
200+ let TEMPS_SUM+=$TEMP
201+ done
202+ # moving mid-point
203+ MEAN_TEMP=$(( TEMPS_SUM/ ${# TEMPS[@]} ))
204+ DEV_MEAN_CRITICAL=$(( MEAN_TEMP- 100 ))
205+ X0=${DEV_MEAN_CRITICAL# -}
206+ # args: x, x0, L, a, b (k=a/b)
207+ MODEL=$( function_logistic ${TEMPS[-1]} $X0 ${DC_ABS_THRESH[-1]} 1 10)
208+ if [[ $MODEL -lt ${DC_ABS_THRESH[0]} ]]; then
209+ echo ${DC_ABS_THRESH[0]} 2> /dev/null > $CHANNEL_FOLDER ' duty_cycle'
210+ elif [[ $MODEL -gt ${DC_ABS_THRESH[-1]} ]]; then
211+ echo ${DC_ABS_THRESH[-1]} 2> /dev/null > $CHANNEL_FOLDER ' duty_cycle'
212+ else
213+ echo $MODEL 2> /dev/null > $CHANNEL_FOLDER ' duty_cycle'
214+ fi
215+ fi
199216 fi
200217 sleep $TIME_LOOP
201218 done
@@ -370,6 +387,8 @@ usage() {
370387 echo ' -s int The MAX SIZE of the TEMPERATURE ARRAY. Interval between data points is set by -l. Default (store last 1min data): 6.'
371388 echo ' -t int Lowest TEMPERATURE threshold (in Celsius). Lower temps set the fan speed to min. Default: 25'
372389 echo ' -T int Highest TEMPERATURE threshold (in Celsius). Higher temps set the fan speed to max. Default: 75'
390+ echo ' -u int Fan-off TEMPERATURE threshold (in Celsius). Shuts off fan under the specified temperature. Default: 0'
391+ echo ' -U int Fan-On TEMPERATURE threshold (in Celsius). Turn on fan control above the specified temperature. Default: 1'
373392 echo ' '
374393 echo ' If no options are provided, the script will run with default values.'
375394 echo ' Defaults have been tested and optimized for the following hardware:'
@@ -389,7 +408,7 @@ usage() {
389408 echo ' '
390409}
391410
392- while getopts ' c:C:d:D:fF:hl:m:p:s:t:T:' OPT; do
411+ while getopts ' c:C:d:D:fF:hl:m:p:s:t:T:u:U: ' OPT; do
393412 case ${OPT} in
394413 c)
395414 CHANNEL=" $OPTARG "
@@ -459,18 +478,32 @@ while getopts 'c:C:d:D:fF:hl:m:p:s:t:T:' OPT; do
459478 ;;
460479 t)
461480 THERMAL_ABS_THRESH_LOW=" $OPTARG "
462- if [[ ! $THERMAL_ABS_THRESH_LOW =~ ^[0-4][0-9]? $ ]]; then
481+ if [[ ! $THERMAL_ABS_THRESH_LOW =~ ^[0-4]? [0-9]$ ]]; then
463482 echo ' The lowest temperature threshold must be an integer between 0 and 49.'
464483 exit 1
465484 fi
466485 ;;
467486 T)
468487 THERMAL_ABS_THRESH_HIGH=" $OPTARG "
469- if [[ ! $THERMAL_ABS_THRESH_HIGH =~ ^([5-9][0-9]? | 1[0-1][0-9]? | 120)$ ]]; then
488+ if [[ ! $THERMAL_ABS_THRESH_HIGH =~ ^([5-9][0-9]| 1[0-1][0-9]| 120)$ ]]; then
470489 echo ' The highest temperature threshold must be an integer between 50 and 120.'
471490 exit 1
472491 fi
473492 ;;
493+ u)
494+ THERMAL_ABS_THRESH_OFF=" $OPTARG "
495+ if [[ ! $THERMAL_ABS_THRESH_OFF =~ ^[0-4]? [0-9]$ ]]; then
496+ echo ' The OFF temperature threshold must be an integer between 0 and 49.'
497+ exit 1
498+ fi
499+ ;;
500+ U)
501+ THERMAL_ABS_THRESH_ON=" $OPTARG "
502+ if [[ $THERMAL_ABS_THRESH_ON -le $THERMAL_ABS_THRESH_OFF ]]; then
503+ echo ' The ON temperature threshold must be an integer strictly greater than the OFF temperature threshold.'
504+ exit 1
505+ fi
506+ ;;
474507 \? )
475508 echo ' !! ATTENTION !!'
476509 echo ' ................................'
0 commit comments