Created
July 11, 2017 01:04
-
-
Save Lauszus/4b9071f2ea019fc75aad1810c68be5e8 to your computer and use it in GitHub Desktop.
OSMC PS3 controller via Bluetooth on the Raspberry Pi 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### BEGIN INIT INFO | |
# Provides: sixad | |
# Required-Start: $local_fs $syslog $remote_fs bluetooth | |
# Required-Stop: $local_fs $syslog $remote_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start sixad | |
### END INIT INFO | |
# | |
# Author: falkTX <[email protected]> | |
# | |
# set -e | |
PATH=/bin:/usr/bin:/sbin:/usr/sbin | |
DAEMON=/usr/bin/sixad | |
sixad_already_running_check () { | |
ps -e | grep sixad-bin > /dev/null | |
} | |
. /lib/lsb/init-functions | |
bt_device_check () { | |
if (which hciconfig > /dev/null); then | |
while (! hciconfig dev &> /dev/null); do | |
echo "No bluetooth adapters found on the system; will try again in 1 second.">>/var/log/sixad | |
sleep 1; | |
done | |
VER=`hciconfig default version | grep "HCI Ver" | awk '{print$3}'` | |
if [ "$VER" == "1.1" ]; then | |
echo "***** NOTICE *****">>/var/log/sixad | |
echo "You're using a very old bluetooth dongle,">>/var/log/sixad | |
echo "the Sixaxis will not work properly!">>/var/log/sixad | |
elif [ "$VER" == "1.0" ]; then | |
echo "***** WARNING *****">>/var/log/sixad | |
echo "You're using a _really_ old bluetooth dongle,">>/var/log/sixad | |
echo "the Sixaxis will just not work!">>/var/log/sixad | |
fi | |
bt_device_enable | |
fi | |
} | |
bt_device_enable () { | |
bt_device_up | |
bt_device_pscan | |
echo "Bluetooth Enabled">>/var/log/sixad | |
} | |
bt_device_up () { | |
hciconfig hci0 up | |
} | |
bt_device_pscan () { | |
hciconfig hci0 pscan | |
} | |
case "$1" in | |
start) | |
if (sixad_already_running_check "$1"); then | |
log_warning_msg "sixad is already running" | |
else | |
{ | |
log_daemon_msg "Setting up Bluetooth" | |
bt_device_check | |
env sleep 1 | |
log_daemon_msg "Starting sixad" | |
$DAEMON --start &>>/var/log/sixad & | |
log_end_msg 0 | |
} | |
fi | |
;; | |
stop) | |
if (sixad_already_running_check "$1"); then | |
{ | |
log_daemon_msg "Stopping sixad" | |
$DAEMON --stop || true | |
log_end_msg 0 | |
} | |
else | |
log_warning_msg "sixad is not running" | |
fi | |
;; | |
restart) | |
$0 stop | |
$0 start | |
;; | |
status) | |
status_of_proc "sixad-bin" "sixad" && exit 0 || exit $? | |
;; | |
*) | |
echo "Usage: /etc/init.d/sixad {start|stop|restart|status}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by: https://github.com/RetroPie/RetroPie-Setup/blob/master/scriptmodules/supplementary/ps3controller.sh
and https://github.com/RetroPie/sixad/blob/master/sixad.