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 DisableableKeys: u8 {
const CAPS_LOCK = 1 << 0;
const NUM_LOCK = 1 << 1;
const SCROLL_LOCK = 1 << 2;
const INSERT = 1 << 3;
const WINDOWS = 1 << 4;
}
}
#[derive(Clone)]
pub struct DisableKeysFeature {
endpoint: FeatureEndpoint,
}
impl CreatableFeature for DisableKeysFeature {
const ID: u16 = 0x4521;
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 DisableKeysFeature {}
impl DisableKeysFeature {
pub async fn get_capabilities(&self) -> Result<DisableableKeys, Hidpp20Error> {
let payload = self.endpoint.call(0, [0; 3]).await?.extend_payload();
Ok(DisableableKeys::from_bits_retain(payload[0]))
}
pub async fn get_disabled_keys(&self) -> Result<DisableableKeys, Hidpp20Error> {
let payload = self.endpoint.call(1, [0; 3]).await?.extend_payload();
Ok(DisableableKeys::from_bits_retain(payload[0]))
}
pub async fn set_disabled_keys(
&self,
keys: DisableableKeys,
) -> Result<DisableableKeys, Hidpp20Error> {
let payload = self
.endpoint
.call(2, [keys.bits(), 0, 0])
.await?
.extend_payload();
Ok(DisableableKeys::from_bits_retain(payload[0]))
}
}