use std::sync::Arc;
use hidpp::{channel::HidppChannel, device::Device, feature::CreatableFeature};
use crate::route::{DeviceRoute, open_route_channel};
mod diagnostics;
mod dpi;
mod error;
mod lighting;
mod shared;
mod smartshift;
pub use diagnostics::{FeatureEntry, ReprogControlEntry, dump_features, dump_reprog_controls};
pub use dpi::{DpiCapabilities, DpiInfo, get_dpi, get_dpi_info, set_dpi};
pub use error::{HidppFeatureErrorKind, HidppOperation, WriteError};
pub use lighting::{LightingMethod, set_keyboard_color, set_keyboard_color_with};
pub use shared::{SharedChannel, set_dpi_on, set_smartshift_on, toggle_smartshift_on};
pub use smartshift::{
get_smartshift_status, set_smartshift, set_smartshift_sensitivity, toggle_smartshift,
};
pub(crate) use error::classify_hidpp_error;
pub(crate) async fn open_feature<F: CreatableFeature + 'static>(
device: &mut Device,
) -> Result<Arc<F>, WriteError> {
let info = device
.root()
.get_feature(F::ID)
.await
.map_err(|e| classify_hidpp_error(e, HidppOperation::ResolveFeature, F::ID))?
.ok_or(WriteError::FeatureUnsupported { feature_hex: F::ID })?;
Ok(device.add_feature::<F>(info.index))
}
pub(crate) async fn with_route<F, Fut, T>(route: &DeviceRoute, f: F) -> Result<T, WriteError>
where
F: FnOnce(Arc<HidppChannel>) -> Fut,
Fut: std::future::Future<Output = Result<T, WriteError>>,
{
match open_route_channel(route).await? {
Some(channel) => f(channel).await,
None => Err(WriteError::DeviceNotFound),
}
}
#[cfg(test)]
mod tests;