Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -268,6 +272,7 @@ pub enum AncState {
Off,
Active,
Aware,
Adaptive,
CycleNext,
CyclePrev,
}
Expand Down
9 changes: 7 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion libmaestro/examples/maestro_write_settings.rs
Original file line number Diff line number Diff line change
@@ -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 -- <bluetooth-device-address> <anc-state>
Expand Down
2 changes: 2 additions & 0 deletions libmaestro/proto/maestro_pw.proto
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,15 @@ message AncrGestureLoop {
bool active = 1;
bool off = 2;
bool aware = 3;
bool adaptive = 4;
}

enum AncState {
ANC_STATE_UNKNOWN = 0;
ANC_STATE_OFF = 1;
ANC_STATE_ACTIVE = 2;
ANC_STATE_AWARE = 3;
ANC_STATE_ADAPTIVE = 4;
}

message EqBands {
Expand Down
17 changes: 15 additions & 2 deletions libmaestro/src/service/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<types::AncrGestureLoop> 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 }
}
}

Expand All @@ -263,6 +264,7 @@ impl From<AncrGestureLoop> for types::AncrGestureLoop {
active: other.active,
off: other.off,
aware: other.aware,
adaptive: other.adaptive,
}
}
}
Expand Down Expand Up @@ -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, "]")
}
}
Expand All @@ -306,6 +316,7 @@ pub enum AncState {
Off = 1,
Active = 2,
Aware = 3,
Adaptive = 4,

#[num_enum(catch_all)]
Unknown(i32),
Expand All @@ -317,6 +328,7 @@ impl AncState {
AncState::Off => "off",
AncState::Active => "active",
AncState::Aware => "aware",
AncState::Adaptive => "adaptive",
AncState::Unknown(_) => "unknown",
}
}
Expand All @@ -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})"),
}
}
Expand Down