Skip to content

Commit

Permalink
Merge pull request #1380 from rofferom/controller-map-vendor-product
Browse files Browse the repository at this point in the history
controller: Add vendor_id() and product_id()
  • Loading branch information
Cobrand authored Jun 13, 2024
2 parents 7596bbd + 67004e6 commit 28063b7
Showing 1 changed file with 24 additions and 0 deletions.
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

0 comments on commit 28063b7

Please sign in to comment.