use std::sync::Arc;
use crate::{
channel::HidppChannel,
feature::{CreatableFeature, Feature, FeatureEndpoint},
protocol::v20::Hidpp20Error,
};
bitflags::bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct ReportRateList: u8 {
const MS_1 = 1 << 0;
const MS_2 = 1 << 1;
const MS_3 = 1 << 2;
const MS_4 = 1 << 3;
const MS_5 = 1 << 4;
const MS_6 = 1 << 5;
const MS_7 = 1 << 6;
const MS_8 = 1 << 7;
}
}
#[derive(Clone)]
pub struct ReportRateFeature {
endpoint: FeatureEndpoint,
}
impl CreatableFeature for ReportRateFeature {
const ID: u16 = 0x8060;
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 ReportRateFeature {}
impl ReportRateFeature {
pub async fn get_report_rate_list(&self) -> Result<ReportRateList, Hidpp20Error> {
let payload = self.endpoint.call(0, [0; 3]).await?.extend_payload();
Ok(ReportRateList::from_bits_retain(payload[0]))
}
pub async fn get_report_rate(&self) -> Result<u8, Hidpp20Error> {
Ok(self.endpoint.call(1, [0; 3]).await?.extend_payload()[0])
}
pub async fn set_report_rate(&self, report_rate_ms: u8) -> Result<(), Hidpp20Error> {
self.endpoint.call(2, [report_rate_ms, 0, 0]).await?;
Ok(())
}
}