2018-01-09 19:53:09 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function detect() {
|
|
|
|
lsusb | grep 0f0d:000d > /dev/null
|
|
|
|
NOT_FOUND=$?
|
|
|
|
}
|
|
|
|
|
|
|
|
function xbox_up() {
|
2017-05-26 23:31:32 +00:00
|
|
|
echo "xboxdrv up"
|
2018-01-09 19:53:09 +00:00
|
|
|
/usr/bin/xboxdrv --daemon --detach --dbus disabled 2> /dev/null > /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
function xbox_down() {
|
2017-05-26 23:31:32 +00:00
|
|
|
echo "xboxdrv down"
|
2018-01-09 19:53:09 +00:00
|
|
|
pkill xboxdrv
|
|
|
|
}
|
|
|
|
|
2017-05-26 23:31:32 +00:00
|
|
|
CURRENT_STATE=""
|
|
|
|
NOT_FOUND=""
|
2018-01-09 19:53:09 +00:00
|
|
|
|
|
|
|
while true; do
|
2017-05-26 23:31:32 +00:00
|
|
|
# |detect| sometime report a wrong result. Take only results that are
|
|
|
|
# reported twice in sequence to stabilize it.
|
|
|
|
LAST_STATE=$NOT_FOUND
|
2018-01-09 19:53:09 +00:00
|
|
|
detect
|
2017-05-26 23:31:32 +00:00
|
|
|
if [ "$LAST_STATE" == "$NOT_FOUND" ]; then
|
|
|
|
|
|
|
|
# If newly detected state is different from the driver up/down state,
|
|
|
|
# run xbox_up/xbox_down for the new state.
|
|
|
|
if [ "$CURRENT_STATE" != "$NOT_FOUND" ]; then
|
|
|
|
if [ "$NOT_FOUND" == "1" ]; then
|
|
|
|
xbox_down
|
|
|
|
else
|
|
|
|
xbox_up
|
|
|
|
fi
|
2018-01-09 19:53:09 +00:00
|
|
|
fi
|
2017-05-26 23:31:32 +00:00
|
|
|
CURRENT_STATE=$NOT_FOUND
|
2018-01-09 19:53:09 +00:00
|
|
|
fi
|
2017-05-26 23:31:32 +00:00
|
|
|
|
|
|
|
# Polling device in every 1 sec.
|
2018-01-09 19:53:09 +00:00
|
|
|
sleep 1
|
|
|
|
done
|