#!/bin/ash
## FAN checking
## 
##	Test the different FANs of the switch at different speed before starting the temperature monitoring.  
##
##
## Authors: 
##	- Benoit Rat (Seven Solutions, www.sevensols.com)
##
## GNU Lesser General Public License Usage
## This file may be used under the terms of the GNU Lesser
## General Public License version 2.1 as published by the Free Software
## Foundation and appearing in the file LICENSE.LGPL included in the
## packaging of this file.  Please review the following information to
## ensure the GNU Lesser General Public License version 2.1 requirements
## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
#######################################################################################################

printf "======: $0\n"
. 000-functions.sh

pwm_module=/wr/lib/modules/at91_softpwm.ko

if [[ -f $pwm_module ]]; then
	insmod $pwm_module &> /dev/null 
else
	echo "$pwm_module not found"
fi

speed=100
while [ ${speed} -gt 30 ]; do
	echo "$speed"
	${APTS_SWITCH_DIR}/bin/shw_tool --fan ${speed}
	sleep 1
	speed=$(expr $speed - 10)
done

ans=""
user_echoasking "y/n" "Did you hear the speed of FAN decrease" "fan_speed_up"
ret0=-$?
if [ $ans == "n" ]; then
	user_echoasking "y/n" "Does the FAN is working?" "fan_enable"
	ret1=-$?
	if [ $ans == "n" ]; then
		echo "WARNING: NO FAN DETECTED! YOU SHOULD STOP THIS TEST BEFORE OVERHEATING YOUR FPGA"
	fi
fi

exit_multierr $ret0 $ret1



