use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub enum BusType {
#[default]
Unknown,
Usb,
Bluetooth,
I2c,
Spi,
}
impl fmt::Display for BusType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = match self {
BusType::Unknown => "Unknown",
BusType::Usb => "USB",
BusType::Bluetooth => "Bluetooth",
BusType::I2c => "I2C",
BusType::Spi => "SPI",
};
f.write_str(name)
}
}
#[derive(Debug, Clone, Default)]
pub struct DeviceInfo {
pub(crate) path: String,
pub(crate) vendor_id: u16,
pub(crate) product_id: u16,
pub(crate) serial_number: Option<String>,
pub(crate) release_number: u16,
pub(crate) manufacturer_string: Option<String>,
pub(crate) product_string: Option<String>,
pub(crate) usage_page: u16,
pub(crate) usage: u16,
pub(crate) interface_number: i32,
pub(crate) bus_type: BusType,
}
impl DeviceInfo {
pub fn path(&self) -> &str {
&self.path
}
pub fn vendor_id(&self) -> u16 {
self.vendor_id
}
pub fn product_id(&self) -> u16 {
self.product_id
}
pub fn serial_number(&self) -> Option<&str> {
self.serial_number.as_deref()
}
pub fn release_number(&self) -> u16 {
self.release_number
}
pub fn manufacturer_string(&self) -> Option<&str> {
self.manufacturer_string.as_deref()
}
pub fn product_string(&self) -> Option<&str> {
self.product_string.as_deref()
}
pub fn usage_page(&self) -> u16 {
self.usage_page
}
pub fn usage(&self) -> u16 {
self.usage
}
pub fn interface_number(&self) -> i32 {
self.interface_number
}
pub fn bus_type(&self) -> BusType {
self.bus_type
}
}