use std::sync::Arc;
use thiserror::Error;
use crate::{channel::HidppChannel, protocol::v10::Hidpp10Error};
pub mod bolt;
pub mod unifying;
pub const RECEIVER_DEVICE_INDEX: u8 = 0xff;
pub fn detect(chan: Arc<HidppChannel>) -> Option<Receiver> {
let vpid_pair = &(chan.vendor_id, chan.product_id);
if bolt::VPID_PAIRS.contains(vpid_pair) {
return bolt::Receiver::new(chan).ok().map(Receiver::Bolt);
}
if unifying::VPID_PAIRS.contains(vpid_pair) {
return unifying::Receiver::new(chan).ok().map(Receiver::Unifying);
}
None
}
#[derive(Clone)]
#[non_exhaustive]
pub enum Receiver {
Bolt(bolt::Receiver),
Unifying(unifying::Receiver),
}
impl Receiver {
pub fn name(&self) -> String {
match self {
Self::Bolt(_) => "Logi Bolt Receiver",
Self::Unifying(_) => "Unifying Receiver",
}
.to_string()
}
pub async fn get_unique_id(&self) -> Result<String, ReceiverError> {
match self {
Self::Bolt(bolt) => bolt.get_unique_id().await,
Self::Unifying(unifying) => unifying.get_receiver_info().await.map(|x| x.serial_number),
}
}
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum ReceiverError {
#[error("no (supported) receiver could be found")]
UnknownReceiver,
#[error("a HID++1.0 error occurred")]
Protocol(#[from] Hidpp10Error),
}