hidpp/feature/disable_keys/
mod.rs1use std::sync::Arc;
8
9use crate::{
10 channel::HidppChannel,
11 feature::{CreatableFeature, Feature, FeatureEndpoint},
12 protocol::v20::Hidpp20Error,
13};
14
15bitflags::bitflags! {
16 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
21 #[cfg_attr(feature = "serde", derive(serde::Serialize))]
22 pub struct DisableableKeys: u8 {
23 const CAPS_LOCK = 1 << 0;
25 const NUM_LOCK = 1 << 1;
27 const SCROLL_LOCK = 1 << 2;
29 const INSERT = 1 << 3;
31 const WINDOWS = 1 << 4;
33 }
34}
35
36#[derive(Clone)]
38pub struct DisableKeysFeature {
39 endpoint: FeatureEndpoint,
41}
42
43impl CreatableFeature for DisableKeysFeature {
44 const ID: u16 = 0x4521;
45 const STARTING_VERSION: u8 = 0;
46
47 fn new(chan: Arc<HidppChannel>, device_index: u8, feature_index: u8) -> Self {
48 Self {
49 endpoint: FeatureEndpoint::new(chan, device_index, feature_index),
50 }
51 }
52}
53
54impl Feature for DisableKeysFeature {}
55
56impl DisableKeysFeature {
57 pub async fn get_capabilities(&self) -> Result<DisableableKeys, Hidpp20Error> {
59 let payload = self.endpoint.call(0, [0; 3]).await?.extend_payload();
60 Ok(DisableableKeys::from_bits_retain(payload[0]))
61 }
62
63 pub async fn get_disabled_keys(&self) -> Result<DisableableKeys, Hidpp20Error> {
65 let payload = self.endpoint.call(1, [0; 3]).await?.extend_payload();
66 Ok(DisableableKeys::from_bits_retain(payload[0]))
67 }
68
69 pub async fn set_disabled_keys(
74 &self,
75 keys: DisableableKeys,
76 ) -> Result<DisableableKeys, Hidpp20Error> {
77 let payload = self
78 .endpoint
79 .call(2, [keys.bits(), 0, 0])
80 .await?
81 .extend_payload();
82 Ok(DisableableKeys::from_bits_retain(payload[0]))
83 }
84}