| 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 |
# (unless you specify a config on the commandline |
|---|
| 12 |
# and use the -b barebones flag) |
|---|
| 13 |
|
|---|
| 14 |
# Modified by Nick Sabalausky: |
|---|
| 15 |
# - Allow a config file to be specified |
|---|
| 16 |
# on the command line. |
|---|
| 17 |
# - Added -b barebones flag to disable kde-based |
|---|
| 18 |
# gui elements (only allowed when a config file |
|---|
| 19 |
# is specified on the commandline). |
|---|
| 20 |
# - Added --help usage screen. |
|---|
| 21 |
|
|---|
| 22 |
configParam=$1 |
|---|
| 23 |
optionParam=$2 |
|---|
| 24 |
|
|---|
| 25 |
kdeOffStr="-b" #"barebones" |
|---|
| 26 |
|
|---|
| 27 |
if [ "$optionParam" != "" -a "$optionParam" != "$kdeOffStr" -o "$configParam" = "--help" -o "$configParam" = "$kdeOffStr" ]; then |
|---|
| 28 |
echo "" |
|---|
| 29 |
echo "Wiimote Watch Script" |
|---|
| 30 |
echo "" |
|---|
| 31 |
echo "Usage:" |
|---|
| 32 |
echo " ./wiimote_watch.sh [[config] $kdeOffStr]" |
|---|
| 33 |
echo "" |
|---|
| 34 |
echo "config: Name of config file to use. If omitted," |
|---|
| 35 |
echo " a KDE-based menu will the allow user to" |
|---|
| 36 |
echo " select a config whenever a wiimote is detected." |
|---|
| 37 |
echo "" |
|---|
| 38 |
echo "$kdeOffStr: Barebones. If config is specified, disables all" |
|---|
| 39 |
echo " KDE-based gui elements." |
|---|
| 40 |
echo "" |
|---|
| 41 |
exit 0 |
|---|
| 42 |
fi |
|---|
| 43 |
|
|---|
| 44 |
declare -a myConfigFiles |
|---|
| 45 |
declare -a configList |
|---|
| 46 |
declare -a hctscan |
|---|
| 47 |
declare -a wiimote |
|---|
| 48 |
|
|---|
| 49 |
echo "started on `date`" >> /tmp/wiimote_watch.log |
|---|
| 50 |
|
|---|
| 51 |
if [ "$optionParam" != "$kdeOffStr" ]; then |
|---|
| 52 |
# directory to look for config files in. |
|---|
| 53 |
cd /usr/local/etc/cwiid/wminput |
|---|
| 54 |
|
|---|
| 55 |
# add all files in the directory above to an array |
|---|
| 56 |
for file in * |
|---|
| 57 |
do |
|---|
| 58 |
myConfigFiles[${#myConfigFiles[@]}]="$file" |
|---|
| 59 |
done |
|---|
| 60 |
|
|---|
| 61 |
# do some ugly stuff so kdialog behaves how we want |
|---|
| 62 |
for (( i=0 ; i <= ${#myConfigFiles[@]} * 2 - 2; i++ )) |
|---|
| 63 |
do |
|---|
| 64 |
configList[i*2+1]=${myConfigFiles[i]} |
|---|
| 65 |
configList[i*2]=${myConfigFiles[i]} |
|---|
| 66 |
done |
|---|
| 67 |
fi |
|---|
| 68 |
|
|---|
| 69 |
# main loop |
|---|
| 70 |
# look for a wiimote. When one is found, ask the user which config file to use then start wminput |
|---|
| 71 |
while true |
|---|
| 72 |
do |
|---|
| 73 |
hctscn=`/usr/bin/hcitool scan | grep Nintendo` |
|---|
| 74 |
if [ "`echo ${hctscn[@]}`" ]; then |
|---|
| 75 |
# parse the output output of hcitool scan |
|---|
| 76 |
n=0 |
|---|
| 77 |
for i in `echo ${hctscn} | tr '.' '\n'` ; do |
|---|
| 78 |
str=${str},${i} |
|---|
| 79 |
let n=$n+1 |
|---|
| 80 |
wiimote[${n}]=${i} |
|---|
| 81 |
done |
|---|
| 82 |
|
|---|
| 83 |
if [ "$optionParam" != "$kdeOffStr" ]; then |
|---|
| 84 |
kdialog --passivepopup "Wiimote Found at ${wiimote[1]}." 5 & |
|---|
| 85 |
fi |
|---|
| 86 |
|
|---|
| 87 |
if [ "$configParam" = "" ]; then |
|---|
| 88 |
whichConfig=`kdialog --menu "Select Which config file to use:" ${configList[@]}` |
|---|
| 89 |
else |
|---|
| 90 |
whichConfig=$configParam |
|---|
| 91 |
fi |
|---|
| 92 |
echo "Starting wminput for wiimote with blutooth address ${wiimote[1]} and configuration file $whichConfig" >> /tmp/wiimote_watch.log |
|---|
| 93 |
wminstatus="`/usr/local/bin/wminput -c $whichConfig ${wiimote[1]}`" |
|---|
| 94 |
|
|---|
| 95 |
echo "Wiimote disconnected." >> /tmp/wiimote_watch.log |
|---|
| 96 |
if [ "$optionParam" != "$kdeOffStr" ]; then |
|---|
| 97 |
kdialog --passivepopup "Wiimote was Disconnected." 5 & |
|---|
| 98 |
fi |
|---|
| 99 |
fi |
|---|
| 100 |
# My system acts up if I don't pause |
|---|
| 101 |
# before doing an hcitool scan continually |
|---|
| 102 |
# you might not need this. Comment it out if you don't. |
|---|
| 103 |
sleep 10 |
|---|
| 104 |
done |
|---|
| 105 |
|
|---|
| 106 |
exit 0 |
|---|