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

controller: Add vendor_id() and product_id() #1380

Merged
merged 1 commit into from
Jun 13, 2024
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
24 changes: 24 additions & 0 deletions src/sdl2/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,30 @@ impl GameController {
}
}

/// Return the USB vendor ID of an opened controller, if available.
#[doc(alias = "SDL_GameControllerGetVendor")]
pub fn vendor_id(&self) -> Option<u16> {
let result = unsafe { sys::SDL_GameControllerGetVendor(self.raw) };

if result == 0 {
None
} else {
Some(result)
}
}

/// Return the USB product ID of an opened controller, if available.
#[doc(alias = "SDL_GameControllerGetProduct")]
pub fn product_id(&self) -> Option<u16> {
let result = unsafe { sys::SDL_GameControllerGetProduct(self.raw) };

if result == 0 {
None
} else {
Some(result)
}
}

/// Get the position of the given `axis`
#[doc(alias = "SDL_GameControllerGetAxis")]
pub fn axis(&self, axis: Axis) -> i16 {
Expand Down
Loading