forked from n1gp/iambic-keyer
/
keyer
executable file
·80 lines (75 loc) · 3.2 KB
/
keyer
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
72
73
74
75
76
77
78
79
80
#!/bin/sh
#//*========================================================================
#// keyer
#//
#// keyer start|stop|restart
#//
#// Iambic keyer for the Raspberry Pi.
#// See accompanying README file for a description on how to use this code.
#// License:
#// This program is free software: you can redistribute it and/or modify
#// it under the terms of the GNU General Public License as published by
#// the Free Software Foundation, either version 2 of the License, or
#// (at your option) any later version.
#//
#// This program is distributed in the hope that it will be useful,
#// but WITHOUT ANY WARRANTY; without even the implied warranty of
#// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#// GNU General Public License for more details.
#//
#// You should have received a copy of the GNU General Public License
#// along with this program. If not, see <http://www.gnu.org/licenses/>.
#//*========================================================================
#// lu7did: initial load
#*----------------------------------------------------------------------------
#* Initialization
#* DO NOT RUN EITHER AS A rc.local script nor as a systemd controlled service
#*----------------------------------------------------------------------------
#* Environment setup
#-----------------------------------------------------------------------------
DPATH="/home/pi/iambic-keyer"
cd $DPATH
case "$1" in
start) echo -n "keyer $(date): Start keyer services" 2>&1 | tee -a $DPATH/keyer.log
PIDL=$(sudo pgrep iambic)
N=0
for line in $PIDL; do
if [ $line -ne $$ ]
then
N=$(( $N + 1 ))
fi
done
if [ $N \> 0 ]; then
echo "keyer $(date): keyer program running, exit(1)" 2>&1 | tee -a $DPATH/keyer.log
exit 1
fi
export `dbus-launch | grep ADDRESS`
export `dbus-launch | grep PID`
trap 'echo Terminating...' INT
#*-----------------------------------------------------------------------------
#* Load jackd server as a background process
#*-----------------------------------------------------------------------------
jackd -P70 -p16 -t2000 -dalsa -dhw:1,0 -p512 -n4 -r48000 -s &
#PID=$!
#*-----------------------------------------------------------------------------
#* Load iambic
#*-----------------------------------------------------------------------------
/home/pi/iambic-keyer/iambic -s 20 -m 2 &
#*-----------------------------------------------------------------------------
#* Terminate
#*-----------------------------------------------------------------------------
exit 0
;;
stop) echo -n "Keyer $(date): Stop keyer services\n" 2>&1 | tee -a $DPATH/keyer.log
echo "Keyer $(date): Stop jackd PID(" $(pgrep 'jackd') ") " $(sudo pkill 'jackd') 2>&1 | tee -a $DPATH/keyer.log
;;
restart)
echo -n "Keyer $(date): Keyer restart" 2>&1 | tee -a $DPATH/keyer.log
$0 stop
$0 start
;;
*) echo "Usage: $0 start|stop|restart" 2>&1 | tee -a $DPATH/keyer.log
exit 1
;;
esac
exit 0