Added ability to set LED per controller slot instead of just globally

This commit is contained in:
Ingo Ruhnke 2011-01-29 05:28:53 +01:00
parent 18d752dbca
commit 6ded8063af
9 changed files with 34 additions and 9 deletions

1
NEWS
View file

@ -15,6 +15,7 @@ xboxdrv 0.7.1 - (??/???/2011)
* added support for Playstation button names (triangle,
circle, square, cross, L1, L2, L3, R1, R2, R3)
* added --on-connect and --on-disconnect to xboxdrv --daemon
* added ability to set LED per controller slot
xboxdrv 0.7.0 - (28/Jan/2011)

View file

@ -317,7 +317,7 @@ CommandLineParser::init_ini(Options* opts)
("silent", &opts->silent)
("quiet", &opts->quiet)
("rumble", &opts->rumble)
("led", &opts->led)
("led", boost::bind(&Options::set_led, boost::ref(opts), _1))
("rumble-l", &opts->rumble_l)
("rumble-r", &opts->rumble_r)
("rumble-gain", &opts->rumble_gain)
@ -706,7 +706,7 @@ CommandLineParser::parse_args(int argc, char** argv, Options* options)
}
else
{
opts.led = boost::lexical_cast<int>(opt.argument);
opts.set_led(opt.argument);
}
break;

View file

@ -25,7 +25,8 @@
ControllerSlotOptions::ControllerSlotOptions() :
m_options(),
m_match_rules(),
m_force_feedback(false)
m_force_feedback(false),
m_led_status(-1)
{
}

View file

@ -46,10 +46,14 @@ public:
int get_ff_device() const { return 0; }
int get_led_status() const { return m_led_status; }
void set_led_status(int v) { m_led_status = v; }
private:
std::map<int, ControllerOptions> m_options;
std::vector<ControllerMatchRulePtr> m_match_rules;
bool m_force_feedback;
int m_led_status;
};
#endif

View file

@ -32,7 +32,6 @@ Options::Options() :
silent (false),
quiet (false),
rumble (false),
led (-1),
rumble_l(-1),
rumble_r(-1),
rumble_gain(255),
@ -161,6 +160,12 @@ Options::set_debug()
g_logger.incr_log_level(Logger::kDebug);
}
void
Options::set_led(const std::string& value)
{
get_controller_slot().set_led_status(boost::lexical_cast<int>(value));
}
void
Options::set_device_name(const std::string& name)
{

View file

@ -58,7 +58,6 @@ public:
bool silent;
bool quiet;
bool rumble;
int led;
int rumble_l;
int rumble_r;
int rumble_gain;
@ -135,6 +134,7 @@ public:
void set_debug();
void set_quiet();
void set_led(const std::string& value);
void set_device_name(const std::string& name);
void set_mouse();
void set_guitar();

View file

@ -418,10 +418,10 @@ Xboxdrv::run_main(const Options& opts)
int jsdev_number = find_jsdev_number();
int evdev_number = find_evdev_number();
if (opts.led == -1)
if (opts.get_controller_slot().get_led_status() == -1)
controller->set_led(2 + jsdev_number % 4);
else
controller->set_led(opts.led);
controller->set_led(opts.get_controller_slot().get_led_status());
if (opts.rumble_l != -1 && opts.rumble_r != -1)
{ // Only set rumble when explicitly requested

View file

@ -219,7 +219,8 @@ XboxdrvDaemon::init_uinput(const Options& opts)
ControllerSlotConfig::create(*m_uinput, slot_count,
opts.extra_devices,
controller->second),
controller->second.get_match_rules()));
controller->second.get_match_rules(),
controller->second.get_led_status()));
slot_count += 1;
}
@ -482,7 +483,14 @@ XboxdrvDaemon::launch_xboxdrv(const XPadDevice& dev_type, const Options& opts,
{
std::auto_ptr<XboxGenericController> controller = XboxControllerFactory::create(dev_type, dev, opts);
controller->set_led(2 + (slot.id % 4));
if (slot.led_status == -1)
{
controller->set_led(2 + (slot.id % 4));
}
else
{
controller->set_led(slot.led_status);
}
std::auto_ptr<MessageProcessor> message_proc;
if (m_uinput.get())

View file

@ -40,22 +40,26 @@ private:
int id;
ControllerSlotConfigPtr config;
std::vector<ControllerMatchRulePtr> rules;
int led_status;
XboxdrvThread* thread;
ControllerSlot() :
id(),
config(),
rules(),
led_status(-1),
thread(0)
{}
ControllerSlot(int id_,
ControllerSlotConfigPtr config_,
std::vector<ControllerMatchRulePtr> rules_,
int led_status_,
XboxdrvThread* thread_ = 0) :
id(id_),
config(config_),
rules(rules_),
led_status(led_status_),
thread(thread_)
{}
@ -63,6 +67,7 @@ private:
id(rhs.id),
config(rhs.config),
rules(rhs.rules),
led_status(rhs.led_status),
thread(rhs.thread)
{}
@ -73,6 +78,7 @@ private:
id = rhs.id;
config = rhs.config;
rules = rhs.rules;
led_status = rhs.led_status;
thread = rhs.thread;
}
return *this;