-
Notifications
You must be signed in to change notification settings - Fork 10
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
Showing
12 changed files
with
166 additions
and
46 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
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
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod features; | ||
mod sound_mode_update_command; | ||
|
||
pub use features::*; | ||
pub use features::*; | ||
pub use sound_mode_update_command::*; |
53 changes: 53 additions & 0 deletions
53
soundcore-lib/src/devices/a3040/sound_mode_update_command.rs
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,53 @@ | ||
use crate::{models::SoundMode, packets::Packet}; | ||
|
||
pub struct A3040SoundModeUpdateCommand { | ||
sound_mode: SoundMode, | ||
} | ||
|
||
impl A3040SoundModeUpdateCommand { | ||
pub fn new(sound_mode: SoundMode) -> Self { | ||
Self { sound_mode } | ||
} | ||
} | ||
|
||
impl Packet for A3040SoundModeUpdateCommand { | ||
fn command(&self) -> [u8; 7] { | ||
[0x08, 0xEE, 0x00, 0x00, 0x00, 0x06, 0x81] | ||
} | ||
|
||
fn payload(&self) -> Vec<u8> { | ||
self.sound_mode.to_bytes_with_custom_transparency().to_vec() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::vec; | ||
|
||
use super::*; | ||
use crate::models::{ | ||
ANCMode, AdaptiveANCMode, CurrentSoundMode, CustomANCValue, CustomTransparencyValue, | ||
CustomizableTransparencyMode, TransparencyMode, | ||
}; | ||
|
||
#[test] | ||
fn test_sound_mode_update_command() { | ||
let command = A3040SoundModeUpdateCommand { | ||
sound_mode: SoundMode { | ||
current: CurrentSoundMode::ANC, | ||
anc_mode: ANCMode::Adaptive(AdaptiveANCMode::Adaptive), | ||
custom_anc: CustomANCValue::from_u8(5), | ||
trans_mode: TransparencyMode::Customizable(CustomizableTransparencyMode::Custom), | ||
custom_trans: Some(CustomTransparencyValue::from_u8(3)), | ||
}, | ||
}; | ||
|
||
assert_eq!( | ||
command.bytes(), | ||
vec![ | ||
0x08, 0xee, 0x00, 0x00, 0x00, 0x06, 0x81, 0x10, 0x00, 0x00, 0x51, 0x01, 0x01, 0x00, | ||
0x03, 0xe3, | ||
] | ||
); | ||
} | ||
} |
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
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
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
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
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
mod sound_mode; | ||
|
||
pub use sound_mode::*; |
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,23 @@ | ||
use crate::{ | ||
devices::A3040SoundModeUpdateCommand, models::SoundMode, packets::Packet, | ||
types::SupportedModels, | ||
}; | ||
|
||
pub struct SoundModeCommandBuilder { | ||
sound_mode: SoundMode, | ||
model: SupportedModels, | ||
} | ||
|
||
impl SoundModeCommandBuilder { | ||
pub fn new(sound_mode: SoundMode, model: SupportedModels) -> Self { | ||
Self { sound_mode, model } | ||
} | ||
|
||
pub fn build(self) -> Vec<u8> { | ||
match self.model { | ||
SupportedModels::A3040 => A3040SoundModeUpdateCommand::new(self.sound_mode).bytes(), | ||
// TODO: use a default comamnd A3951? | ||
_ => panic!("Unsupported model"), | ||
} | ||
} | ||
} |
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