4 . "settings.messages.sh"
6 # -----------------------
10 # if [ -n "$1" ]; then IN="$1"; else read IN; fi
11 # echo "[ETG] [$0] $IN" | tee /dev/console
16 # ------- save PID ------
18 ## if [ ! -d "$PID" ]; then
22 ## echo "[start] --------- $0 ---------" | myLog
23 ## if [ "$0" != "./kbd.sh" ] echo $$ > $PID/$0
25 # ------- update --------
31 # ------- player --------
33 prevLocation=prevlocatoin
35 currentLang=currentlang
36 currentLangNum=currentlangNum
38 # ------- messages ------
44 # ------- GPS -----------
46 CURRENTGPS=$TMPFS/currentgps
47 TIMENMEA=$TMPFS/timenmea
49 # ------ navigation -----
51 navMemo=$TMPFS/navmemo
54 # ------ transmitter ----
56 recDone=$TMPFS/recdone
57 recStart=$TMPFS/recstart
59 # ------ wifi -----------
61 wifiButton=$TMPFS/wifibutton
62 wifiState=$TMPFS/wifistate
64 # ------ misc -----------
65 shutDown=$TMPFS/shutdown
67 # -----------------------
71 ./fast-gpio set-output $PIN_WIFI
72 ./fast-gpio set-output $PIN_MAIN
77 if [ "$1" == "wifi" ]; then
83 if [ "$2" != "off" ]; then
102 ./fast-gpio pwm $led_pin $led_mode
104 ./fast-gpio set $led_pin 0
108 # -----------------------
114 uci set wireless.ra0.disabled=0
115 uci set wireless.@wifi-iface[0].ApCliEnable='0'
116 uci set wireless.@wifi-iface[0].hidden='0' # make AP visible for followers
119 uci set network.wlan.ipaddr=$LEADER_IP
133 uci set wireless.ra0.disabled=0
134 uci set wireless.@wifi-iface[0].ApCliSsid=$AP_CLI_SSID
135 uci set wireless.@wifi-iface[0].ApCliPassWord=$AP_CLI_PASS
136 uci set wireless.@wifi-iface[0].ApCliEnable='1'
137 uci set wireless.@wifi-iface[0].hidden='0' # make AP visible
139 uci set wireless.@wifi-config[0].ssid=$AP_CLI_SSID
140 uci set wireless.@wifi-config[0].key=$AP_CLI_PASS
141 # uci set wireless.@wifi-config[0].encryption='AES'
145 uci set network.wlan.ipaddr=$SERVICE_IP
159 targetAP=$(aps 2>/dev/null | grep "ETG-" | awk '{print $2; exit}' | head -1) # grab Leader's SSID
161 if [ "$targetAP" != "" ]; then
163 echo "follower targetAP: $targetAP" | myLog
164 uci set wireless.@wifi-iface[0].ApCliSsid=$targetAP
165 uci set wireless.@wifi-config[0].ssid=$targetAP
169 currentApCliSsid=$(uci get wireless.@wifi-iface[0].ApCliSsid 2>/dev/null)
171 if [ "$currentApCliSsid" != "" ]; then
172 uci set wireless.@wifi-iface[0].ApCliEnable='1'
174 uci set wireless.@wifi-iface[0].ApCliEnable='0'
177 uci set wireless.ra0.disabled=0
178 uci set wireless.@wifi-iface[0].ApCliPassWord=$FOLLOW_PASS
179 uci set wireless.@wifi-iface[0].hidden='1' # make AP invisible for future reboots
181 uci set wireless.@wifi-config[0].key=$FOLLOW_PASS
185 uci set network.wlan.ipaddr=$FOLLOWER_IP
192 ifconfig ra0 down # disable AP radio interface
200 if ping -W 4 -w 4 -c 2 $LEADER_IP &> /dev/null; then
202 myLog "followingMode: Connection to group network has been esteblished."
205 myLog "followingMode: connecting... $conCnt"
207 if [ "$conCnt" -gt "20" ]; then
210 conCnt=$(( $conCnt + 1 ))
215 myLog "followingMod exit"
220 # uci get wireless.ra0.disabled=1
228 # ----------- sound ------------
231 if [ ! -e /dev/dsp ]; then
232 amixer scontrols -D pulse | head -1 | grep -oE "'.*'"
234 amixer scontrols | head -1 | grep -oE "'.*'"
239 if [ ! -e /dev/dsp ]; then
240 amixer scontrols -D pulse | awk -v a=2 'NR == a {print $4; exit}' | grep -oE "'.*'"
242 amixer scontrols | awk -v a=2 'NR == a {print $4; exit}' | grep -oE "'.*'"
247 if [ ! -e /dev/dsp ]; then
248 amixer sset $micDevice $1% -D pulse > /dev/null
250 # amixer set $micDevice $1% > /dev/null
251 amixer set $micDevice $1% | myLog
256 if [ ! -e /dev/dsp ]; then
257 amixer sset $audioDevice $1% -D pulse 2>&1 > /dev/null
259 amixer set $audioDevice $1% 2>&1 > /dev/null
264 echo "[robot] $1" | myLog
265 espeak -v en -p 30 -s 150 "$1" 2> /dev/null
268 generateRoboMessage(){
270 espeak -v en -p 30 -s 150 "$1" -a 100 -w "$TMPFS/robo_$time.wav" 2> /dev/null
271 ## echo "$TMPFS/robo_$time.wav" >> $TMPFS/$message
272 echo "$TMPFS/robo_$time.wav"
279 if [ ! -e /dev/dsp ]; then
281 nice -n -20 madplay "$2" "$3" "$4" "$5" -A $AMP -Q --downsample --no-tty-control --start=$(date +%H:%M:%S -d @$start -u) -o wav:- 2>/dev/null | aplay -q > /dev/null 2>&1
284 nice -n -20 madplay "$2" "$3" "$4" "$5" -A $AMP -Q --downsample --no-tty-control --start=$(date +%H:%M:%S -d @$start -u) > /dev/null 2>&1
291 if echo "$1" | grep -q 'robo_' ; then
293 # playing file generated by generateRoboMessage, no additional filtering
295 if [ "$BBOARD" ]; then
296 aplay "$1" # for bboard
298 sox "$1" -t alsa plughw:0,0
301 # play $1 gain $REC_PLAY_GAIN bass $REC_PLAY_BASS norm fade 0.3 # norm fade 0.3 # contrast 100 hain +10
302 # sox "$1" -t alsa plughw:0,0 gain $REC_PLAY_GAIN bass $REC_PLAY_BASS norm fade 0.3 # norm fade 0.3 # contrast 100 gain +10
303 sox "$1" -t alsa plughw:0,0 fade 0.3
310 angleABS=$(echo $angle | tr -d '-')
312 if [ "$angleABS" -le "180" ] && [ "$angleABS" -ge "135" ]; then dirMessage=$NAV_GO_STRAIGHT; fi
313 if [ "$angle" -ge "-135" ] && [ "$angle" -lt "-45" ]; then dirMessage=$NAV_GO_RIGHT; fi
314 if [ "$angle" -le "135" ] && [ "$angle" -gt "40" ]; then dirMessage=$NAV_GO_LEFT; fi
315 if [ "$angleABS" -le "45" ] && [ "$angleABS" -ge "0" ]; then dirMessage=$NAV_GO_BACK; fi
323 play -n synth sin %41 fade q 0.0 0.1 0.01 gain -25
326 # --------------- gps --------------------------
329 fast-gpio set $GPS_EN_PIN 1
330 echo "GPS enabled" | myLog
334 fast-gpio set $GPS_EN_PIN 0
335 echo "GPS disabled" | myLog
338 # -------------- FS ----------------------------
342 umount /tmp/mounts/SD-P1/
344 e2fsck -p /dev/mmcblk0p1
349 # ------------------------ create appropriate TMP files for each location -----------------------------
351 narrativeStructureReset(){
354 IFS=$'\n' # make newlines the only separator
356 if [ -d "$TMPMAPDIR" ]; then
360 # TODO: CREATE FILES FOR EACH ASSET
365 # ----------------------- shut down ------------------------------------------------------------------
371 echo "going to sleep..." | myLog
373 # interrupt current possible message
375 ## if [ -s $TMPFS/$message ]; then
376 # killall madplay 2> /dev/null;
377 ## while killall madplay 2> /dev/null; do sleep 0; done
380 # say shutdown message
382 if [ "$2" != "" ]; then finMess=$2; fi
383 if [ "$3" != "" ]; then finMess="$finMess|$3"; fi
384 if [ "$finMess" != "" ]; then echo $finMess > $TMPFS/$message; fi
397 echo "o" >/proc/sysrq-trigger
401 # ----------------------- get audio devices ---------------------------------------------------------
403 if [ "$0" != "./kbd.sh" ]; then
404 audioDevice=$(getAudioDevice)
405 micDevice=$(getMicDevice)