Skip to content

Commit fd39150

Browse files
author
Tiger Sachse
authored
Override device_id when device_name is provided. (#199) (#211)
1 parent 3fd02f4 commit fd39150

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

joy/src/joy.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ void Joy::handleJoyDeviceAdded(const SDL_Event & e)
308308
RCLCPP_WARN(get_logger(), "Failed to get the number of joysticks: %s", SDL_GetError());
309309
return;
310310
}
311+
bool matching_device_found = false;
311312
for (int i = 0; i < num_joysticks; ++i) {
312313
const char * name = SDL_JoystickNameForIndex(i);
313314
if (name == nullptr) {
@@ -316,10 +317,17 @@ void Joy::handleJoyDeviceAdded(const SDL_Event & e)
316317
}
317318
if (std::string(name) == dev_name_) {
318319
// We found it!
320+
matching_device_found = true;
319321
dev_id_ = i;
320322
break;
321323
}
322324
}
325+
if (!matching_device_found) {
326+
RCLCPP_WARN(
327+
get_logger(), "Could not get joystick with name %s: %s",
328+
dev_name_.c_str(), SDL_GetError());
329+
return;
330+
}
323331
}
324332

325333
if (e.jdevice.which != dev_id_) {

0 commit comments

Comments
 (0)