#!/bin/bash ######################################################################################### # # filename: txfan # # description: This file controls a PC fan attached to any aux port. It starts up when # PTT is detected, and will stay on for the time period specified in # the TIMEAFTER variable after the PTT drops. If the PTT is triggered # in the countdown period, the timer resets. # # original authors: The majority of this script (the state manager) was taken from # the ID scripts by KC6HUR and WW4M. # # Add the following to the events stanza of rpt.conf for each node you want # controlled by the fan. Multiple nodes can control a single fan. The Event Management # Subsystem is used to indicate PTT state to the txfan process. # # touch /dev/shm/~pttstate = s|t|RPT_TXKEYED # rm -f /dev/shm/~pttstate = s|f|RPT_TXKEYED # # Default location for this txfan script is /etc/asterisk # # Add the following code snipit near the end of /etc/rc.local # This will restart TXFAN process each time the node is restarted. # # CUSTOM=/etc/asterisk # if [ -f $CUSTOM/txfan ] ; then # echo -n "Starting TXFAN process..." # killall txfan &>/dev/null # /bin/su - -c $CUSTOM/txfan root &>/dev/null & # echo "done!" # fi # # history: # 2005-02-16 kd6hwc Initial creation (with help from other scripts) # 2007-07-29 k6jwn Added new variable PTTON, fan won't come on until this timer reaches # it's limit. # 2012-01-28 k0kn Adapted script for app_rpt system # 2015-09-07 k0kn Feature add for external commands during fan on/off # 2015-12-02 k0kn PiGpio pin support added ######################################################################################### # Temp file that exists when PTT active PTTSTATE="/dev/shm/~pttstate" # Define the AUX Switch that the fan is connected to # # Pi_gpio pin 3 FANON="gpio -g write 3 1" # FANOFF="gpio -g write 3 0" # For parallel port pin 4 # FANON="/home/kyle/aux 2211 4 1" # # FANOFF="/home/kyle/aux 2211 4 0" # # For GPIO pin 1 # FANON="/home/kyle/gpio 2211 1 1" # FANOFF="/home/kyle/gpio 2211 1 0" # Define external commands when fan turns on/off FANON_CMD="ln -f -s /etc/asterisk/sounds/fan_on.wav /home/kyle/fan.wav" FANOFF_CMD="ln -f -s /etc/asterisk/sounds/fan_off.wav /home/kyle/fan.wav" # Define the period of time after the PTT drops to shut off the fan TIMEAFTER=300 # Define the max PTT time before the fan is activated PTTON=10 # define variables declare -i IDLETIMER declare -i PTTKEY # Start with state set to "Initial" STATE="Initial" while [ TRUE ] do case "$STATE" in "Initial") # Wait for first keyup, then proceed to Countdown echo -en "\r"`date ` "STATE = Initial\n" sleep 1; PTTKEY=0 while [ TRUE ] do echo -en "\rPTT Timer: $PTTKEY " sleep 1; # while PTT is silent (PTT=T) if [ -f $PTTSTATE ] ; then PTTKEY=$PTTKEY+1 fi if ! [ -f $PTTSTATE ] ; then PTTKEY=0 fi if [ $PTTKEY -gt $PTTON ] ; then break fi done echo -en "\nPTT timer expired, activating fan" $FANON eval $FANON_CMD STATE="Countdown" ;; "Countdown") # Count down period, if PTT is triggered, reset the timer. echo -en "\n\n"`date ` "STATE = Countdown\n" sleep 1 IDLETIMER=$TIMEAFTER while [ TRUE ] do echo -en "\rFan powerdown timer: $IDLETIMER " IDLETIMER=$IDLETIMER-1 sleep 1 if [ -f $PTTSTATE ] then IDLETIMER=$TIMEAFTER fi if [ $IDLETIMER = 0 ] then break fi done echo -en "\nTimer expired, deactivating fan" $FANOFF eval $FANOFF_CMD STATE=Initial ;; esac done echo -e "\n\nOops! - Not supposed to get to here" ########################