Some improvements on the SetConfig D-Bus command

This commit is contained in:
Ingo Ruhnke 2011-03-05 12:30:53 +01:00
parent 1742ac9073
commit 37ccd8caa9
3 changed files with 30 additions and 21 deletions

2
TODO
View file

@ -51,8 +51,6 @@ Stuff to do before 0.7.2 release:
-> maybe get rid of them completely, have another way to handle
build-in configuration files
* add SetConfig command to D-Bus interface and xboxdrvctl
== Device Name ==
* implement Options::set_device_usbid() and CommandLineParser::set_device_usbid()

View file

@ -278,13 +278,13 @@ ControllerSlotConfig::get_config(int i) const
void
ControllerSlotConfig::set_current_config(int num)
{
if (num < 0 || num >= static_cast<int>(m_config.size()))
if (num >= 0 && num < static_cast<int>(m_config.size()))
{
raise_exception(std::runtime_error, "argument out of range");
m_current_config = num;
}
else
{
m_current_config = num;
raise_exception(std::runtime_error, "argument out of range");
}
}

View file

@ -5,7 +5,7 @@ import sys
import re
from optparse import OptionParser, OptionGroup
parser = OptionParser("Usage: %prog [OPTIONS] [FILES]")
parser = OptionParser("Usage: %prog [OPTIONS]")
group = OptionGroup(parser, "D-Bus Options")
group.add_option("-b", "--bus", metavar="BUS",
@ -32,7 +32,12 @@ group.add_option("-l", "--led", metavar="NUM", type="int",
group.add_option("-r", "--rumble", metavar="L:R",
dest="rumble",
help="Print controller status")
help="print controller status")
group.add_option("-c", "--config", metavar="NUM", type="int",
dest="config",
help="switches to controller configuration NUM")
parser.add_option_group(group)
(options, args) = parser.parse_args()
@ -43,23 +48,29 @@ if options.status:
daemon = bus.get_object("org.seul.Xboxdrv", '/org/seul/Xboxdrv/Daemon')
sys.stdout.write(daemon.Status())
else:
if (options.led or options.rumble) and options.slot == None:
if (options.led or options.rumble or options.config) and options.slot == None:
print "Error: --slot argument required"
exit()
else:
slot = bus.get_object("org.seul.Xboxdrv", '/org/seul/Xboxdrv/ControllerSlots/%d' % options.slot)
if options.slot != None:
slot = bus.get_object("org.seul.Xboxdrv", '/org/seul/Xboxdrv/ControllerSlots/%d' % options.slot)
if options.led:
slot.SetLed(options.led)
if options.led:
slot.SetLed(options.led)
if options.rumble:
m = re.match('^(\d+):(\d+)$', options.rumble)
if not m:
print "Error: invalid argument to --rumble"
exit()
else:
left = int(m.group(1))
right = int(m.group(2))
slot.SetRumble(left, right)
if options.rumble:
m = re.match('^(\d+):(\d+)$', options.rumble)
if not m:
print "Error: invalid argument to --rumble"
exit()
else:
left = int(m.group(1))
right = int(m.group(2))
slot.SetRumble(left, right)
if options.config:
slot.SetConfig(options.config)
else:
parser.print_help()
# EOF #