summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/change_channel.sh
blob: 819076a8649172d04edd7692e060dafce73137ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
# 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

. /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"


while [ -f $LOCKFILE ]
do
  echo "Waiting for change channel lock file..."
  sleep .1
done

touch $LOCKFILE

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