1use futures_lite::{Stream, StreamExt as _};
4
5use crate::inventory::InventoryError;
6use crate::transport::hid_backend;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum HotplugEvent {
11 Connected,
13 Disconnected,
15}
16
17pub fn watch_hotplug() -> Result<impl Stream<Item = HotplugEvent> + Send + Unpin, InventoryError> {
19 let stream = hid_backend().watch().map_err(InventoryError::Hid)?;
20 Ok(stream.map(|event| match event {
21 async_hid::DeviceEvent::Connected(_) => HotplugEvent::Connected,
22 async_hid::DeviceEvent::Disconnected(_) => HotplugEvent::Disconnected,
23 }))
24}