hidpp/feature/
report_rate.rs1use openlogi_hidpp_derive::Feature;
4
5use crate::{feature::FeatureEndpoint, protocol::v20::Hidpp20Error};
6
7bitflags::bitflags! {
8 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
10 #[cfg_attr(feature = "serde", derive(serde::Serialize))]
11 pub struct ReportRateList: u8 {
12 const MS_1 = 1 << 0;
14 const MS_2 = 1 << 1;
16 const MS_3 = 1 << 2;
18 const MS_4 = 1 << 3;
20 const MS_5 = 1 << 4;
22 const MS_6 = 1 << 5;
24 const MS_7 = 1 << 6;
26 const MS_8 = 1 << 7;
28 }
29}
30
31#[derive(Clone, Feature)]
33#[creatable(id = 0x8060, version = 0)]
34pub struct ReportRateFeature {
35 endpoint: FeatureEndpoint,
37}
38
39impl ReportRateFeature {
40 pub async fn get_report_rate_list(&self) -> Result<ReportRateList, Hidpp20Error> {
42 let payload = self.endpoint.call(0, [0; 3]).await?.extend_payload();
43 Ok(ReportRateList::from_bits_retain(payload[0]))
44 }
45
46 pub async fn get_report_rate(&self) -> Result<u8, Hidpp20Error> {
48 Ok(self.endpoint.call(1, [0; 3]).await?.extend_payload()[0])
49 }
50
51 pub async fn set_report_rate(&self, report_rate_ms: u8) -> Result<(), Hidpp20Error> {
55 self.endpoint.call(2, [report_rate_ms, 0, 0]).await?;
56 Ok(())
57 }
58}