diff --git a/manager-app/src/async_bridge/command.rs b/manager-app/src/async_bridge/command.rs index 4710570..ffbceb4 100644 --- a/manager-app/src/async_bridge/command.rs +++ b/manager-app/src/async_bridge/command.rs @@ -3,7 +3,7 @@ use typeshare::typeshare; use soundcore_lib::btaddr::BluetoothAdrr; use soundcore_lib::device_manager::DiscoveredDevice; -use soundcore_lib::models::{EQProfile, MonoEQ, SoundMode}; +use soundcore_lib::models::{EQProfile, SoundMode}; #[typeshare] #[derive(Debug, Deserialize, Clone)] diff --git a/manager-fut/src/wasm.rs b/manager-fut/src/wasm.rs index 737cbb6..6a1be1b 100644 --- a/manager-fut/src/wasm.rs +++ b/manager-fut/src/wasm.rs @@ -1,6 +1,6 @@ -use std::{future::Future, rc::Rc, time::Duration}; use futures::pin_mut; use js_sys::Promise; +use std::{future::Future, rc::Rc, time::Duration}; use tokio::{select, sync::Notify}; use wasm_bindgen_futures::JsFuture; use web_sys::window; diff --git a/manager-wasm/src/connection.rs b/manager-wasm/src/connection.rs index 2c4ce1f..16b3b3c 100644 --- a/manager-wasm/src/connection.rs +++ b/manager-wasm/src/connection.rs @@ -2,8 +2,8 @@ use std::cell::RefCell; use js_sys::{Array, Uint8Array}; use tokio::sync::mpsc::Receiver; -use wasm_bindgen::{JsCast, JsValue}; use wasm_bindgen::prelude::Closure; +use wasm_bindgen::{JsCast, JsValue}; use wasm_bindgen_futures::JsFuture; use web_sys::{ BluetoothDevice, BluetoothRemoteGattCharacteristic, BluetoothRemoteGattServer, @@ -60,7 +60,11 @@ impl BLEConnection for WebBLEConnection { fn descriptor(&self) -> BLEDeviceDescriptor { BLEDeviceDescriptor { addr: Default::default(), - name: self.gatt_server.device().name().unwrap_or(String::default()) + name: self + .gatt_server + .device() + .name() + .unwrap_or(String::default()), } } async fn byte_channel(&self) -> SoundcoreLibResult>> { diff --git a/soundcore-lib/src/ble/btleplug/connection.rs b/soundcore-lib/src/ble/btleplug/connection.rs index 7e06794..0ce696a 100644 --- a/soundcore-lib/src/ble/btleplug/connection.rs +++ b/soundcore-lib/src/ble/btleplug/connection.rs @@ -1,5 +1,5 @@ use async_trait::async_trait; -use btleplug::api::{Characteristic, CharPropFlags, Peripheral as _, Service}; +use btleplug::api::{CharPropFlags, Characteristic, Peripheral as _, Service}; use btleplug::platform::Peripheral; use futures::StreamExt; use log::{error, trace, warn}; diff --git a/soundcore-lib/src/ble/characteristic_resolver.rs b/soundcore-lib/src/ble/characteristic_resolver.rs index f0abee6..6fd5316 100644 --- a/soundcore-lib/src/ble/characteristic_resolver.rs +++ b/soundcore-lib/src/ble/characteristic_resolver.rs @@ -1,3 +1,3 @@ mod resolver; -pub use resolver::*; \ No newline at end of file +pub use resolver::*; diff --git a/soundcore-lib/src/btaddr.rs b/soundcore-lib/src/btaddr.rs index f573d4f..32f3cbc 100644 --- a/soundcore-lib/src/btaddr.rs +++ b/soundcore-lib/src/btaddr.rs @@ -10,6 +10,7 @@ use crate::error::{SoundcoreLibError, SoundcoreLibResult}; #[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] #[typeshare] +#[derive(Default)] pub struct BluetoothAdrr { pub address: [u8; 6], } @@ -110,13 +111,6 @@ impl From for u64 { } } -impl Default for BluetoothAdrr { - fn default() -> Self { - BluetoothAdrr { - address: [0, 0, 0, 0, 0, 0], - } - } -} impl Display for BluetoothAdrr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { diff --git a/soundcore-lib/src/device.rs b/soundcore-lib/src/device.rs index a87fe37..ba4cb6a 100644 --- a/soundcore-lib/src/device.rs +++ b/soundcore-lib/src/device.rs @@ -2,8 +2,7 @@ use std::sync::Arc; use std::time::Duration; use log::{debug, error, trace}; -use tokio::sync::{mpsc, Mutex, watch}; -use tokio::task::JoinHandle; +use tokio::sync::{mpsc, watch, Mutex}; use manager_fut::ManagerFuture; @@ -235,10 +234,7 @@ where WriteType::WithoutResponse, ) .await?; - new_state.bass_up = match new_state.bass_up { - None => None, - Some(_) => Some(BassUp(false)), - }; + new_state.bass_up = new_state.bass_up.map(|_| BassUp(false)); } } } diff --git a/soundcore-lib/src/device_manager.rs b/soundcore-lib/src/device_manager.rs index 720363a..5c72b3c 100644 --- a/soundcore-lib/src/device_manager.rs +++ b/soundcore-lib/src/device_manager.rs @@ -1,6 +1,6 @@ -use std::{sync::Arc, time::Duration}; use std::collections::hash_map::Entry; use std::collections::HashMap; +use std::{sync::Arc, time::Duration}; use serde::{Deserialize, Serialize}; use tokio::sync::RwLock; @@ -8,9 +8,14 @@ use typeshare::typeshare; use manager_fut::ManagerFuture; /// default-features shall be set to false -#[cfg(any(feature = "mock", feature = "btleplug-backend", feature = "winrt-backend"))] +#[cfg(any( + feature = "mock", + feature = "btleplug-backend", + feature = "winrt-backend" +))] use manager_fut::TokioFuture; +use crate::ble::BLEAdapterEvent; use crate::{ ble::{BLEConnectionManager, BLEDeviceDescriptor}, btaddr::BluetoothAdrr, @@ -18,7 +23,6 @@ use crate::{ error::SoundcoreLibResult, types::{KnownProductCodes, SOUNDCORE_NAME_PRODUCT_CODE_MAP}, }; -use crate::ble::BLEAdapterEvent; // TODO: Specify clippy & fmt features #[allow(unused_imports)] #[cfg(all(feature = "btleplug-backend", not(feature = "mock")))] diff --git a/soundcore-lib/src/devices/a3028/features.rs b/soundcore-lib/src/devices/a3028/features.rs index 28ef37e..7b966da 100644 --- a/soundcore-lib/src/devices/a3028/features.rs +++ b/soundcore-lib/src/devices/a3028/features.rs @@ -10,7 +10,7 @@ pub fn a3028_features() -> DeviceFeatureSet { equalizer_features: Some(EqualizerFeatures { bands: 8, channels: 1, - has_bass_up: false + has_bass_up: false, }), flags: Arc::new([]), } diff --git a/soundcore-lib/src/devices/a3029/features.rs b/soundcore-lib/src/devices/a3029/features.rs index bac639f..4249fe5 100644 --- a/soundcore-lib/src/devices/a3029/features.rs +++ b/soundcore-lib/src/devices/a3029/features.rs @@ -10,7 +10,7 @@ pub fn a3029_features() -> DeviceFeatureSet { equalizer_features: Some(EqualizerFeatures { bands: 8, channels: 1, - has_bass_up: false + has_bass_up: false, }), flags: Arc::new([]), } diff --git a/soundcore-lib/src/devices/a3040/bass_up_command.rs b/soundcore-lib/src/devices/a3040/bass_up_command.rs index 767944e..d435f28 100644 --- a/soundcore-lib/src/devices/a3040/bass_up_command.rs +++ b/soundcore-lib/src/devices/a3040/bass_up_command.rs @@ -27,12 +27,18 @@ mod tests { #[test] pub fn enable_bass_up() { let command = super::A3040BassUpCommand::new(true); - assert_eq!(command.bytes(), test_data::a3040::BASS_UP_UPDATE_ENABLE.to_vec()); + assert_eq!( + command.bytes(), + test_data::a3040::BASS_UP_UPDATE_ENABLE.to_vec() + ); } #[test] pub fn disable_bass_up() { let command = super::A3040BassUpCommand::new(false); - assert_eq!(command.bytes(), test_data::a3040::BASS_UP_UPDATE_DISABLE.to_vec()); + assert_eq!( + command.bytes(), + test_data::a3040::BASS_UP_UPDATE_DISABLE.to_vec() + ); } } diff --git a/soundcore-lib/src/devices/a3040/eq_info_update.rs b/soundcore-lib/src/devices/a3040/eq_info_update.rs index fee06fc..65f75f3 100644 --- a/soundcore-lib/src/devices/a3040/eq_info_update.rs +++ b/soundcore-lib/src/devices/a3040/eq_info_update.rs @@ -13,8 +13,7 @@ pub fn parse_a3040_eq_info_update<'a, E: ParseError<'a>>( context( "parse_a3040_eq_info_update", map(tuple((le_u8, le_u8)), |(b1, b2)| { - let eq_idx = (b1 as u16) - | ((b2 as u16) << 8).clamp(0, EQProfile::COUNT as u16); + let eq_idx = (b1 as u16) | ((b2 as u16) << 8).clamp(0, EQProfile::COUNT as u16); match EQProfile::from_id_le(eq_idx) { Some(eq) => eq, None => { diff --git a/soundcore-lib/src/devices/a3040/eq_update_command.rs b/soundcore-lib/src/devices/a3040/eq_update_command.rs index 40a5b87..2bbad32 100644 --- a/soundcore-lib/src/devices/a3040/eq_update_command.rs +++ b/soundcore-lib/src/devices/a3040/eq_update_command.rs @@ -30,7 +30,6 @@ impl Packet for A3040EqUpdateCommand { return vec![0x01]; } - // 2 bytes profile - FEFE - Custom let profile_bytes = [ self.eq_configuration.profile.id() as u8, @@ -106,7 +105,9 @@ mod tests { eq: EQProfile::Acoustic.eq(), }; let command = A3040EqUpdateCommand::new(EQConfiguration::Mono(eq_configuration)); - assert_eq!(test_data::a3040::SET_EQ_ACOUSTIC_NO_HEAR_ID.to_vec(), command.bytes()); + assert_eq!( + test_data::a3040::SET_EQ_ACOUSTIC_NO_HEAR_ID.to_vec(), + command.bytes() + ); } - } diff --git a/soundcore-lib/src/devices/a3951.rs b/soundcore-lib/src/devices/a3951.rs index 9a00330..b6d83cf 100644 --- a/soundcore-lib/src/devices/a3951.rs +++ b/soundcore-lib/src/devices/a3951.rs @@ -1,7 +1,7 @@ +mod eq_update_command; mod features; mod sound_mode_update_command; -mod eq_update_command; +pub use eq_update_command::*; pub use features::*; pub use sound_mode_update_command::*; -pub use eq_update_command::*; \ No newline at end of file diff --git a/soundcore-lib/src/devices/a3951/eq_update_command.rs b/soundcore-lib/src/devices/a3951/eq_update_command.rs index 759d03e..2f3230d 100644 --- a/soundcore-lib/src/devices/a3951/eq_update_command.rs +++ b/soundcore-lib/src/devices/a3951/eq_update_command.rs @@ -1,5 +1,5 @@ use crate::{ - models::{CustomHearID, EQConfiguration, HearID, StereoEQConfiguration}, + models::{CustomHearID, EQConfiguration, StereoEQConfiguration}, packets::Packet, }; @@ -9,8 +9,7 @@ pub struct A3951EqUpdateCommand { } impl A3951EqUpdateCommand { - const DEFAULT_HEAR_ID_EQ: [u8; 8] = - [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]; + const DEFAULT_HEAR_ID_EQ: [u8; 8] = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]; pub fn new(eq_configuration: EQConfiguration) -> Self { Self { eq_configuration: eq_configuration.into(), @@ -88,7 +87,6 @@ impl Packet for A3951EqUpdateCommand { } } - #[cfg(test)] mod tests { use crate::models::EQProfile; @@ -100,6 +98,9 @@ mod tests { fn test_deep_eq_update_command() { let eq_configuration = EQConfiguration::stereo_with_profile(EQProfile::Deep); let command = A3951EqUpdateCommand::new(eq_configuration); - assert_eq!(test_data::a3951::A3951_EQ_UPDATE_DEEP_NO_HEAR_ID.to_vec(), command.bytes()); + assert_eq!( + test_data::a3951::A3951_EQ_UPDATE_DEEP_NO_HEAR_ID.to_vec(), + command.bytes() + ); } -} \ No newline at end of file +} diff --git a/soundcore-lib/src/devices/a3951/features.rs b/soundcore-lib/src/devices/a3951/features.rs index b052e6f..c2208ce 100644 --- a/soundcore-lib/src/devices/a3951/features.rs +++ b/soundcore-lib/src/devices/a3951/features.rs @@ -10,7 +10,7 @@ pub fn a3951_features() -> DeviceFeatureSet { equalizer_features: Some(EqualizerFeatures { bands: 8, channels: 2, - has_bass_up: false + has_bass_up: false, }), flags: Arc::new([ FeatureFlags::CUSTOM_BUTTONS, diff --git a/soundcore-lib/src/mocks/connection.rs b/soundcore-lib/src/mocks/connection.rs index 8598db8..277d5ae 100644 --- a/soundcore-lib/src/mocks/connection.rs +++ b/soundcore-lib/src/mocks/connection.rs @@ -2,11 +2,11 @@ use std::str::FromStr; use tokio::sync::Mutex; +use crate::btaddr::BluetoothAdrr; use crate::{ ble::{BLEConnection, BLEDeviceDescriptor, WriteType}, error::SoundcoreLibResult, }; -use crate::btaddr::BluetoothAdrr; pub struct MockBLEConnection { read_channel_loop: Mutex>>>, diff --git a/soundcore-lib/src/models/eq.rs b/soundcore-lib/src/models/eq.rs index e09ed80..a33163d 100644 --- a/soundcore-lib/src/models/eq.rs +++ b/soundcore-lib/src/models/eq.rs @@ -1,4 +1,3 @@ -use log::trace; use serde::{Deserialize, Serialize}; use typeshare::typeshare; @@ -115,7 +114,7 @@ impl MonoEQ { fn calculate_drc_adjustments(values: Vec) -> Vec { // Input floats should be in the range ((MIN_FLOAT - MIN_FLOAT) - (MAX_FLOAT - MIN_FLOAT)) and length >= 8 assert!(values.len() >= 8); - assert!(values.iter().all(|&v| v >= (-6.0) && v <= 6.0)); + assert!(values.iter().all(|&v| ((-6.0)..=6.0).contains(&v))); // f64s is required to match the original implementation let d = values[0] as f64; @@ -135,8 +134,7 @@ impl MonoEQ { let d15 = d4 * 0.81f64 * d3; let d16 = d9 * 0.81f64 * d3; - vec![ - (d11 - (0.00217f64 * d12)) as f32, + [(d11 - (0.00217f64 * d12)) as f32, (((((((d13 + ((d2 * 1.73f64) * d14)) - d15) + (d6 * 0.204f64)) - (d7 * 0.068f64)) + (d9 * 0.045f64)) - (d10 * 0.0235f64)) @@ -175,8 +173,7 @@ impl MonoEQ { - ((d10 * 0.71f64) * d3)) + (d12 * 1.5f64)) as f32, 0f32, - -120f32, - ] + -120f32] .iter() .map(|v| v / 10.0) .collect() @@ -220,13 +217,13 @@ mod eq_model { // Extracted values from the original implementation let expected_post_drc_floats = vec![ - 1.19351225, + 1.193_512_2, -1.61997, - 1.23241205, + 1.232_412_1, -1.0682, 0.9448091, -0.735985, - 0.58319497, + 0.583_195, -0.13796605, 0.0, -12.0, diff --git a/soundcore-lib/src/packets/command.rs b/soundcore-lib/src/packets/command.rs index 36d4e6e..ffb7635 100644 --- a/soundcore-lib/src/packets/command.rs +++ b/soundcore-lib/src/packets/command.rs @@ -5,4 +5,3 @@ pub use sound_mode::*; mod bass_up; mod eq; mod sound_mode; - diff --git a/test_data/src/lib.rs b/test_data/src/lib.rs index 493f693..21e2947 100644 --- a/test_data/src/lib.rs +++ b/test_data/src/lib.rs @@ -1,3 +1,3 @@ -pub mod a3951; pub mod a3040; pub mod a3947; +pub mod a3951;