summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/change_channel.sh
diff options
context:
space:
mode:
authorJames Meyer <james.meyer@operamail.com>2012-10-11 14:44:17 (GMT)
committerJames Meyer <james.meyer@operamail.com>2012-10-11 14:44:17 (GMT)
commit3558cfb46c2019697b12e449f3a42e00a84bf1a3 (patch)
tree9d490b2b5ac37f144ab0f58b51a5d7f7a14e1bda /abs/core/LinHES-system/change_channel.sh
parent4f945ba715a09fb2425e3a40e9bb1783e45f86c5 (diff)
downloadlinhes_pkgbuild-3558cfb46c2019697b12e449f3a42e00a84bf1a3.zip
linhes_pkgbuild-3558cfb46c2019697b12e449f3a42e00a84bf1a3.tar.gz
linhes_pkgbuild-3558cfb46c2019697b12e449f3a42e00a84bf1a3.tar.bz2
LinHES-system: more work with change_channel.sh
This version uses getops instead of position based. -d delay -c channel -n transmitter # -s key to send after the channel, like Enter
Diffstat (limited to 'abs/core/LinHES-system/change_channel.sh')
-rwxr-xr-xabs/core/LinHES-system/change_channel.sh205
1 files changed, 150 insertions, 55 deletions
diff --git a/abs/core/LinHES-system/change_channel.sh b/abs/core/LinHES-system/change_channel.sh
index 819076a..3337785 100755
--- a/abs/core/LinHES-system/change_channel.sh
+++ b/abs/core/LinHES-system/change_channel.sh
@@ -1,71 +1,166 @@
-#!/bin/sh
+#!/bin/bash
# Maintained by CommandIR Support mini at commandir.com - Comments / Suggestions Welcome.
# Modified for LinHES specifics
-echo $@ > /tmp/change_channel.log
-if [ $# -lt 2 ]
-then
- echo "IR Control Script for LIRC V2.0
-Includes support for CommandIR transmitter selection and lockfile.
-The remote codes will be specific to the transmitter number and matched via /etc/systemconfig
-Usage:
-$0 TRANSMITTER_NUM (CHANNEL_NUMBER | IR_COMMAND) [DELAY]
-
-Sends an IR command or sequence of numbers using REMOTE_NAME via emitter
-TRANSMITTER_NUM. DELAY (in seconds) is waited between sending IR commands.
-
-Example: Change to channel 123 using emitter 2 with a 0.3s pause between digits:
-$0 1 123 .3
-
-"
- exit 1
-fi
-
-if [ $# -eq 3 ]
-then
- DELAY=$3
-else
- DELAY=.2
-fi
+echo $@ > /tmp/change_channel.log
. /etc/systemconfig
-
-
LOCKFILE=/tmp/lirclock
export PATH=/bin:/usr/bin:/usr/local/bin
-TRANSMITTER=$1
-#get remote name from system config
-tname="HostTransmitproto_$TRANSMITTER"
-REMOTE_NAME=${!tname}
-if [ x$REMOTE_NAME = "xnone" ]
-then
- echo "Please define Transmitters in /etc/systemconfig"
- exit 1
-fi
-cmd="$2"
+function change_channel() {
+ touch $LOCKFILE
+ irsend SET_TRANSMITTERS $TRANSMITTER
+ sleep .15
+ case $cmd in
+ [0-9]*)
+ for digit in $(echo $cmd | sed -e 's/./& /g')
+ do
+ irsend SEND_ONCE $REMOTE_NAME $digit
+ sleep $DELAY
+ done
+ if [ x$SENDKEY != "x" ]
+ then
+ irsend SEND_ONCE $REMOTE_NAME $SENDKEY
+ fi
+
+ ;;
+
+ *)
+ irsend SEND_ONCE $REMOTE_NAME $cmd
+ ;;
+ esac
+}
+
+function showhelp(){
+ echo "IR Control Script for LIRC
+ Includes support for CommandIR transmitter selection and lockfile.
+ The remote codes will be specific to the transmitter number and matched via /etc/systemconfig
+ Usage:
+ $0 -d delay -c channel -n transmitter_number -s Enter
+
+ -d delay in tenths of a seconds -
+ -c channel or cmd
+ -n transmitter_number
+ -s Key to send after executing change channel command (optional)
+
+ Sends an IR command or sequence of numbers using via emitter TRANSMITTER_NUM.
+ DELAY ( in 10th of seconds) is waited between sending IR commands.
+
+ Example: Change to channel 123 using emitter 2 with a 0.3s pause between digits:
+ $0 -n1 -c123 -d3
+
+ "
+ exit 1
+
+
+}
+
+function testvars() {
+ if [ x$DELAY = "x" ]
+ then
+ tdelay="HostTransmitDelay_$TRANSMITTER"
+ d=${!tdelay}
+ DELAY=$(echo "scale=2; $d / 10" | bc)
+ fi
+
+
+ if [ x$cmd = "x" ]
+ then
+ echo "-c is mandatory"
+ exit 1
+ fi
+
+
+ if [ x$TRANSMITTER = "x" ]
+ then
+ echo "-n is mandatory"
+ exit 1
+ fi
+ echo "delay is $DELAY"
+
+
+# echo "channel or button name is $cmd"
+# echo "Using transmitter $TRANSMITTER"
+# echo "Remote name is $REMOTE_NAME"
+# echo "Will send key $SENDKEY after numbers"
+}
+
+
+#-----------------------------Main Program-----------------------
+
+while getopts ":d:c:n:hs:" opt; do
+ case $opt in
+ h) showhelp
+ ;;
+ d) DELAY=$(echo "scale=2; $OPTARG / 10" | bc)
+ ;;
+
+ c) cmd=$OPTARG
+ ;;
+
+ n) TRANSMITTER=$OPTARG
+ tname="HostTransmitproto_$TRANSMITTER"
+ REMOTE_NAME=${!tname}
+ if [ x$REMOTE_NAME = "xnone" ]
+ then
+ echo "Please define Transmitters in /etc/systemconfig"
+ exit 1
+ fi
+ if [ x$REMOTE_NAME = "x" ]
+ then
+ echo "Please define Transmitters in /etc/systemconfig"
+ exit 1
+ fi
+
+ ;;
+
+ s) SENDKEY=$OPTARG
+ ;;
+
+ \?)
+ echo
+ echo "Invalid option: -$OPTARG" >&2
+ exit 1
+ ;;
+ :)
+ echo
+ echo "Option -$OPTARG requires an argument." >&2
+ exit 1
+ ;;
+ esac
+done
+
+testvars
while [ -f $LOCKFILE ]
do
- echo "Waiting for change channel lock file..."
- sleep .1
+ echo "Waiting for change channel lock file..."
+ sleep .1
done
-touch $LOCKFILE
+change_channel
+rm -f /tmp/lirclock
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-irsend SET_TRANSMITTERS $TRANSMITTER
-sleep .15
-case $cmd in
- [0-9]*)
- for digit in $(echo $2 | sed -e 's/./& /g'); do
- irsend SEND_ONCE $REMOTE_NAME $digit
- sleep $DELAY
- done
- ;;
- *)
- irsend SEND_ONCE $REMOTE_NAME $cmd
- ;;
-esac
-rm -f /tmp/lirclock \ No newline at end of file