use std::sync::Arc;
use crate::{
channel::HidppChannel,
feature::{CreatableFeature, Feature, FeatureEndpoint},
protocol::v20::Hidpp20Error,
};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[non_exhaustive]
pub struct SidetoneMuteStatus {
pub statuses: u8,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct SidetoneMuteChange {
pub change_mask: u8,
pub statuses: u8,
}
#[derive(Clone)]
pub struct SidetoneFeature {
endpoint: FeatureEndpoint,
}
impl CreatableFeature for SidetoneFeature {
const ID: u16 = 0x8300;
const STARTING_VERSION: u8 = 1;
fn new(chan: Arc<HidppChannel>, device_index: u8, feature_index: u8) -> Self {
Self {
endpoint: FeatureEndpoint::new(chan, device_index, feature_index),
}
}
}
impl Feature for SidetoneFeature {}
impl SidetoneFeature {
pub async fn get_sidetone_level(&self) -> Result<u8, Hidpp20Error> {
Ok(self.endpoint.call(0, [0; 3]).await?.extend_payload()[0])
}
pub async fn set_sidetone_level(&self, level: u8) -> Result<(), Hidpp20Error> {
self.endpoint.call(1, [level, 0, 0]).await?;
Ok(())
}
pub async fn get_sidetone_mute(&self) -> Result<SidetoneMuteStatus, Hidpp20Error> {
Ok(SidetoneMuteStatus {
statuses: self.endpoint.call(2, [0; 3]).await?.extend_payload()[0],
})
}
pub async fn set_sidetone_mute(&self, change: SidetoneMuteChange) -> Result<(), Hidpp20Error> {
self.endpoint
.call(3, [change.change_mask, change.statuses, 0])
.await?;
Ok(())
}
}