diff --git a/cli/src/cli.rs b/cli/src/cli.rs index d3c3d69..53628ed 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -195,6 +195,10 @@ pub enum SetSetting { /// Enable 'aware' mode in loop #[arg(action=clap::ArgAction::Set)] aware: bool, + + /// Enable 'adaptive' mode in loop + #[arg(action=clap::ArgAction::Set)] + adaptive: bool, }, /// Set adaptive noise-cancelling state @@ -268,6 +272,7 @@ pub enum AncState { Off, Active, Aware, + Adaptive, CycleNext, CyclePrev, } diff --git a/cli/src/main.rs b/cli/src/main.rs index 9a7f792..4f43547 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -138,8 +138,8 @@ async fn main() -> Result<()> { let value = SettingValue::MultipointEnable(value); run(client, cmd_set_setting(handle, channel, value)).await }, - SetSetting::AncGestureLoop { off, active, aware } => { - let value = settings::AncrGestureLoop { off, active, aware }; + SetSetting::AncGestureLoop { off, active, aware, adaptive } => { + let value = settings::AncrGestureLoop { off, active, aware, adaptive }; if !value.is_valid() { use clap::error::ErrorKind; @@ -169,6 +169,10 @@ async fn main() -> Result<()> { let value = SettingValue::CurrentAncrState(settings::AncState::Active); run(client, cmd_set_setting(handle, channel, value)).await }, + AncState::Adaptive => { + let value = SettingValue::CurrentAncrState(settings::AncState::Adaptive); + run(client, cmd_set_setting(handle, channel, value)).await + }, AncState::CycleNext => { run(client, cmd_anc_cycle(handle, channel, true)).await }, @@ -451,6 +455,7 @@ async fn cmd_anc_cycle(handle: ClientHandle, channel: u32, forward: bool) -> Res (settings::AncState::Active, enabled.active), (settings::AncState::Off, enabled.off), (settings::AncState::Aware, enabled.aware), + (settings::AncState::Adaptive, enabled.adaptive), ]; let index = states.iter().position(|(s, _)| *s == state).unwrap(); diff --git a/libmaestro/examples/maestro_write_settings.rs b/libmaestro/examples/maestro_write_settings.rs index 4cb6323..2b6f7b9 100644 --- a/libmaestro/examples/maestro_write_settings.rs +++ b/libmaestro/examples/maestro_write_settings.rs @@ -1,6 +1,6 @@ //! Simple example for changing settings on the Pixel Buds Pro via the Maestro service. //! -//! Sets active nois ecancelling (ANC) state. 1: off, 2: active, 3: aware. +//! Sets active noise cancelling (ANC) state. 1: off, 2: active, 3: aware, 4: adaptive. //! //! Usage: //! cargo run --example maestro_write_settings -- diff --git a/libmaestro/proto/maestro_pw.proto b/libmaestro/proto/maestro_pw.proto index a17ea66..32aa466 100644 --- a/libmaestro/proto/maestro_pw.proto +++ b/libmaestro/proto/maestro_pw.proto @@ -169,6 +169,7 @@ message AncrGestureLoop { bool active = 1; bool off = 2; bool aware = 3; + bool adaptive = 4; } enum AncState { @@ -176,6 +177,7 @@ enum AncState { ANC_STATE_OFF = 1; ANC_STATE_ACTIVE = 2; ANC_STATE_AWARE = 3; + ANC_STATE_ADAPTIVE = 4; } message EqBands { diff --git a/libmaestro/src/service/settings.rs b/libmaestro/src/service/settings.rs index 183d768..2eed99f 100644 --- a/libmaestro/src/service/settings.rs +++ b/libmaestro/src/service/settings.rs @@ -242,18 +242,19 @@ pub struct AncrGestureLoop { pub active: bool, pub off: bool, pub aware: bool, + pub adaptive: bool, } impl AncrGestureLoop { pub fn is_valid(&self) -> bool { // at least two need to be set - (self.active as u32 + self.off as u32 + self.aware as u32) >= 2 + (self.active as u32 + self.off as u32 + self.aware as u32 + self.adaptive as u32) >= 2 } } impl From for AncrGestureLoop { fn from(other: types::AncrGestureLoop) -> Self { - AncrGestureLoop { active: other.active, off: other.off, aware: other.aware } + AncrGestureLoop { active: other.active, off: other.off, aware: other.aware, adaptive: other.adaptive } } } @@ -263,6 +264,7 @@ impl From for types::AncrGestureLoop { active: other.active, off: other.off, aware: other.aware, + adaptive: other.adaptive, } } } @@ -295,6 +297,14 @@ impl std::fmt::Display for AncrGestureLoop { write!(f, "aware")?; } + if self.adaptive { + if n > 0 { + write!(f, ", ")?; + } + + write!(f, "adaptive")?; + } + write!(f, "]") } } @@ -306,6 +316,7 @@ pub enum AncState { Off = 1, Active = 2, Aware = 3, + Adaptive = 4, #[num_enum(catch_all)] Unknown(i32), @@ -317,6 +328,7 @@ impl AncState { AncState::Off => "off", AncState::Active => "active", AncState::Aware => "aware", + AncState::Adaptive => "adaptive", AncState::Unknown(_) => "unknown", } } @@ -336,6 +348,7 @@ impl std::fmt::Display for AncState { AncState::Off => write!(f, "off"), AncState::Active => write!(f, "active"), AncState::Aware => write!(f, "aware"), + AncState::Adaptive => write!(f, "adaptive"), AncState::Unknown(x) => write!(f, "unknown ({x})"), } }