ConfigScriptEtc: wiimote_watch.sh

File wiimote_watch.sh, 1.8 kB (added by nickishappy, 3 years ago)

A script similar to wiimote_connect.rb but uses kdialog and allows user to specify which config file to use for wminput on each wiimote connect. Also keeps a log in /tmp/wiimote_watch.log

Line 
1#!/bin/bash
2
3# This script was written by Nick Wilbanks
4# and is released under the GPL v2
5# it was inspired by wiimote_connect.rb
6# written by Heavybell.
7# Some things aren't done properly
8# so use at your own risk!
9
10# requires kdialog to function properly
11
12declare -a myConfigFiles
13declare -a configList
14declare -a hctscan
15declare -a wiimote
16
17echo "started on `date`" >> /tmp/wiimote_watch.log
18
19# directory to look for config files in.
20cd ~/.cwiid/wminput/
21
22# add all files in the directory above to an array
23for file in *
24do
25        myConfigFiles[${#myConfigFiles[@]}]="$file"
26done
27
28# do some ugly stuff so kdialog behaves how we want
29for ((  i=0 ;  i <= ${#myConfigFiles[@]} * 2 - 2; i++  ))
30do
31        configList[i*2+1]=${myConfigFiles[i]}
32        configList[i*2]=${myConfigFiles[i]}
33done
34
35# main loop
36# look for a wiimote. When one is found, ask the user which config file to use then start wminput
37while true
38do
39        hctscn=`/usr/bin/hcitool scan | grep Nintendo`
40        if [ "`echo ${hctscn[@]}`" ]; then
41                # parse  the output output of hcitool scan
42                n=0
43                for i in `echo ${hctscn} | tr '.' '\n'` ; do
44                        str=${str},${i}
45                        let n=$n+1
46                        wiimote[${n}]=${i}
47                done
48                kdialog --passivepopup "Wiimote Found at ${wiimote[1]}." 5 &
49                whichConfig=`kdialog --menu "Select Which config file to use:" ${configList[@]}`
50                echo "Starting wminput for wiimote with blutooth address ${wiimote[1]} and configuration file $whichConfig" >> /tmp/wiimote_watch.log
51                wminstatus="`/usr/local/bin/wminput -c $whichConfig ${wiimote[1]}`"
52                echo "Wiimote disconnected." >> /tmp/wiimote_watch.log
53                kdialog --passivepopup "Wiimote was Disconnected." 5 &
54        fi
55        # My system acts up if I don't pause
56        # before doing an hcitool scan continually
57        # you might not need this. Comment it out if you don't.
58        sleep 10
59done
60
61exit 0