use futures_lite::{Stream, StreamExt as _};
use crate::inventory::InventoryError;
use crate::transport::hid_backend;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HotplugEvent {
Connected,
Disconnected,
}
pub fn watch_hotplug() -> Result<impl Stream<Item = HotplugEvent> + Send + Unpin, InventoryError> {
let stream = hid_backend().watch().map_err(InventoryError::Hid)?;
Ok(stream.map(|event| match event {
async_hid::DeviceEvent::Connected(_) => HotplugEvent::Connected,
async_hid::DeviceEvent::Disconnected(_) => HotplugEvent::Disconnected,
}))
}