-
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
7 changed files
with
88 additions
and
19 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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
mod bass_up_update; | ||
mod eq_update_command; | ||
mod features; | ||
mod sound_mode_update_command; | ||
|
||
pub use bass_up_update::*; | ||
pub use eq_update_command::*; | ||
pub use features::*; | ||
pub use sound_mode_update_command::*; |
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 @@ | ||
use nom::{combinator::map, error::context}; | ||
|
||
use crate::{ | ||
models::BassUp, | ||
parsers::{parse_bool, ParseError, ParseResult}, | ||
}; | ||
|
||
pub fn parse_a3040_bass_up_update<'a, E: ParseError<'a>>( | ||
bytes: &'a [u8], | ||
) -> ParseResult<BassUp, E> { | ||
context("parse_a3040_bass_up_update", map(parse_bool, BassUp))(bytes) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use log::{debug, warn}; | ||
use nom::combinator::map; | ||
use nom::error::context; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::api::SoundcoreDeviceState; | ||
use crate::devices::parse_a3040_bass_up_update; | ||
use crate::models::BassUp; | ||
use crate::packets::StateTransformationPacket; | ||
use crate::parsers::{ParseError, ParseResult}; | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)] | ||
pub struct BassUpUpdateResponse(pub BassUp); | ||
pub fn parse_bass_up_update<'a, E: ParseError<'a>>( | ||
bytes: &'a [u8], | ||
) -> ParseResult<BassUpUpdateResponse, E> { | ||
context( | ||
"parse_bass_up_update", | ||
map(parse_a3040_bass_up_update, BassUpUpdateResponse), | ||
)(bytes) | ||
} | ||
|
||
impl StateTransformationPacket for BassUpUpdateResponse { | ||
fn transform_state(self, state: &SoundcoreDeviceState) -> SoundcoreDeviceState { | ||
let mut state = state.to_owned(); | ||
match state.bass_up { | ||
Some(bass_up) => { | ||
debug!("Updating BassUp state from {:?} to {:?}", bass_up, self.0); | ||
state.bass_up = Some(self.0); | ||
} | ||
None => { | ||
warn!("BassUpUpdateResponse received without a previous BassUp state"); | ||
} | ||
} | ||
state | ||
} | ||
} |
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