hal daemon from Thomas Debouverie <debouverie_thomas@yahoo.fr>
This commit is contained in:
parent
442ceda634
commit
a5dd9f9b30
3 changed files with 109 additions and 0 deletions
44
contrib/hal_plugandplay
Normal file
44
contrib/hal_plugandplay
Normal file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
import dbus
|
||||
import dbus.service
|
||||
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
|
||||
import dbus.glib
|
||||
import gobject
|
||||
import sys
|
||||
import os
|
||||
|
||||
class DeviceManager:
|
||||
def __init__(self):
|
||||
self.bus = dbus.SystemBus()
|
||||
self.bus.add_signal_receiver(self.device_added,
|
||||
'DeviceAdded',
|
||||
'org.freedesktop.Hal.Manager',
|
||||
'org.freedesktop.Hal',
|
||||
'/org/freedesktop/Hal/Manager')
|
||||
|
||||
self.bus.add_signal_receiver(self.device_removed,
|
||||
'DeviceRemoved',
|
||||
'org.freedesktop.Hal.Manager',
|
||||
'org.freedesktop.Hal',
|
||||
'/org/freedesktop/Hal/Manager')
|
||||
|
||||
def udi_to_device(self, udi):
|
||||
return self.bus.get_object("org.freedesktop.Hal", udi)
|
||||
|
||||
def device_added(self, udi):
|
||||
os.system("exec '/home/media/Scripts/usb_added'")
|
||||
|
||||
def device_removed(self, udi):
|
||||
os.system("exec '/home/media/Scripts/usb_removed'")
|
||||
|
||||
if __name__ == '__main__':
|
||||
m = DeviceManager()
|
||||
|
||||
mainloop = gobject.MainLoop()
|
||||
try:
|
||||
mainloop.run()
|
||||
except KeyboardInterrupt:
|
||||
mainloop.quit()
|
||||
print 'Exiting...'
|
||||
sys.exit(0)
|
43
contrib/usb_added
Normal file
43
contrib/usb_added
Normal file
|
@ -0,0 +1,43 @@
|
|||
#!/bin/sh
|
||||
# Define constants
|
||||
c_one_stick=1
|
||||
c_two_stick=2
|
||||
c_one_driver_running=2
|
||||
c_two_drivers_running=3
|
||||
|
||||
# Define functions
|
||||
load_first_driver_and_emul(){
|
||||
# Check if driver is already running for one Stick
|
||||
if [ $1 -lt $c_one_driver_running ]
|
||||
then
|
||||
# Kill media center
|
||||
killall xbmc.bin
|
||||
# Start driver
|
||||
sudo /home/media/Sources/xboxdrv-linux-0.4.4/./xboxdrv --id 0 --buttonmap lt=tl,rt=tr --dpad-only --silent &
|
||||
# Wait a little to avoid two launches of Mame, which can happen if the usb_added script is rerun before the driver is loaded
|
||||
sleep 3
|
||||
# Start custom script for launching Mame
|
||||
exec "/home/media/Scripts/MamePKK" &
|
||||
fi
|
||||
}
|
||||
|
||||
load_second_driver(){
|
||||
# If second driver not yet running, start it
|
||||
if [ $1 -lt $c_two_drivers_running ]
|
||||
then
|
||||
sudo /home/media/Sources/xboxdrv-linux-0.4.4/./xboxdrv --id 0 --buttonmap lt=tl,rt=tr --dpad-only --silent &
|
||||
fi
|
||||
}
|
||||
|
||||
# Get number of Hori Sticks plugged in
|
||||
v_nb_of_sticks=`lsusb -d 0f0d:000d | wc -l`
|
||||
# Get number of drivers loaded
|
||||
v_nb_of_drivers=`ps -C xboxdrv | wc -l`
|
||||
if [ $v_nb_of_sticks -eq $c_one_stick ]
|
||||
then
|
||||
load_first_driver_and_emul $v_nb_of_drivers
|
||||
elif [ $v_nb_of_sticks -eq $c_two_stick ]
|
||||
then
|
||||
load_second_driver $v_nb_of_drivers
|
||||
fi
|
||||
|
22
contrib/usb_removed
Normal file
22
contrib/usb_removed
Normal file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh
|
||||
# Define constants
|
||||
c_no_xbmc=1
|
||||
c_no_stick=0
|
||||
|
||||
# Get number of Hori Sticks plugged in
|
||||
v_nb_of_sticks=`lsusb -d 0f0d:000d | wc -l`
|
||||
# Get test result of XBMC already running
|
||||
v_xbmc_running=`ps -C xbmc.bin | wc -l`
|
||||
|
||||
# If XBMC is not running
|
||||
if [ $v_xbmc_running -eq $c_no_xbmc ]
|
||||
then
|
||||
# If no sticks plugged in
|
||||
if [ $v_nb_of_sticks -eq $c_no_stick ]
|
||||
then
|
||||
# MAME is a windows version running under Wine, so stop Wineserver to kill MAME
|
||||
wineserver -k
|
||||
# Run custom script to launch XBMC
|
||||
exec "/home/media/Scripts/XBMC_NOWAIT" &
|
||||
fi
|
||||
fi
|
Loading…
Reference in a new issue