use std::sync::Arc;
use crate::{
channel::HidppChannel,
feature::{CreatableFeature, Feature, FeatureType},
nibble::U4,
protocol::v20::{self, Hidpp20Error},
};
#[derive(Clone)]
pub struct FeatureSetFeatureV0 {
chan: Arc<HidppChannel>,
device_index: u8,
feature_index: u8,
}
impl CreatableFeature for FeatureSetFeatureV0 {
const ID: u16 = 0x0001;
const STARTING_VERSION: u8 = 0;
fn new(chan: Arc<HidppChannel>, device_index: u8, feature_index: u8) -> Self {
Self {
chan,
device_index,
feature_index,
}
}
}
impl Feature for FeatureSetFeatureV0 {
}
impl FeatureSetFeatureV0 {
pub async fn count(&self) -> Result<u8, Hidpp20Error> {
let response = self
.chan
.send_v20(v20::Message::Short(
v20::MessageHeader {
device_index: self.device_index,
feature_index: self.feature_index,
function_id: U4::from_lo(0),
software_id: self.chan.get_sw_id(),
},
[0x00, 0x00, 0x00],
))
.await?;
Ok(response.extend_payload()[0])
}
pub async fn get_feature(&self, index: u8) -> Result<FeatureInformation, Hidpp20Error> {
let response = self
.chan
.send_v20(v20::Message::Short(
v20::MessageHeader {
device_index: self.device_index,
feature_index: self.feature_index,
function_id: U4::from_lo(1),
software_id: self.chan.get_sw_id(),
},
[index, 0x00, 0x00],
))
.await?;
let payload = response.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)]
#[non_exhaustive]
pub struct FeatureInformation {
pub id: u16,
pub typ: FeatureType,
pub version: u8,
}