-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 824c988
Showing
9 changed files
with
511 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "yeti" | ||
version = "1.0.0" | ||
authors = ["Maximilian Hils <git@maximilianhils.com>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
anyhow = "1.0.33" | ||
hidapi = "1.2" | ||
windows = "0.19" | ||
|
||
[build-dependencies] | ||
windows = "0.19" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2021 Maximilian Hils | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Blue Yeti Volume Sync | ||
|
||
`yeti.exe` is a small utility program that | ||
syncs the volume level of the Blue Yeti with | ||
Windows' device volume settings. | ||
|
||
This was mostly developed as fun exercise to reverse USB HID protocols | ||
and play around with Rust's [`windows-rs`](https://github.com/microsoft/windows-rs). | ||
|
||
## Usage | ||
|
||
Download `yeti.exe` from the [releases page](https://github.com/mhils/yeti-volume-sync/releases). | ||
|
||
To sync volume settings permanently, place yeti.exe somewhere on your system | ||
and then create a shortcut to `C:\your\path\to\yeti.exe --hide` in | ||
`%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup`. | ||
|
||
## Compatibility | ||
|
||
This code was tested with a Blue Yeti X only, | ||
but maybe also works with the regular Yeti. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
fn main() { | ||
windows::build! { | ||
Windows::Win32::Foundation::PWSTR, | ||
Windows::Win32::Media::Audio::CoreAudio::*, | ||
Windows::Win32::Storage::StructuredStorage::{PROPVARIANT, STGM_READ}, | ||
Windows::Win32::System::Com::*, | ||
Windows::Win32::System::Console::GetConsoleWindow, | ||
Windows::Win32::System::PropertiesSystem::{IPropertyStore, PROPERTYKEY}, | ||
Windows::Win32::System::SystemServices::*, | ||
Windows::Win32::UI::WindowsAndMessaging::ShowWindow, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
use std::time::Instant; | ||
|
||
use anyhow::Result; | ||
|
||
pub fn get_yeti(api: &hidapi::HidApi) -> Result<hidapi::HidDevice> { | ||
for device in api.device_list() { | ||
if device.vendor_id() == 0x46d && device.product_id() == 0xaaf { | ||
if device.usage() == 1 { | ||
let dev = device.open_device(&api)?; | ||
return Ok(dev); | ||
} | ||
// there are other usage ids. one is used by GHub, the other doesn't emit anything. | ||
} | ||
} | ||
return Err(anyhow!("Yeti not found.")); | ||
} | ||
|
||
pub fn send(device: &hidapi::HidDevice, opcode: Op, val: &str) -> Result<()> { | ||
let mut buf = [0u8; 65]; | ||
buf[0] = 0x01; | ||
buf[4] = opcode as u8; | ||
buf[8] = 8 + val.len() as u8; | ||
buf[9..9 + val.len()].copy_from_slice(val.as_bytes()); | ||
//println!("Send hex: {:x?}", buf); | ||
let res = device.write(&buf)?; | ||
ensure!(res == 64, "did not write all bytes"); | ||
Ok(()) | ||
} | ||
|
||
pub fn read(device: &hidapi::HidDevice, op: Recv, timeout: i32) -> Result<Option<u8>> { | ||
let start = Instant::now(); | ||
loop { | ||
let mut buf = [0u8; 0x40]; | ||
|
||
let bytes_read = if timeout >= 0 { | ||
let elapsed = start.elapsed().as_millis(); | ||
if elapsed >= timeout as u128 { | ||
return Ok(None); | ||
} | ||
device.read_timeout(&mut buf, timeout - elapsed as i32)? | ||
} else { | ||
device.read(&mut buf)? | ||
}; | ||
|
||
if bytes_read == 0 { | ||
return Ok(None); | ||
} | ||
|
||
//println!("{:02x?}", buf); | ||
|
||
if &buf[..4] == &[0x01, 0x80, 0x00, 0x00] { | ||
match Recv::from_u8(buf[4]) { | ||
Ok(r) if r == op => { | ||
let val = buf[9]; | ||
return Ok(Some(val)); | ||
} | ||
Ok(_) => {} | ||
Err(e) => { | ||
println!("{}", e); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
#[allow(dead_code)] | ||
pub enum Op { | ||
GetVolume = 0x01, | ||
UnknownX05 = 0x05, | ||
SetPattern = 0x08, | ||
SetBlend = 0x14, | ||
SetGain = 0x17, | ||
Mute = 0x20, | ||
SetVolume = 0x23, | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum Recv { | ||
OldPattern, | ||
Pattern, | ||
SoftwareBlend, | ||
DeviceBlend, | ||
SoftwareGain, | ||
DeviceGain, | ||
SoftwareMute, | ||
DeviceMute, | ||
SoftwareVolume, | ||
DeviceVolume, | ||
UnknownX05, | ||
} | ||
|
||
impl Recv { | ||
pub fn from_u8(value: u8) -> Result<Recv> { | ||
Ok(match value { | ||
0x01 => Recv::DeviceVolume, | ||
0x05 => Recv::UnknownX05, | ||
0x08 => Recv::OldPattern, | ||
0x12 => Recv::Pattern, | ||
0x14 => Recv::SoftwareBlend, | ||
0x15 => Recv::DeviceBlend, | ||
0x17 => Recv::SoftwareGain, | ||
0x18 => Recv::DeviceGain, | ||
0x20 => Recv::SoftwareMute, | ||
0x21 => Recv::DeviceMute, | ||
0x23 => Recv::SoftwareVolume, | ||
0x24 => Recv::DeviceVolume, | ||
_ => return Err(anyhow!("Received unknown message type: {:x}", value)), | ||
}) | ||
} | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub mod pattern { | ||
pub const STEREO: &str = "0"; | ||
pub const OMNIDIRECTIONAL: &str = "1"; | ||
pub const CARDIOID: &str = "2"; | ||
pub const BIDIRECTIONAL: &str = "3"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#[macro_use] | ||
extern crate anyhow; | ||
extern crate hidapi; | ||
|
||
|
||
use std::{thread, time}; | ||
|
||
use anyhow::Result; | ||
|
||
mod win; | ||
mod hid; | ||
|
||
fn main() -> Result<()> { | ||
if std::env::args().any(|x| x == "--hide") { | ||
win::hide_window(); | ||
} else { | ||
println!("Run with --hide to hide console window."); | ||
} | ||
loop { | ||
let err = sync_volumes().err().unwrap(); | ||
println!("Error syncing Yeti ({}). Sleeping for 5s...", err); | ||
thread::sleep(time::Duration::from_secs(5)); | ||
} | ||
} | ||
|
||
fn sync_volumes() -> Result<()> { | ||
let api = hidapi::HidApi::new()?; | ||
let yeti_hid = hid::get_yeti(&api)?; | ||
let yeti_snd = win::get_yeti()?; | ||
|
||
println!("Yeti found."); | ||
|
||
// We need to send this for the yeti to get into a proper state. | ||
// It's still somewhat flaky, but that's also the case with the Blue Sherpa software. | ||
hid::send(&yeti_hid, hid::Op::UnknownX05, "")?; | ||
hid::send(&yeti_hid, hid::Op::GetVolume, "")?; | ||
let vol_yeti = hid::read(&yeti_hid, hid::Recv::DeviceVolume, 5000)? | ||
.ok_or(anyhow!("cannot get yeti volume"))?; | ||
|
||
let vol_windows = win::get_volume(&yeti_snd)?; | ||
if vol_yeti < vol_windows { | ||
win::set_volume(&yeti_snd, vol_yeti)?; | ||
println!("Windows volume lowered from {} to {}.", vol_windows, vol_yeti); | ||
} else if vol_windows < vol_yeti { | ||
hid::send(&yeti_hid, hid::Op::SetVolume, &vol_windows.to_string())?; | ||
println!("Yeti volume lowered from {} to {}.", vol_yeti, vol_windows); | ||
} else { | ||
println!("Both volumes are at {}.", vol_yeti); | ||
} | ||
|
||
//let current_volume = win::get_volume(&yeti_snd)?.to_string(); | ||
//hid::send(&yeti_hid, hid::Op::SetVolume, ¤t_volume)?; | ||
//hid::send(&yeti_hid, hid::Op::SetPattern, hid::pattern::CARDIOID)?; | ||
//hid::send(&yeti_hid, hid::Op::SetBlend, "50")?; | ||
//hid::send(&yeti_hid, hid::Op::SetGain, "25")?; | ||
//hid::send(&yeti_hid, hid::Op::Mute, "0")?; | ||
|
||
// Register for notifications for Windows -> Yeti updates. | ||
println!("Watching changes..."); | ||
win::register_yeti_updater(&yeti_snd, hid::get_yeti(&api)?)?; | ||
|
||
// Read HID messages to perform Yeti -> Windows updates. | ||
loop { | ||
let new_yeti_volume = hid::read(&yeti_hid, hid::Recv::DeviceVolume, -1)? | ||
.ok_or(anyhow!("no data read"))?; | ||
println!("Adjusting Windows volume to {}.", new_yeti_volume); | ||
win::set_volume(&yeti_snd, new_yeti_volume)?; | ||
} | ||
} |
Oops, something went wrong.