Add noise gate option to CLI app

This commit is contained in:
Lennard Kittner
2026-02-24 14:02:36 +01:00
parent 7928f55a98
commit 2fd0373fbe
2 changed files with 40 additions and 7 deletions

View File

@@ -147,6 +147,8 @@ Options:
Enables surround sound. This may be on by default and cannot be changed on your device. [possible values: true, false] Enables surround sound. This may be on by default and cannot be changed on your device. [possible values: true, false]
--mute_playback <mute_playback> --mute_playback <mute_playback>
Mute or unmute playback. [possible values: true, false] Mute or unmute playback. [possible values: true, false]
--activate_noise_gate <activate_noise_gate>
Activates nose gate. [possible values: true, false]
-h, --help -h, --help
Print help Print help
-V, --version -V, --version

View File

@@ -3,6 +3,8 @@ use std::time::Duration;
use clap::{Arg, Command}; use clap::{Arg, Command};
use hyper_headset::devices::connect_compatible_device; use hyper_headset::devices::connect_compatible_device;
const SHOW_ALL_OPTIONS: bool = false;
fn main() { fn main() {
let mut device = match connect_compatible_device() { let mut device = match connect_compatible_device() {
Ok(device) => device, Ok(device) => device,
@@ -24,7 +26,8 @@ fn main() {
.help( .help(
"Set the delay in minutes after which the headset will automatically shutdown.\n0 will disable automatic shutdown.", "Set the delay in minutes after which the headset will automatically shutdown.\n0 will disable automatic shutdown.",
) )
.hide(!device.can_set_automatic_shutdown()) .hide(!SHOW_ALL_OPTIONS
&& !device.can_set_automatic_shutdown())
.value_parser(clap::value_parser!(u8)), .value_parser(clap::value_parser!(u8)),
) )
.arg( .arg(
@@ -32,7 +35,8 @@ fn main() {
.long("mute") .long("mute")
.required(false) .required(false)
.help("Mute or unmute the headset.") .help("Mute or unmute the headset.")
.hide(!device.can_set_mute()) .hide(!SHOW_ALL_OPTIONS
&& !device.can_set_mute())
.value_parser(clap::value_parser!(bool)), .value_parser(clap::value_parser!(bool)),
) )
.arg( .arg(
@@ -40,7 +44,8 @@ fn main() {
.long("enable_side_tone") .long("enable_side_tone")
.required(false) .required(false)
.help("Enable or disable side tone.") .help("Enable or disable side tone.")
.hide(!device.can_set_side_tone()) .hide(!SHOW_ALL_OPTIONS
&& !device.can_set_side_tone())
.value_parser(clap::value_parser!(bool)), .value_parser(clap::value_parser!(bool)),
) )
.arg( .arg(
@@ -48,7 +53,8 @@ fn main() {
.long("side_tone_volume") .long("side_tone_volume")
.required(false) .required(false)
.help("Set the side tone volume.") .help("Set the side tone volume.")
.hide(!device.can_set_side_tone_volume()) .hide(!SHOW_ALL_OPTIONS
&& !device.can_set_side_tone_volume())
.value_parser(clap::value_parser!(u8)), .value_parser(clap::value_parser!(u8)),
) )
.arg( .arg(
@@ -56,7 +62,8 @@ fn main() {
.long("enable_voice_prompt") .long("enable_voice_prompt")
.required(false) .required(false)
.help("Enable voice prompt. This may not be supported on your device.") .help("Enable voice prompt. This may not be supported on your device.")
.hide(!device.can_set_voice_prompt()) .hide(!SHOW_ALL_OPTIONS
&& !device.can_set_voice_prompt())
.value_parser(clap::value_parser!(bool)), .value_parser(clap::value_parser!(bool)),
) )
.arg( .arg(
@@ -64,7 +71,8 @@ fn main() {
.long("surround_sound") .long("surround_sound")
.required(false) .required(false)
.help("Enables surround sound. This may be on by default and cannot be changed on your device.") .help("Enables surround sound. This may be on by default and cannot be changed on your device.")
.hide(!device.can_set_surround_sound()) .hide(!SHOW_ALL_OPTIONS
&& !device.can_set_surround_sound())
.value_parser(clap::value_parser!(bool)), .value_parser(clap::value_parser!(bool)),
) )
.arg( .arg(
@@ -72,7 +80,17 @@ fn main() {
.long("mute_playback") .long("mute_playback")
.required(false) .required(false)
.help("Mute or unmute playback.") .help("Mute or unmute playback.")
.hide(!device.can_set_silent_mode()) .hide(!SHOW_ALL_OPTIONS
&& !device.can_set_silent_mode())
.value_parser(clap::value_parser!(bool)),
)
.arg(
Arg::new("activate_noise_gate")
.long("activate_noise_gate")
.required(false)
.help("Activates nose gate.")
.hide(!SHOW_ALL_OPTIONS
&& !device.can_set_silent_mode())
.value_parser(clap::value_parser!(bool)), .value_parser(clap::value_parser!(bool)),
) )
.get_matches(); .get_matches();
@@ -172,6 +190,19 @@ fn main() {
} }
} }
if let Some(activate) = matches.get_one::<bool>("activate_noise_gate") {
if let Some(packet) = device.set_noise_gate_packet(*activate) {
device.prepare_write();
if let Err(err) = device.get_device_state().hid_device.write(&packet) {
eprintln!("Failed to activate noise gate with error: {:?}", err);
std::process::exit(1);
}
} else {
eprintln!("ERROR: Activating noise gate is not supported on this device");
std::process::exit(1);
}
}
std::thread::sleep(Duration::from_secs_f64(0.5)); std::thread::sleep(Duration::from_secs_f64(0.5));
// setting an option may cause a response form the headset // setting an option may cause a response form the headset