use anyhow::Result;
use clap::Subcommand;
pub mod dpi;
pub mod features;
pub mod smartshift;
#[derive(Debug, Subcommand)]
pub enum DiagCmd {
Features(features::FeaturesArgs),
Dpi(dpi::DpiArgs),
Smartshift(smartshift::SmartshiftArgs),
}
impl DiagCmd {
pub async fn run(self) -> Result<()> {
match self {
Self::Features(args) => features::run(args).await,
Self::Dpi(args) => dpi::run(args).await,
Self::Smartshift(args) => smartshift::run(args).await,
}
}
}
pub(crate) async fn first_online_device() -> Result<(String, u8, String)> {
use anyhow::anyhow;
let inventories = openlogi_hid::enumerate().await?;
inventories
.into_iter()
.find_map(|inv| {
let uid = inv.receiver.unique_id?;
let paired = inv.paired.into_iter().find(|p| p.online)?;
let name = paired
.codename
.unwrap_or_else(|| format!("Slot {}", paired.slot));
Some((uid, paired.slot, name))
})
.ok_or_else(|| anyhow!("no online HID++ device found — is a Logi mouse paired?"))
}