initial commit
[ETG_Helmet] / SOFTWARE / OMEGA2 / message.sh
1 #/bin/bash
2
3 if [ "$TMPFS" == "" ]; then 
4         . "common.sh"
5 fi
6
7 echo $$ > $PID/$0
8
9 # set defaul volume
10
11 echo $VOLDEF > $TMPFS/$volume
12 setVolume $VOLDEF
13
14 # read the message 
15
16 tail -F $TMPFS/$message | while read MSG; do 
17
18                 if [ "$MSG" != "" ]; then
19
20                         currentVolume=$(cat $TMPFS/$volume)
21
22                         # ---------------- fade out TODO: add curretn PLAY detection ----------------
23
24                         vol=$currentVolume
25
26                 if echo $MSG | grep -q "RECMIC"; then
27                         echo "MESSAGE" > $TMPFS/$state
28 ##                      while killall madplay 2> /dev/null; do sleep 0; done
29                         while kill -15 $(pidof madplay) 2> /dev/null; do sleep 0; done
30                         while [ -s $recStart ]; do 
31                                 sleep 1; 
32                                 printf 'rec mic' | myLog
33                         done #  wait for MIC recording complete
34                         echo "play JINGLE OUT..." | myLog
35                         currentL=$(cat $TMPFS/$currentLang)
36                         playFile 0 "$CONTENT/$currentL/$SYSMESSAGES/$DEV_JINGLE_OUT"
37                 else 
38
39                         if echo $MSG | grep -q ".language"; then        # skip fade out on LANGUAGE CHANGE 
40                                 vol=$VOLMIN
41                                 setVolume $vol
42
43 #                               echo "drop fade out"
44         
45                         else 
46                                 while [ "$vol" -ge "$VOLMIN" ]; do
47                                         setVolume $vol
48                                         vol=$(($vol-$VOLSTEP))
49 #                                       printf "."
50                                 done
51
52 #                               echo "norm fade out"
53                         fi
54
55                         echo "MESSAGE" > $TMPFS/$state
56
57 #                       while killall madplay 2> /dev/null; do sleep 0; done
58                         while kill -15 $(pidof madplay) 2> /dev/null; do sleep 0; done
59
60                         # ---------------- play the message -----------------------------------------
61
62                         setVolume $currentVolume
63
64                         echo $MSG | tr "|" "\n" | while read file; do 
65
66                                 currentL=$(cat $TMPFS/$currentLang)
67
68                                 echo "Playing message: $file" | myLog
69
70                                 fileext=$(echo $file | awk -F. '{print (NF>1?$NF:"no extension")}')
71
72                                 if [ "$fileext" == "mp3" ]; then 
73
74                                         playFile 0 "$CONTENT/$currentL/$SYSMESSAGES/$file"
75
76                                         # mute for shutdown process
77
78                                         if [ "$file" == "$DEVICE_OFF" ]; then 
79                                                 setVolume $VOLMIN
80                                                 sleep 10000
81                                         fi
82
83                                 else 
84                                         playRecMessage "$file"
85                                         rm $file
86                                 fi 
87
88                         done
89
90                 fi
91
92                         setVolume $VOLMIN
93
94                         # ---------------- fade in TODO: add curretn PLAY detection -----------------
95
96                         : > $TMPFS/$state
97
98                         vol=$VOLMIN
99
100                                 while [ "$vol" -le "$currentVolume" ]; do
101                                         setVolume $vol
102                                         vol=$(($vol+$VOLSTEP))
103 #                                       printf "."
104                                 done    
105                 fi
106
107 done
108
109
Contact me: dev (at) shalnoff (dot) com
PGP fingerprint: A6B8 3B23 6013 F18A 0C71 198B 83D8 C64D 917A 5717