#!/bin/sh # # change_channel # Usage: change_channel # The name of the application that sends IR signals IRSEND=irsend # This may have to be adjusted up for some models SLEEP_TIME=0.4 # To log the usage of the change_channel script, specify a valid (writable) # file name. To skip logging, specify /dev/null. LOG_FILE=/dev/null #LOG_FILE=/home/mythtv/log/change_channel.log # The following file is used to ensure a channel change request doesn't begin # until any already-occurring requests have completed. # Ensure the user running the script has write access to the named file. LOCKFILE=/var/tmp/change_channel.lock if [ ! -w $LOG_FILE ]; then LOG_FILE="" fi log() { if [ $# = 0 ]; then echo "Usage: log " return 1 fi echo `date`: $1 | tee -a $LOG_FILE } if [ $# != 2 ]; then echo "Usage: change_channel " exit 1 fi send_button() { if [ $# = 0 ]; then log "Usage: send_button " return 1 fi # Uncomment to "see" the buttons being sent log "$IRSEND SEND_ONCE $REMOTE_NAME $1" $IRSEND SEND_ONCE $REMOTE_NAME $1 sleep $SLEEP_TIME } # display the program info screen dish_info() { # wait for mythtv to begin recording sleep 2 # now display the info screen for N seconds send_button info # Uncomment to make the info screen opaque send_button info sleep 6 # and cancel back out of the info screen send_button cancel } log "Received request: $0 $1 $2" MYPID="$$" while [ "${HAVELOCK}" != "true" ]; do echo ${MYPID} >>${LOCKFILE} if [ "`cat ${LOCKFILE} 2>/dev/null | head -n 1`" = "$MYPID" ]; then HAVELOCK=true else log "Channel change in progress. Waiting." sleep 1 fi done REMOTE_NAME=$1 log "Processing: $0 $1 $2" # Send cancel (can be used if first-digit is always skipped) #send_button cancel for digit in $(echo $2 | sed -e 's/./& /g'); do send_button ${digit} done # Send select to immediately change the channel send_button select # Send cancel to remove the OSD send_button cancel # Uncomment to display the Dish network OSD program info #dish_info rm ${LOCKFILE} exit 0