use serde::Serialize;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum DeviceKind {
Mouse,
Keyboard,
Numpad,
Presenter,
Remote,
Trackball,
Touchpad,
Tablet,
Gamepad,
Joystick,
Headset,
Unknown,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum BatteryLevel {
Critical,
Low,
Good,
Full,
Unknown,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum BatteryStatus {
Discharging,
Charging,
ChargingSlow,
Full,
Error,
Unknown,
}
#[derive(Debug, Clone, Serialize)]
pub struct BatteryInfo {
pub percentage: u8,
pub level: BatteryLevel,
pub status: BatteryStatus,
}
#[derive(Debug, Clone, Serialize)]
pub struct ReceiverInfo {
pub name: String,
pub vendor_id: u16,
pub product_id: u16,
pub unique_id: Option<String>,
}
#[derive(Debug, Clone, Copy, Serialize)]
pub struct DeviceModelInfo {
pub entity_count: u8,
pub unit_id: [u8; 4],
pub transports: DeviceTransports,
pub model_ids: [u16; 3],
pub extended_model_id: u8,
}
impl DeviceModelInfo {
#[must_use]
pub fn config_key(&self) -> String {
format!("{:x}{:04x}", self.extended_model_id, self.model_ids[0])
}
}
#[allow(
clippy::struct_excessive_bools,
reason = "bitfield mirroring HID++ DeviceInformation; transports are independent flags"
)]
#[derive(Debug, Clone, Copy, Default, Serialize)]
pub struct DeviceTransports {
pub usb: bool,
pub equad: bool,
pub btle: bool,
pub bluetooth: bool,
}
#[derive(Debug, Clone, Serialize)]
pub struct PairedDevice {
pub slot: u8,
pub codename: Option<String>,
pub wpid: Option<u16>,
pub kind: DeviceKind,
pub online: bool,
pub battery: Option<BatteryInfo>,
pub model_info: Option<DeviceModelInfo>,
}
#[derive(Debug, Clone, Serialize)]
pub struct DeviceInventory {
pub receiver: ReceiverInfo,
pub paired: Vec<PairedDevice>,
}