Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override device_id when device_name is provided. (#199) #211

Merged
merged 1 commit into from
Sep 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions joy/src/joy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ void Joy::handleJoyDeviceAdded(const SDL_Event & e)
RCLCPP_WARN(get_logger(), "Failed to get the number of joysticks: %s", SDL_GetError());
return;
}
bool matching_device_found = false;
for (int i = 0; i < num_joysticks; ++i) {
const char * name = SDL_JoystickNameForIndex(i);
if (name == nullptr) {
Expand All @@ -316,10 +317,17 @@ void Joy::handleJoyDeviceAdded(const SDL_Event & e)
}
if (std::string(name) == dev_name_) {
// We found it!
matching_device_found = true;
dev_id_ = i;
break;
}
}
if (!matching_device_found) {
RCLCPP_WARN(
get_logger(), "Could not get joystick with name %s: %s",
dev_name_.c_str(), SDL_GetError());
return;
}
}

if (e.jdevice.which != dev_id_) {
Expand Down