8000 Merge pull request #7 from araynard/passive-cooling · cgomesu/nanopim4-satahat-fan@f193513 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Merge pull request #7 from araynard/passive-cooling
Browse files Browse the repository at this point in the history
Add 2 parameters -u and -U, respectively Fan-OFF and Fan-ON temperature thresholds
  • Loading branch information
cgomesu authored Jan 24, 2022
2 parents 641e3c2 + 6589b99 commit f193513
Showing 1 changed file with 58 additions and 25 deletions.
83 changes: 58 additions & 25 deletions pwm-fan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ fan_run_thermal () {
THERMAL_ABS_THRESH_HIGH=75
fi
THERMAL_ABS_THRESH=($THERMAL_ABS_THRESH_LOW $THERMAL_ABS_THRESH_HIGH)
if [[ -z $THERMAL_ABS_THRESH_OFF ]]; then
THERMAL_ABS_THRESH_OFF=0
fi
if [[ -z $THERMAL_ABS_THRESH_ON ]]; then
THERMAL_ABS_THRESH_ON=1
fi
if [[ -z $FAN_ON_OFF_STATE ]]; then
FAN_ON_OFF_STATE=1
fi
if [[ -z $DC_PERCENT_MIN ]]; then
DC_PERCENT_MIN=25
fi
Expand All @@ -174,28 +183,36 @@ fan_run_thermal () {
if [[ ${#TEMPS[@]} -gt $TEMPS_SIZE ]]; then
TEMPS=(${TEMPS[@]:1})
fi
if [[ ${TEMPS[-1]} -le ${THERMAL_ABS_THRESH[0]} ]]; then
echo ${DC_ABS_THRESH[0]} 2> /dev/null > $CHANNEL_FOLDER'duty_cycle'
elif [[ ${TEMPS[-1]} -ge ${THERMAL_ABS_THRESH[-1]} ]]; then
echo ${DC_ABS_THRESH[-1]} 2> /dev/null > $CHANNEL_FOLDER'duty_cycle'
elif [[ ${#TEMPS[@]} -gt 1 ]]; then
TEMPS_SUM=0
for TEMP in ${TEMPS[@]}; do
let TEMPS_SUM+=$TEMP
done
# moving mid-point
MEAN_TEMP=$((TEMPS_SUM/${#TEMPS[@]}))
DEV_MEAN_CRITICAL=$((MEAN_TEMP-100))
X0=${DEV_MEAN_CRITICAL#-}
# args: x, x0, L, a, b (k=a/b)
MODEL=$(function_logistic ${TEMPS[-1]} $X0 ${DC_ABS_THRESH[-1]} 1 10)
if [[ $MODEL -lt ${DC_ABS_THRESH[0]} ]]; then
echo ${DC_ABS_THRESH[0]} 2> /dev/null > $CHANNEL_FOLDER'duty_cycle'
elif [[ $MODEL -gt ${DC_ABS_THRESH[-1]} ]]; then
echo ${DC_ABS_THRESH[-1]} 2> /dev/null > $CHANNEL_FOLDER'duty_cycle'
else
echo $MODEL 2> /dev/null > $CHANNEL_FOLDER'duty_cycle'
fi
if [[ ${TEMPS[-1]} -le ${THERMAL_ABS_THRESH_OFF} ]]; then
echo "0" 2> /dev/null > $CHANNEL_FOLDER'duty_cycle'
FAN_ON_OFF_STATE=0
elif [[ ${TEMPS[-1]} -ge ${THERMAL_ABS_THRESH_ON} ]]; then
FAN_ON_OFF_STATE=1
fi
if [[ $FAN_ON_OFF_STATE -eq 1 ]]; then
if [[ ${TEMPS[-1]} -le ${THERMAL_ABS_THRESH[0]} ]]; then
echo ${DC_ABS_THRESH[0]} 2> /dev/null > $CHANNEL_FOLDER'duty_cycle'
elif [[ ${TEMPS[-1]} -ge ${THERMAL_ABS_THRESH[-1]} ]]; then
echo ${DC_ABS_THRESH[-1]} 2> /dev/null > $CHANNEL_FOLDER'duty_cycle'
elif [[ ${#TEMPS[@]} -gt 1 ]]; then
TEMPS_SUM=0
for TEMP in ${TEMPS[@]}; do
let TEMPS_SUM+=$TEMP
done
# moving mid-point
MEAN_TEMP=$((TEMPS_SUM/${#TEMPS[@]}))
DEV_MEAN_CRITICAL=$((MEAN_TEMP-100))
X0=${DEV_MEAN_CRITICAL#-}
# args: x, x0, L, a, b (k=a/b)
MODEL=$(function_logistic ${TEMPS[-1]} $X0 ${DC_ABS_THRESH[-1]} 1 10)
if [[ $MODEL -lt ${DC_ABS_THRESH[0]} ]]; then
echo ${DC_ABS_THRESH[0]} 2> /dev/null > $CHANNEL_FOLDER'duty_cycle'
elif [[ $MODEL -gt ${DC_ABS_THRESH[-1]} ]]; then
echo ${DC_ABS_THRESH[-1]} 2> /dev/null > $CHANNEL_FOLDER'duty_cycle'
else
echo $MODEL 2> /dev/null > $CHANNEL_FOLDER'duty_cycle'
fi
fi
fi
sleep $TIME_LOOP
done
Expand Down Expand Up @@ -370,6 +387,8 @@ usage() {
echo ' -s int The MAX SIZE of the TEMPERATURE ARRAY. Interval between data points is set by -l. Default (store last 1min data): 6.'
echo ' -t int Lowest TEMPERATURE threshold (in Celsius). Lower temps set the fan speed to min. Default: 25'
echo ' -T int Highest TEMPERATURE threshold (in Celsius). Higher temps set the fan speed to max. Default: 75'
echo ' -u int Fan-off TEMPERATURE threshold (in Celsius). Shuts off fan under the specified temperature. Default: 0'
echo ' -U int Fan-On TEMPERATURE threshold (in Celsius). Turn on fan control above the specified temperature. Default: 1'
echo ''
echo ' If no options are provided, the script will run with default values.'
echo ' Defaults have been tested and optimized for the following hardware:'
Expand All @@ -389,7 +408,7 @@ usage() {
echo ''
}

while getopts 'c:C:d:D:fF:hl:m:p:s:t:T:' OPT; do
while getopts 'c:C:d:D:fF:hl:m:p:s:t:T:u:U:' OPT; do
case ${OPT} in
c)
CHANNEL="$OPTARG"
Expand Down Expand Up @@ -459,18 +478,32 @@ while getopts 'c:C:d:D:fF:hl:m:p:s:t:T:' OPT; do
;;
t)
THERMAL_ABS_THRESH_LOW="$OPTARG"
if [[ ! $THERMAL_ABS_THRESH_LOW =~ ^[0-4][0-9]?$ ]]; then
if [[ ! $THERMAL_ABS_THRESH_LOW =~ ^[0-4]?[0-9]$ ]]; then
echo 'The lowest temperature threshold must be an integer between 0 and 49.'
exit 1
fi
;;
T)
THERMAL_ABS_THRESH_HIGH="$OPTARG"
if [[ ! $THERMAL_ABS_THRESH_HIGH =~ ^([5-9][0-9]?|1[0-1][0-9]?|120)$ ]]; then
if [[ ! $THERMAL_ABS_THRESH_HIGH =~ ^([5-9][0-9]|1[0-1][0-9]|120)$ ]] 7674 ; then
echo 'The highest temperature threshold must be an integer between 50 and 120.'
exit 1
fi
;;
u)
THERMAL_ABS_THRESH_OFF="$OPTARG"
if [[ ! $THERMAL_ABS_THRESH_OFF =~ ^[0-4]?[0-9]$ ]]; then
echo 'The OFF temperature threshold must be an integer between 0 and 49.'
exit 1
fi
;;
U)
THERMAL_ABS_THRESH_ON="$OPTARG"
if [[ $THERMAL_ABS_THRESH_ON -le $THERMAL_ABS_THRESH_OFF ]]; then
echo 'The ON temperature threshold must be an integer strictly greater than the OFF temperature threshold.'
exit 1
fi
;;
\?)
echo '!! ATTENTION !!'
echo '................................'
Expand Down

0 comments on commit f193513

Please sign in to comment.
0