Added command line parsing and attach/detach scripts
This commit is contained in:
parent
57925cbb6c
commit
1076a9a469
4 changed files with 52 additions and 11 deletions
4
NEWS
4
NEWS
|
@ -1,6 +1,8 @@
|
|||
xboxdrv 0.4.6 - (??/Feb/2009)
|
||||
=============================
|
||||
* --calibration option
|
||||
|
||||
* --calibration option to workaround broken controller
|
||||
* xboxdrv-daemon.py to launch xboxdrv automatically
|
||||
|
||||
|
||||
xboxdrv 0.4.5 - (15/Feb/2009)
|
||||
|
|
19
README
19
README
|
@ -144,10 +144,23 @@ You can also run xboxdrv automatically whenever you plug in a gamepad via:
|
|||
% tools/xboxdrv-daemon.py
|
||||
|
||||
The script assumes that xboxdrv is available from PATH and that hal
|
||||
and dbus are available.
|
||||
and dbus are available. You can pass arguments to xboxdrv after a
|
||||
double dash '--':
|
||||
|
||||
Note that you lose most of the configurabilty when you launch it
|
||||
automatically, so this isn't recomment.
|
||||
% tools/xboxdrv-daemon.py -- --buttonmap B=A,X=A,Y=A
|
||||
|
||||
You can also run scripts that get started after xboxdrv is started
|
||||
via:
|
||||
|
||||
% tools/xboxdrv-daemon.py --attach /home/juser/xboxdrv_attach \
|
||||
--detach /home/juser/xboxdrv_deatach
|
||||
|
||||
This is useful in Kiosk settings, such as a media center PC, where you
|
||||
might want to restart the media center to have the controller working
|
||||
properly after it got attached.
|
||||
|
||||
Note that you lose some of the configurabilty when you launch it
|
||||
automatically via the daemon, so this isn't generally recomment.
|
||||
|
||||
When you want configurability and automatic launching, it is recomment
|
||||
that you write little startup scripts for your games, such as this:
|
||||
|
|
5
TODO
5
TODO
|
@ -4,6 +4,7 @@ Pre Release Testing:
|
|||
* default, test all axis and buttons
|
||||
* --dpad-only check that X/Y act properly
|
||||
* --dpad-as-button check buttons are working and no useless axis present
|
||||
* check the version number
|
||||
|
||||
VERSION="0.4.6"
|
||||
TAG="v${VERSION}"
|
||||
|
@ -14,9 +15,7 @@ git push --tags
|
|||
Stuff to do before 0.4.6 release:
|
||||
=================================
|
||||
|
||||
* work in xboxdrv-hal demon to launch things
|
||||
|
||||
* boost::tokenizer is broken on 64bit
|
||||
* check for controllers already connected when launching xboxdrv-daemon
|
||||
|
||||
|
||||
Stuff to do before 0.5 release:
|
||||
|
|
|
@ -16,12 +16,14 @@
|
|||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import time
|
||||
import dbus
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
import gobject
|
||||
import sys
|
||||
import os
|
||||
import signal
|
||||
from optparse import OptionParser
|
||||
|
||||
# This list is a direct copy of src/xboxmsg.hpp
|
||||
xboxdrv_device_list = [
|
||||
|
@ -78,7 +80,11 @@ xboxdrv_device_list = [
|
|||
]
|
||||
|
||||
class DeviceManager:
|
||||
def __init__(self):
|
||||
def __init__(self, attach=None, detach=None, xboxdrv_args=[]):
|
||||
self.attach_script = attach
|
||||
self.detach_script = detach
|
||||
self.xboxdrv_args = xboxdrv_args
|
||||
|
||||
self.processes = {}
|
||||
self.bus = dbus.SystemBus()
|
||||
|
||||
|
@ -120,10 +126,18 @@ class DeviceManager:
|
|||
self.xboxdrv_kill(udi)
|
||||
|
||||
def xboxdrv_launch(self, udi, bus, dev, type):
|
||||
self.processes[udi] = os.spawnlp(os.P_NOWAIT, 'xboxdrv',
|
||||
'xboxdrv', '--silent', '--device-by-path', "%03d:%03d" % (bus, dev), '--type', type)
|
||||
self.processes[udi] = os.spawnvp(os.P_NOWAIT, 'xboxdrv',
|
||||
['xboxdrv',
|
||||
'--silent',
|
||||
'--device-by-path', "%03d:%03d" % (bus, dev),
|
||||
'--type', type] +
|
||||
self.xboxdrv_args)
|
||||
print "Launched:", self.processes[udi]
|
||||
|
||||
if self.attach_script:
|
||||
time.sleep(2) # give xboxdrv time to start up
|
||||
os.system(self.attach_script)
|
||||
|
||||
def xboxdrv_kill(self, udi):
|
||||
if self.processes.has_key(udi):
|
||||
pid = self.processes[udi]
|
||||
|
@ -132,6 +146,9 @@ class DeviceManager:
|
|||
os.waitpid(pid, 0)
|
||||
del self.processes[udi]
|
||||
|
||||
if self.detach_script:
|
||||
os.system(self.detach_script)
|
||||
|
||||
def shutdown(self):
|
||||
for (udi, pid) in self.processes.iteritems():
|
||||
print "Shutdown:", udi, pid
|
||||
|
@ -147,9 +164,19 @@ class DeviceManager:
|
|||
return None
|
||||
|
||||
if __name__ == '__main__':
|
||||
# parse options
|
||||
parser = OptionParser(usage = "%prog [OPTIONS] -- [XBOXDRV ARGS]",
|
||||
version = "0.1",
|
||||
description = "A simple daemon that automatically launches xboxdrv.")
|
||||
parser.add_option('-a', '--attach', metavar='EXE',
|
||||
help="Launch EXE when a new controller is connected")
|
||||
parser.add_option('-d', '--detach', metavar='EXE',
|
||||
help="Launch EXE when a controller is detached")
|
||||
(opts, args) = parser.parse_args()
|
||||
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
|
||||
mgr = DeviceManager()
|
||||
mgr = DeviceManager(attach = opts.attach, detach = opts.detach, xboxdrv_args = args)
|
||||
loop = gobject.MainLoop()
|
||||
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue