use std::sync::Arc;
use crate::{
channel::HidppChannel,
feature::{CreatableFeature, Feature, FeatureEndpoint, FeatureType},
protocol::v20::Hidpp20Error,
};
#[derive(Clone)]
pub struct FeatureSetFeature {
endpoint: FeatureEndpoint,
}
impl CreatableFeature for FeatureSetFeature {
const ID: u16 = 0x0001;
const STARTING_VERSION: u8 = 0;
fn new(chan: Arc<HidppChannel>, device_index: u8, feature_index: u8) -> Self {
Self {
endpoint: FeatureEndpoint::new(chan, device_index, feature_index),
}
}
}
impl Feature for FeatureSetFeature {}
impl FeatureSetFeature {
pub async fn count(&self) -> Result<u8, Hidpp20Error> {
Ok(self.endpoint.call(0, [0; 3]).await?.extend_payload()[0])
}
pub async fn get_feature(&self, index: u8) -> Result<FeatureInformation, Hidpp20Error> {
let payload = self
.endpoint
.call(1, [index, 0x00, 0x00])
.await?
.extend_payload();
Ok(FeatureInformation {
id: (payload[0] as u16) << 8 | payload[1] as u16,
typ: FeatureType::from(payload[2]),
version: payload[3],
})
}
}
#[derive(Clone, Copy, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[non_exhaustive]
pub struct FeatureInformation {
pub id: u16,
pub typ: FeatureType,
pub version: u8,
}