-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
51 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,49 @@ | ||
pub mod devices; | ||
pub mod cc253x; | ||
pub mod cc253x; | ||
use rusb::{Device, DeviceList, Error as RusbError, GlobalContext}; | ||
|
||
pub struct UsbDeviceInfo { | ||
pub device: Option<Device<GlobalContext>>, | ||
pub product_name: &'static str, | ||
pub manufacturer: &'static str, | ||
pub product_id: u16, | ||
pub vendor_id: u16, | ||
} | ||
|
||
// model, manufacturer, vendor_id, product_id | ||
pub const SUPPORTED_DEVICES: [(&str, &str, u16, u16); 1] = | ||
[("CC2531 Dongle", "Texas Instruments", 0x0451, 0x16ae)]; | ||
|
||
fn supported_device_match( | ||
device: &Device<GlobalContext>, | ||
) -> Result<Option<UsbDeviceInfo>, RusbError> { | ||
let descriptor = device.device_descriptor()?; | ||
let product_id = descriptor.product_id(); | ||
let vendor_id = descriptor.vendor_id(); | ||
Ok(SUPPORTED_DEVICES | ||
.iter() | ||
.find(|(_, _, vid, pid)| product_id == *pid && vendor_id == *vid) | ||
.map(|d| UsbDeviceInfo { | ||
device: None, | ||
product_name: d.0, | ||
manufacturer: d.1, | ||
vendor_id: d.2, | ||
product_id: d.3, | ||
})) | ||
} | ||
|
||
pub fn find_supported_device() -> Result<Option<UsbDeviceInfo>, RusbError> { | ||
let device_list = DeviceList::new()?; | ||
for device in device_list.iter() { | ||
if let Some(d) = supported_device_match(&device)? { | ||
return Ok(Some(UsbDeviceInfo { | ||
device: Some(device), | ||
product_name: d.product_name, | ||
manufacturer: d.manufacturer, | ||
vendor_id: d.vendor_id, | ||
product_id: d.product_id, | ||
})); | ||
} | ||
} | ||
Ok(None) | ||
} | ||
|