use openlogi_hidpp_derive::Feature;
use crate::{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, Feature)]
#[creatable(id = 0x8300, version = 1)]
pub struct SidetoneFeature {
endpoint: FeatureEndpoint,
}
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(())
}
}