Skip to content

Commit

Permalink
chore: clippy & fmt fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gmallios committed Jul 15, 2024
1 parent dffa4ba commit e4d0d1e
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 52 deletions.
2 changes: 1 addition & 1 deletion manager-app/src/async_bridge/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion manager-fut/src/wasm.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
8 changes: 6 additions & 2 deletions manager-wasm/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Receiver<Vec<u8>>> {
Expand Down
2 changes: 1 addition & 1 deletion soundcore-lib/src/ble/btleplug/connection.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion soundcore-lib/src/ble/characteristic_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod resolver;

pub use resolver::*;
pub use resolver::*;
8 changes: 1 addition & 7 deletions soundcore-lib/src/btaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}
Expand Down Expand Up @@ -110,13 +111,6 @@ impl From<BluetoothAdrr> 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 {
Expand Down
8 changes: 2 additions & 6 deletions soundcore-lib/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions soundcore-lib/src/device_manager.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
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;
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,
device::SoundcoreBLEDevice,
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")))]
Expand Down
2 changes: 1 addition & 1 deletion soundcore-lib/src/devices/a3028/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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([]),
}
Expand Down
2 changes: 1 addition & 1 deletion soundcore-lib/src/devices/a3029/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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([]),
}
Expand Down
10 changes: 8 additions & 2 deletions soundcore-lib/src/devices/a3040/bass_up_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
3 changes: 1 addition & 2 deletions soundcore-lib/src/devices/a3040/eq_info_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
7 changes: 4 additions & 3 deletions soundcore-lib/src/devices/a3040/eq_update_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
);
}

}
4 changes: 2 additions & 2 deletions soundcore-lib/src/devices/a3951.rs
Original file line number Diff line number Diff line change
@@ -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::*;
13 changes: 7 additions & 6 deletions soundcore-lib/src/devices/a3951/eq_update_command.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
models::{CustomHearID, EQConfiguration, HearID, StereoEQConfiguration},
models::{CustomHearID, EQConfiguration, StereoEQConfiguration},
packets::Packet,
};

Expand All @@ -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(),
Expand Down Expand Up @@ -88,7 +87,6 @@ impl Packet for A3951EqUpdateCommand {
}
}


#[cfg(test)]
mod tests {
use crate::models::EQProfile;
Expand All @@ -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()
);
}
}
}
2 changes: 1 addition & 1 deletion soundcore-lib/src/devices/a3951/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion soundcore-lib/src/mocks/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<tokio::sync::mpsc::Receiver<Vec<u8>>>>,
Expand Down
15 changes: 6 additions & 9 deletions soundcore-lib/src/models/eq.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use log::trace;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;

Expand Down Expand Up @@ -115,7 +114,7 @@ impl MonoEQ {
fn calculate_drc_adjustments(values: Vec<f32>) -> Vec<f32> {
// 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;
Expand All @@ -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))
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion soundcore-lib/src/packets/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ pub use sound_mode::*;
mod bass_up;
mod eq;
mod sound_mode;

2 changes: 1 addition & 1 deletion test_data/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod a3951;
pub mod a3040;
pub mod a3947;
pub mod a3951;

0 comments on commit e4d0d1e

Please sign in to comment.