diff --git a/TODO b/TODO index 828ed35..d77bcc5 100644 --- a/TODO +++ b/TODO @@ -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() diff --git a/src/controller_slot_config.cpp b/src/controller_slot_config.cpp index 35ee5c5..57a15b7 100644 --- a/src/controller_slot_config.cpp +++ b/src/controller_slot_config.cpp @@ -278,13 +278,13 @@ ControllerSlotConfig::get_config(int i) const void ControllerSlotConfig::set_current_config(int num) { - if (num < 0 || num >= static_cast(m_config.size())) + if (num >= 0 && num < static_cast(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"); } } diff --git a/xboxdrvctl b/xboxdrvctl index ab70f79..ac5937d 100755 --- a/xboxdrvctl +++ b/xboxdrvctl @@ -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.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.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.config: + slot.SetConfig(options.config) + else: + parser.print_help() # EOF #