diff --git a/manager-app/src/async_bridge/bridge.rs b/manager-app/src/async_bridge/bridge.rs index fa6b385..e158940 100644 --- a/manager-app/src/async_bridge/bridge.rs +++ b/manager-app/src/async_bridge/bridge.rs @@ -1,10 +1,9 @@ use std::sync::Arc; use log::{debug, info, trace}; -use tauri::AppHandle; + use tokio::sync::{mpsc, Mutex}; -use soundcore_lib::device::SoundcoreBLEDevice; use soundcore_lib::{ ble::BLEConnectionManager, device_manager::{create_device_manager, DeviceManager}, @@ -138,7 +137,7 @@ async fn handle_command( .manager .get_device(payload.addr) .await; - + if let Some(device) = device { trace!("Setting sound mode for {:?}", addr_clone); let res = device.set_sound_mode(payload.sound_mode).await; diff --git a/manager-app/src/main.rs b/manager-app/src/main.rs index 6cd4dca..7fe9ae0 100644 --- a/manager-app/src/main.rs +++ b/manager-app/src/main.rs @@ -6,11 +6,11 @@ use std::collections::HashMap; use std::sync::Arc; -use log::{info, trace}; +use log::trace; use mpsc::channel; use soundcore_lib::api::SoundcoreDeviceState; use soundcore_lib::btaddr::BluetoothAdrr; -use tauri::api::notification::Notification; + use tauri::async_runtime::{Mutex, RwLock}; use tauri::{AppHandle, Manager}; use tauri_plugin_log::LogTarget; @@ -140,12 +140,10 @@ async fn send_bridge_command( fn handle_state_update( last_state: Option, new_state: SoundcoreDeviceState, - app_handle: AppHandle, + _app_handle: AppHandle, ) { if let Some(last_state) = last_state { - if last_state == new_state { - return; - } + if last_state == new_state {} // This is a bit too verbose for now // TODO: Add a setting to enable/disable this // TODO: Improve the notification message based on the values changed diff --git a/soundcore-lib/src/api.rs b/soundcore-lib/src/api.rs index bb08533..9ecb03c 100644 --- a/soundcore-lib/src/api.rs +++ b/soundcore-lib/src/api.rs @@ -1,5 +1,5 @@ -mod state; mod feature_set; +mod state; +pub use feature_set::*; pub use state::*; -pub use feature_set::*; \ No newline at end of file diff --git a/soundcore-lib/src/api/feature_set.rs b/soundcore-lib/src/api/feature_set.rs index 47c6575..d1db31e 100644 --- a/soundcore-lib/src/api/feature_set.rs +++ b/soundcore-lib/src/api/feature_set.rs @@ -3,13 +3,13 @@ use std::sync::Arc; use serde::{Deserialize, Serialize}; use typeshare::typeshare; +mod equalizer_features; mod flags; mod sound_mode_features; -mod equalizer_features; +pub use equalizer_features::*; pub use flags::*; pub use sound_mode_features::*; -pub use equalizer_features::*; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Hash)] #[typeshare] @@ -28,4 +28,4 @@ impl Default for DeviceFeatureSet { flags: Arc::new([]), } } -} \ No newline at end of file +} diff --git a/soundcore-lib/src/api/feature_set/equalizer_features.rs b/soundcore-lib/src/api/feature_set/equalizer_features.rs index 3cd6e32..31f1f3b 100644 --- a/soundcore-lib/src/api/feature_set/equalizer_features.rs +++ b/soundcore-lib/src/api/feature_set/equalizer_features.rs @@ -1,11 +1,9 @@ use serde::{Deserialize, Serialize}; use typeshare::typeshare; -#[derive( - Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, -)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash)] #[typeshare] pub struct EqualizerFeatures { pub bands: u8, pub channels: u8, -} \ No newline at end of file +} diff --git a/soundcore-lib/src/api/state/state.rs b/soundcore-lib/src/api/state/state.rs index 93509ae..bd86897 100644 --- a/soundcore-lib/src/api/state/state.rs +++ b/soundcore-lib/src/api/state/state.rs @@ -1,7 +1,13 @@ use serde::{Deserialize, Serialize}; use typeshare::typeshare; -use crate::{api::DeviceFeatureSet, models::{AgeRange, Battery, ButtonModel, CustomHearID, EQConfiguration, FirmwareVer, HearID, SerialNumber, SideTone, SoundMode, SoundcoreFeatureFlags, TwsStatus, WearDetection}}; +use crate::{ + api::DeviceFeatureSet, + models::{ + AgeRange, Battery, ButtonModel, EQConfiguration, FirmwareVer, HearID, SerialNumber, + SideTone, SoundMode, TwsStatus, WearDetection, + }, +}; /// This is a generalized version of the state for all devices #[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone, Hash, Default)] @@ -23,4 +29,3 @@ pub struct SoundcoreDeviceState { pub hear_id: Option, pub age_range: Option, } - diff --git a/soundcore-lib/src/ble.rs b/soundcore-lib/src/ble.rs index 4636438..3077645 100644 --- a/soundcore-lib/src/ble.rs +++ b/soundcore-lib/src/ble.rs @@ -32,7 +32,9 @@ pub trait BLEConnectionManager { uuid_set: Option, ) -> SoundcoreLibResult>; - async fn adapter_events(&self) -> SoundcoreLibResult>; + async fn adapter_events( + &self, + ) -> SoundcoreLibResult>; } #[derive(Debug, Serialize, Deserialize, Clone)] @@ -43,7 +45,6 @@ pub enum BLEAdapterEvent { DeviceDisconnected(BluetoothAdrr), } - #[async_trait] pub trait BLEConnection { fn descriptor(&self) -> BLEDeviceDescriptor; @@ -112,7 +113,6 @@ pub struct BLEConnectionUuidSet { pub write_uuid: uuid::Uuid, } - #[cfg(all(target_os = "windows", feature = "winrt-backend"))] impl From for ::windows::Devices::Bluetooth::GenericAttributeProfile::GattWriteOption { fn from(val: WriteType) -> Self { @@ -122,5 +122,3 @@ impl From for ::windows::Devices::Bluetooth::GenericAttributeProfile: } } } - - diff --git a/soundcore-lib/src/ble/btleplug/connection.rs b/soundcore-lib/src/ble/btleplug/connection.rs index 1191bf3..3ef3a21 100644 --- a/soundcore-lib/src/ble/btleplug/connection.rs +++ b/soundcore-lib/src/ble/btleplug/connection.rs @@ -173,7 +173,11 @@ impl BLEConnection for BtlePlugConnection { self.write_characteristic.clone(), bytes.to_owned(), ); - trace!("Writing bytes: {:#X?} to characteristic: {:?}", bytes, self.write_characteristic); + trace!( + "Writing bytes: {:#X?} to characteristic: {:?}", + bytes, + self.write_characteristic + ); tokio::spawn(async move { peripheral .write(&writer_characteristic, &bytes, write_type.into()) diff --git a/soundcore-lib/src/ble/btleplug/connection_factory.rs b/soundcore-lib/src/ble/btleplug/connection_factory.rs index 45543ee..9097cb4 100644 --- a/soundcore-lib/src/ble/btleplug/connection_factory.rs +++ b/soundcore-lib/src/ble/btleplug/connection_factory.rs @@ -1,5 +1,5 @@ use async_trait::async_trait; -use btleplug::api::{Central, Manager as _, Peripheral as _}; +use btleplug::api::{Central, Peripheral as _}; use btleplug::platform::{Adapter, Manager, Peripheral}; use crate::ble::{BLEConnectionFactory, BLEDeviceDescriptor}; diff --git a/soundcore-lib/src/ble/btleplug/manager.rs b/soundcore-lib/src/ble/btleplug/manager.rs index 5d0ac34..ce30984 100644 --- a/soundcore-lib/src/ble/btleplug/manager.rs +++ b/soundcore-lib/src/ble/btleplug/manager.rs @@ -15,8 +15,8 @@ use weak_table::WeakValueHashMap; use crate::ble::btleplug::connection::BtlePlugConnection; use crate::ble::{ - BLEConnectionFactory, BLEConnectionManager, BLEConnectionUuidSet, BLEDeviceDescriptor, - BLEAdapterEvent, BLEDeviceScanner, + BLEAdapterEvent, BLEConnectionFactory, BLEConnectionManager, BLEConnectionUuidSet, + BLEDeviceDescriptor, BLEDeviceScanner, }; use crate::btaddr::BluetoothAdrr; use crate::error::{SoundcoreLibError, SoundcoreLibResult}; @@ -107,7 +107,7 @@ impl BLEConnectionManager for BtlePlugBLEManager { let mut adapter_events = adapter.events().await.unwrap(); tokio::spawn(async move { while let Some(evt) = adapter_events.next().await { - let event: Option = evt.try_into().ok(); + let event: Option = evt.try_into().ok(); if let Some(event) = event { tx_clone.send(event).await.unwrap(); } @@ -118,18 +118,21 @@ impl BLEConnectionManager for BtlePlugBLEManager { } } - impl TryInto for CentralEvent { type Error = SoundcoreLibError; fn try_into(self) -> Result { match self { - CentralEvent::DeviceDisconnected(id) => Ok(BLEAdapterEvent::DeviceDisconnected(id.try_into()?)), - CentralEvent::DeviceConnected(id) => Ok(BLEAdapterEvent::DeviceConnected(id.try_into()?)), + CentralEvent::DeviceDisconnected(id) => { + Ok(BLEAdapterEvent::DeviceDisconnected(id.try_into()?)) + } + CentralEvent::DeviceConnected(id) => { + Ok(BLEAdapterEvent::DeviceConnected(id.try_into()?)) + } _ => { warn!("Unhandled CentralEvent: {:?}", self); Err(SoundcoreLibError::Unknown) } } } -} \ No newline at end of file +} diff --git a/soundcore-lib/src/ble/windows/scanner.rs b/soundcore-lib/src/ble/windows/scanner.rs index 6733bf6..99c7ad7 100644 --- a/soundcore-lib/src/ble/windows/scanner.rs +++ b/soundcore-lib/src/ble/windows/scanner.rs @@ -1,5 +1,5 @@ use collections::HashMap; -use std::{collections, sync}; +use std::{collections, sync, time::Duration}; use sync::{Arc, Mutex}; use async_trait::async_trait; @@ -64,7 +64,7 @@ impl WindowsBLEDeviceScanner { impl BLEDeviceScanner for WindowsBLEDeviceScanner { // type Descriptor = WindowsBLEDescriptor; - async fn scan(&self) -> SoundcoreLibResult> { + async fn scan(&self, duration: Option) -> SoundcoreLibResult> { spawn_blocking(move || { let addr_swap_map = Arc::new(Mutex::new(HashMap::::new())); diff --git a/soundcore-lib/src/device.rs b/soundcore-lib/src/device.rs index 41fa4b5..329d214 100644 --- a/soundcore-lib/src/device.rs +++ b/soundcore-lib/src/device.rs @@ -11,8 +11,8 @@ use crate::ble::{BLEConnection, WriteType}; use crate::error::{SoundcoreLibError, SoundcoreLibResult}; use crate::models::{EQConfiguration, SoundMode}; use crate::packets::{ - DeviceStateResponse, RequestPacketBuilder, RequestPacketKind, ResponsePacket, - SoundModeCommandBuilder, StateTransformationPacket, + RequestPacketBuilder, RequestPacketKind, ResponsePacket, SoundModeCommandBuilder, + StateTransformationPacket, }; use crate::parsers::TaggedData; use crate::types::SupportedModels; @@ -187,11 +187,11 @@ where let mut new_state = state_sender.borrow().clone(); new_state.sound_mode = sound_mode; state_sender.send_replace(new_state); - + Ok(()) } - pub async fn set_eq(&self, eq: EQConfiguration) -> SoundcoreLibResult<()> { + pub async fn set_eq(&self, _eq: EQConfiguration) -> SoundcoreLibResult<()> { todo!() } } diff --git a/soundcore-lib/src/device_manager.rs b/soundcore-lib/src/device_manager.rs index 9b4fc35..0cb4d48 100644 --- a/soundcore-lib/src/device_manager.rs +++ b/soundcore-lib/src/device_manager.rs @@ -2,7 +2,6 @@ use std::collections::hash_map::Entry; use std::collections::HashMap; use std::{sync::Arc, time::Duration}; -use crate::ble::btleplug::manager::BtlePlugBLEManager; use crate::ble::BLEAdapterEvent; #[cfg(any(test, feature = "mock"))] use crate::mocks::*; @@ -17,6 +16,10 @@ use serde::{Deserialize, Serialize}; use tokio::sync::RwLock; use typeshare::typeshare; +// TODO: Specify clippy & fmt features +#[allow(unused_imports)] +use crate::ble::btleplug::manager::BtlePlugBLEManager; + pub struct DeviceManager where B: BLEConnectionManager, @@ -57,7 +60,10 @@ where } } - pub async fn get_device(&self, addr: BluetoothAdrr) -> Option>> { + pub async fn get_device( + &self, + addr: BluetoothAdrr, + ) -> Option>> { self.ble_devices.read().await.get(&addr).cloned() } diff --git a/soundcore-lib/src/devices/a3027.rs b/soundcore-lib/src/devices/a3027.rs index 02c6244..b71c465 100644 --- a/soundcore-lib/src/devices/a3027.rs +++ b/soundcore-lib/src/devices/a3027.rs @@ -1,3 +1,3 @@ mod features; -pub use features::*; \ No newline at end of file +pub use features::*; diff --git a/soundcore-lib/src/devices/a3027/features.rs b/soundcore-lib/src/devices/a3027/features.rs index df4adaa..f420861 100644 --- a/soundcore-lib/src/devices/a3027/features.rs +++ b/soundcore-lib/src/devices/a3027/features.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use crate::api::{DeviceFeatureSet, EqualizerFeatures, FeatureFlags, SoundModeFeatures}; +use crate::api::{DeviceFeatureSet, EqualizerFeatures, SoundModeFeatures}; pub fn a3027_features() -> DeviceFeatureSet { DeviceFeatureSet { diff --git a/soundcore-lib/src/devices/a3028.rs b/soundcore-lib/src/devices/a3028.rs index 02c6244..b71c465 100644 --- a/soundcore-lib/src/devices/a3028.rs +++ b/soundcore-lib/src/devices/a3028.rs @@ -1,3 +1,3 @@ mod features; -pub use features::*; \ No newline at end of file +pub use features::*; diff --git a/soundcore-lib/src/devices/a3028/features.rs b/soundcore-lib/src/devices/a3028/features.rs index 41720d2..e423369 100644 --- a/soundcore-lib/src/devices/a3028/features.rs +++ b/soundcore-lib/src/devices/a3028/features.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use crate::api::{DeviceFeatureSet, EqualizerFeatures, FeatureFlags, SoundModeFeatures}; +use crate::api::{DeviceFeatureSet, EqualizerFeatures, SoundModeFeatures}; pub fn a3028_features() -> DeviceFeatureSet { DeviceFeatureSet { diff --git a/soundcore-lib/src/devices/a3029.rs b/soundcore-lib/src/devices/a3029.rs index 02c6244..b71c465 100644 --- a/soundcore-lib/src/devices/a3029.rs +++ b/soundcore-lib/src/devices/a3029.rs @@ -1,3 +1,3 @@ mod features; -pub use features::*; \ No newline at end of file +pub use features::*; diff --git a/soundcore-lib/src/devices/a3029/features.rs b/soundcore-lib/src/devices/a3029/features.rs index 2b11461..a233fcc 100644 --- a/soundcore-lib/src/devices/a3029/features.rs +++ b/soundcore-lib/src/devices/a3029/features.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use crate::api::{DeviceFeatureSet, EqualizerFeatures, FeatureFlags, SoundModeFeatures}; +use crate::api::{DeviceFeatureSet, EqualizerFeatures, SoundModeFeatures}; pub fn a3029_features() -> DeviceFeatureSet { DeviceFeatureSet { diff --git a/soundcore-lib/src/devices/a3040.rs b/soundcore-lib/src/devices/a3040.rs index aba382c..d8f180e 100644 --- a/soundcore-lib/src/devices/a3040.rs +++ b/soundcore-lib/src/devices/a3040.rs @@ -2,4 +2,4 @@ mod features; mod sound_mode_update_command; pub use features::*; -pub use sound_mode_update_command::*; \ No newline at end of file +pub use sound_mode_update_command::*; diff --git a/soundcore-lib/src/devices/a3930.rs b/soundcore-lib/src/devices/a3930.rs index 02c6244..b71c465 100644 --- a/soundcore-lib/src/devices/a3930.rs +++ b/soundcore-lib/src/devices/a3930.rs @@ -1,3 +1,3 @@ mod features; -pub use features::*; \ No newline at end of file +pub use features::*; diff --git a/soundcore-lib/src/devices/a3930/features.rs b/soundcore-lib/src/devices/a3930/features.rs index 8891ce0..5805a7c 100644 --- a/soundcore-lib/src/devices/a3930/features.rs +++ b/soundcore-lib/src/devices/a3930/features.rs @@ -1,13 +1,11 @@ use std::sync::Arc; -use crate::api::{DeviceFeatureSet, EqualizerFeatures, FeatureFlags, SoundModeFeatures}; +use crate::api::{DeviceFeatureSet, EqualizerFeatures, SoundModeFeatures}; pub fn a3930_features() -> DeviceFeatureSet { DeviceFeatureSet { // A3030 Seems to have no sound modes - sound_mode_features: Some( - SoundModeFeatures::new(&[], &[], true), - ), + sound_mode_features: Some(SoundModeFeatures::new(&[], &[], true)), equalizer_features: Some(EqualizerFeatures { bands: 8, channels: 1, diff --git a/soundcore-lib/src/devices/a3951.rs b/soundcore-lib/src/devices/a3951.rs index 02c6244..b71c465 100644 --- a/soundcore-lib/src/devices/a3951.rs +++ b/soundcore-lib/src/devices/a3951.rs @@ -1,3 +1,3 @@ mod features; -pub use features::*; \ No newline at end of file +pub use features::*; diff --git a/soundcore-lib/src/devices/a3951/features.rs b/soundcore-lib/src/devices/a3951/features.rs index fac2253..e4f5218 100644 --- a/soundcore-lib/src/devices/a3951/features.rs +++ b/soundcore-lib/src/devices/a3951/features.rs @@ -19,4 +19,4 @@ pub fn a3951_features() -> DeviceFeatureSet { FeatureFlags::WEAR_DETECTION, ]), } -} \ No newline at end of file +} diff --git a/soundcore-lib/src/mocks.rs b/soundcore-lib/src/mocks.rs index b956311..0f10f94 100644 --- a/soundcore-lib/src/mocks.rs +++ b/soundcore-lib/src/mocks.rs @@ -3,8 +3,7 @@ mod connection_factory; mod connection_manager; mod scanner; - pub use connection::*; pub use connection_factory::*; pub use connection_manager::*; -pub use scanner::*; \ No newline at end of file +pub use scanner::*; diff --git a/soundcore-lib/src/mocks/connection.rs b/soundcore-lib/src/mocks/connection.rs index 06ef4a3..e5f7a8c 100644 --- a/soundcore-lib/src/mocks/connection.rs +++ b/soundcore-lib/src/mocks/connection.rs @@ -13,6 +13,12 @@ pub struct MockBLEConnection { read_channel_loop: Mutex>>>, } +impl Default for MockBLEConnection { + fn default() -> Self { + Self::new() + } +} + impl MockBLEConnection { pub fn new() -> Self { MockBLEConnection { @@ -45,7 +51,7 @@ impl BLEConnection for MockBLEConnection { Ok(self.read_channel_loop.lock().await.take().unwrap()) } - async fn write(&self, bytes: &[u8], write_type: WriteType) -> SoundcoreLibResult<()> { + async fn write(&self, _bytes: &[u8], _write_type: WriteType) -> SoundcoreLibResult<()> { // TODO: Implement it, no-op for now Ok(()) } diff --git a/soundcore-lib/src/mocks/connection_factory.rs b/soundcore-lib/src/mocks/connection_factory.rs index 1abdb9e..5416d42 100644 --- a/soundcore-lib/src/mocks/connection_factory.rs +++ b/soundcore-lib/src/mocks/connection_factory.rs @@ -1,6 +1,9 @@ use async_trait::async_trait; -use crate::{ble::{BLEConnectionFactory, BLEConnectionUuidSet, BLEDeviceDescriptor}, error::SoundcoreLibResult}; +use crate::{ + ble::{BLEConnectionFactory, BLEConnectionUuidSet, BLEDeviceDescriptor}, + error::SoundcoreLibResult, +}; use super::MockBLEConnection; @@ -12,8 +15,8 @@ impl BLEConnectionFactory for MockBLEConnectionFactory { async fn connect( &self, - descriptor: BLEDeviceDescriptor, - uuid_set: Option, + _descriptor: BLEDeviceDescriptor, + _uuid_set: Option, ) -> SoundcoreLibResult { unimplemented!() } diff --git a/soundcore-lib/src/mocks/connection_manager.rs b/soundcore-lib/src/mocks/connection_manager.rs index 7a4b186..9991c1f 100644 --- a/soundcore-lib/src/mocks/connection_manager.rs +++ b/soundcore-lib/src/mocks/connection_manager.rs @@ -47,8 +47,8 @@ impl BLEConnectionManager for MockBLEConnectionManager { async fn connect( &self, - descriptor: BLEDeviceDescriptor, - uuid_set: Option, + _descriptor: BLEDeviceDescriptor, + _uuid_set: Option, ) -> SoundcoreLibResult> { let conn = MockBLEConnection::new_with_empty_channel(); Ok(Arc::new(conn)) @@ -67,4 +67,4 @@ impl Default for MockBLEConnectionManager { fn default() -> Self { Self::new() } -} \ No newline at end of file +} diff --git a/soundcore-lib/src/mocks/scanner.rs b/soundcore-lib/src/mocks/scanner.rs index b61c04f..02e6a50 100644 --- a/soundcore-lib/src/mocks/scanner.rs +++ b/soundcore-lib/src/mocks/scanner.rs @@ -2,11 +2,11 @@ use std::{str::FromStr, time::Duration}; use async_trait::async_trait; +use crate::btaddr::BluetoothAdrr; use crate::{ ble::{BLEDeviceDescriptor, BLEDeviceScanner}, error::SoundcoreLibResult, }; -use crate::btaddr::BluetoothAdrr; pub struct MockBLEScanner; @@ -14,7 +14,7 @@ pub struct MockBLEScanner; impl BLEDeviceScanner for MockBLEScanner { async fn scan( &self, - duration: Option, + _duration: Option, ) -> SoundcoreLibResult> { let descriptor = BLEDeviceDescriptor { addr: BluetoothAdrr::from_str("00:11:22:33:44:55").unwrap(), diff --git a/soundcore-lib/src/models.rs b/soundcore-lib/src/models.rs index 19270ee..b7aed14 100644 --- a/soundcore-lib/src/models.rs +++ b/soundcore-lib/src/models.rs @@ -8,6 +8,7 @@ pub use button_model::*; pub use curr_sound_mode::*; pub use custom_anc_value::*; pub use custom_trans_value::*; +pub use customizable_trans_mode::*; pub use device_color::*; pub use eq::*; pub use eq_configuration::*; @@ -18,6 +19,7 @@ pub use gender::*; pub use hearid::*; pub use hearing_protect::*; pub use misc::*; +pub use non_customizable_trans_mode::*; pub use packet_header::*; pub use packet_kind::*; pub use prompt_language::*; @@ -25,17 +27,18 @@ pub use scene_based_anc_mode::*; pub use serial::*; pub use sound_mode::*; pub use trans_mode::*; -pub use customizable_trans_mode::*; -pub use non_customizable_trans_mode::*; mod a3040_button_model; mod a3909_button_model; +mod adaptive_anc_mode; mod anc_mode; mod auto_power; mod battery; mod button_model; mod curr_sound_mode; mod custom_anc_value; +mod custom_trans_value; +mod customizable_trans_mode; mod device_color; mod eq; mod eq_configuration; @@ -46,14 +49,11 @@ mod gender; mod hearid; mod hearing_protect; mod misc; +mod non_customizable_trans_mode; mod packet_header; mod packet_kind; mod prompt_language; +mod scene_based_anc_mode; mod serial; mod sound_mode; mod trans_mode; -mod scene_based_anc_mode; -mod adaptive_anc_mode; -mod customizable_trans_mode; -mod custom_trans_value; -mod non_customizable_trans_mode; diff --git a/soundcore-lib/src/models/a3909_button_model.rs b/soundcore-lib/src/models/a3909_button_model.rs index 419b67b..4572ea9 100644 --- a/soundcore-lib/src/models/a3909_button_model.rs +++ b/soundcore-lib/src/models/a3909_button_model.rs @@ -2,7 +2,6 @@ use crate::models::Action; use serde::{Deserialize, Serialize}; use typeshare::typeshare; - /// This is the A3909 variant of the CustomBtnModel /// TODO: Check if there are common models to other button models, if so move them to a common file #[derive(Debug, Serialize, Deserialize, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] diff --git a/soundcore-lib/src/models/adaptive_anc_mode.rs b/soundcore-lib/src/models/adaptive_anc_mode.rs index 227c3c1..db3398e 100644 --- a/soundcore-lib/src/models/adaptive_anc_mode.rs +++ b/soundcore-lib/src/models/adaptive_anc_mode.rs @@ -4,19 +4,19 @@ use typeshare::typeshare; #[repr(u8)] #[derive( -Debug, -Serialize, -Deserialize, -Eq, -PartialEq, -Ord, -PartialOrd, -Clone, -Copy, -Default, -FromRepr, -Display, -Hash, + Debug, + Serialize, + Deserialize, + Eq, + PartialEq, + Ord, + PartialOrd, + Clone, + Copy, + Default, + FromRepr, + Display, + Hash, )] #[typeshare] pub enum AdaptiveANCMode { @@ -33,4 +33,4 @@ impl AdaptiveANCMode { pub fn as_u8(&self) -> u8 { *self as u8 } -} \ No newline at end of file +} diff --git a/soundcore-lib/src/models/curr_sound_mode.rs b/soundcore-lib/src/models/curr_sound_mode.rs index c59a8b0..0bfed41 100644 --- a/soundcore-lib/src/models/curr_sound_mode.rs +++ b/soundcore-lib/src/models/curr_sound_mode.rs @@ -4,19 +4,19 @@ use typeshare::typeshare; #[repr(u8)] #[derive( -Debug, -Serialize, -Deserialize, -Eq, -PartialEq, -Ord, -PartialOrd, -Clone, -Copy, -Default, -FromRepr, -Display, -Hash, + Debug, + Serialize, + Deserialize, + Eq, + PartialEq, + Ord, + PartialOrd, + Clone, + Copy, + Default, + FromRepr, + Display, + Hash, )] #[serde(rename_all = "lowercase")] #[typeshare] diff --git a/soundcore-lib/src/models/custom_anc_value.rs b/soundcore-lib/src/models/custom_anc_value.rs index 65ea679..768d5b9 100644 --- a/soundcore-lib/src/models/custom_anc_value.rs +++ b/soundcore-lib/src/models/custom_anc_value.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use typeshare::typeshare; #[derive( -Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Default, Hash, + Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Default, Hash, )] #[typeshare] pub struct CustomANCValue(pub u8); diff --git a/soundcore-lib/src/models/custom_trans_value.rs b/soundcore-lib/src/models/custom_trans_value.rs index ee0ed06..b41402f 100644 --- a/soundcore-lib/src/models/custom_trans_value.rs +++ b/soundcore-lib/src/models/custom_trans_value.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use typeshare::typeshare; #[derive( -Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Default, Hash, + Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Default, Hash, )] #[typeshare] pub struct CustomTransparencyValue(pub u8); diff --git a/soundcore-lib/src/models/customizable_trans_mode.rs b/soundcore-lib/src/models/customizable_trans_mode.rs index 1f15af5..ac6e7a1 100644 --- a/soundcore-lib/src/models/customizable_trans_mode.rs +++ b/soundcore-lib/src/models/customizable_trans_mode.rs @@ -4,19 +4,19 @@ use typeshare::typeshare; #[repr(u8)] #[derive( -Debug, -Serialize, -Deserialize, -Eq, -PartialEq, -Ord, -PartialOrd, -Clone, -Copy, -Default, -FromRepr, -Display, -Hash, + Debug, + Serialize, + Deserialize, + Eq, + PartialEq, + Ord, + PartialOrd, + Clone, + Copy, + Default, + FromRepr, + Display, + Hash, )] #[serde(rename_all = "camelCase")] #[typeshare] @@ -34,4 +34,4 @@ impl CustomizableTransparencyMode { pub fn from_u8(value: u8) -> Option { Self::from_repr(value) } -} \ No newline at end of file +} diff --git a/soundcore-lib/src/models/device_color.rs b/soundcore-lib/src/models/device_color.rs index ba82b96..12ff1a9 100644 --- a/soundcore-lib/src/models/device_color.rs +++ b/soundcore-lib/src/models/device_color.rs @@ -1,5 +1,5 @@ -use serde::{Serialize, Deserialize}; use derive_more::From; +use serde::{Deserialize, Serialize}; /// This u8 is a char which based on it fetches the apropriate image for the device (Reference: OtaBaseActivity/renderProductIcon). /// Perhaps this can be internally mapped to our product images. @@ -7,4 +7,4 @@ use derive_more::From; #[derive( Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Default, Hash, From, )] -pub struct DeviceColor(pub u8); \ No newline at end of file +pub struct DeviceColor(pub u8); diff --git a/soundcore-lib/src/models/eq.rs b/soundcore-lib/src/models/eq.rs index fd5dc43..0fb5444 100644 --- a/soundcore-lib/src/models/eq.rs +++ b/soundcore-lib/src/models/eq.rs @@ -32,9 +32,12 @@ impl MonoEQ { } } - pub fn to_bytes(&self, bands: usize) -> Vec { - self.values.iter().take(bands).map(|&v| Self::to_byte(&v)).collect() + self.values + .iter() + .take(bands) + .map(|&v| Self::to_byte(&v)) + .collect() } pub fn from_signed_bytes(bytes: Vec) -> Self { @@ -75,10 +78,11 @@ impl MonoEQ { (value * 10.0).clamp(Self::MIN_FLOAT, Self::MAX_FLOAT) as u8 } - /* Input should be clamped to -120..=120 then converted to the range 0..=240 */ fn from_signed(value: &i8) -> u8 { - value.clamp(&Self::MIN_SIGNED, &Self::MAX_SIGNED).wrapping_add(Self::MIN_SIGNED.abs()) as u8 + value + .clamp(&Self::MIN_SIGNED, &Self::MAX_SIGNED) + .wrapping_add(Self::MIN_SIGNED.abs()) as u8 } fn to_signed(value: u8) -> i8 { @@ -86,14 +90,16 @@ impl MonoEQ { } } - #[cfg(test)] mod eq_model { #[test] fn from_signed_check() { - let signed_values = vec![-120, -100, -80, -60, -40, -20, 0, 20, 40, 60, 80, 100, 120]; + let signed_values = [-120, -100, -80, -60, -40, -20, 0, 20, 40, 60, 80, 100, 120]; let expected_values = vec![0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240]; - let actual_values: Vec = signed_values.iter().map(super::MonoEQ::from_signed).collect(); + let actual_values: Vec = signed_values + .iter() + .map(super::MonoEQ::from_signed) + .collect(); assert_eq!(expected_values, actual_values); } -} \ No newline at end of file +} diff --git a/soundcore-lib/src/models/feature_flags.rs b/soundcore-lib/src/models/feature_flags.rs index 0acdea3..d782760 100644 --- a/soundcore-lib/src/models/feature_flags.rs +++ b/soundcore-lib/src/models/feature_flags.rs @@ -31,5 +31,5 @@ pub enum SoundcoreFeatureFlags { AMBIENT_SOUND_NOTICE, POWER_ON_BATTERY_NOTICE, SUPPORT_TWO_CONNECTIONS, - MULTIPLE_DEVICE_LIST + MULTIPLE_DEVICE_LIST, } diff --git a/soundcore-lib/src/models/hearing_protect.rs b/soundcore-lib/src/models/hearing_protect.rs index c184402..bd154ae 100644 --- a/soundcore-lib/src/models/hearing_protect.rs +++ b/soundcore-lib/src/models/hearing_protect.rs @@ -1,5 +1,5 @@ -use serde::{Serialize, Deserialize}; use derive_more::From; +use serde::{Deserialize, Serialize}; #[derive( Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Default, Hash, From, @@ -8,4 +8,4 @@ pub struct HearingProtect { pub enabled: bool, pub db: u8, pub freq: u8, -} \ No newline at end of file +} diff --git a/soundcore-lib/src/models/non_customizable_trans_mode.rs b/soundcore-lib/src/models/non_customizable_trans_mode.rs index 88fe84a..ad0fc9e 100644 --- a/soundcore-lib/src/models/non_customizable_trans_mode.rs +++ b/soundcore-lib/src/models/non_customizable_trans_mode.rs @@ -1,23 +1,22 @@ -use log::trace; use serde::{Deserialize, Serialize}; use strum::{Display, FromRepr}; use typeshare::typeshare; #[repr(u8)] #[derive( -Debug, -Serialize, -Deserialize, -Eq, -PartialEq, -Ord, -PartialOrd, -Clone, -Copy, -Default, -FromRepr, -Display, -Hash, + Debug, + Serialize, + Deserialize, + Eq, + PartialEq, + Ord, + PartialOrd, + Clone, + Copy, + Default, + FromRepr, + Display, + Hash, )] #[serde(rename_all = "camelCase")] #[typeshare] @@ -35,4 +34,4 @@ impl NonCustomizableTransparencyMode { pub fn from_u8(value: u8) -> Option { Self::from_repr(value) } -} \ No newline at end of file +} diff --git a/soundcore-lib/src/models/scene_based_anc_mode.rs b/soundcore-lib/src/models/scene_based_anc_mode.rs index 1afb536..5e8d3eb 100644 --- a/soundcore-lib/src/models/scene_based_anc_mode.rs +++ b/soundcore-lib/src/models/scene_based_anc_mode.rs @@ -4,19 +4,19 @@ use typeshare::typeshare; #[repr(u8)] #[derive( -Debug, -Serialize, -Deserialize, -Eq, -PartialEq, -Ord, -PartialOrd, -Clone, -Copy, -Default, -FromRepr, -Display, -Hash, + Debug, + Serialize, + Deserialize, + Eq, + PartialEq, + Ord, + PartialOrd, + Clone, + Copy, + Default, + FromRepr, + Display, + Hash, )] #[typeshare] pub enum SceneBasedANCMode { @@ -31,7 +31,7 @@ impl SceneBasedANCMode { pub fn from_u8(value: u8) -> Option { Self::from_repr(value) } - + pub fn as_u8(&self) -> u8 { *self as u8 } @@ -43,10 +43,22 @@ mod scene_based_anc_mode_tests { #[test] fn init_from_u8() { - assert_eq!(SceneBasedANCMode::from_u8(0), Some(SceneBasedANCMode::Transport)); - assert_eq!(SceneBasedANCMode::from_u8(1), Some(SceneBasedANCMode::Outdoor)); - assert_eq!(SceneBasedANCMode::from_u8(2), Some(SceneBasedANCMode::Indoor)); - assert_eq!(SceneBasedANCMode::from_u8(3), Some(SceneBasedANCMode::Custom)); + assert_eq!( + SceneBasedANCMode::from_u8(0), + Some(SceneBasedANCMode::Transport) + ); + assert_eq!( + SceneBasedANCMode::from_u8(1), + Some(SceneBasedANCMode::Outdoor) + ); + assert_eq!( + SceneBasedANCMode::from_u8(2), + Some(SceneBasedANCMode::Indoor) + ); + assert_eq!( + SceneBasedANCMode::from_u8(3), + Some(SceneBasedANCMode::Custom) + ); } #[test] @@ -61,4 +73,4 @@ mod scene_based_anc_mode_tests { assert_eq!(SceneBasedANCMode::Indoor.as_u8(), 2); assert_eq!(SceneBasedANCMode::Custom.as_u8(), 3); } -} \ No newline at end of file +} diff --git a/soundcore-lib/src/models/trans_mode.rs b/soundcore-lib/src/models/trans_mode.rs index 6bf1276..97ed876 100644 --- a/soundcore-lib/src/models/trans_mode.rs +++ b/soundcore-lib/src/models/trans_mode.rs @@ -1,4 +1,3 @@ -use log::trace; use serde::{Deserialize, Serialize}; use strum::{Display, FromRepr}; use typeshare::typeshare; diff --git a/soundcore-lib/src/packets/command.rs b/soundcore-lib/src/packets/command.rs index 117872c..59ed3fd 100644 --- a/soundcore-lib/src/packets/command.rs +++ b/soundcore-lib/src/packets/command.rs @@ -1,3 +1,3 @@ mod sound_mode; -pub use sound_mode::*; \ No newline at end of file +pub use sound_mode::*; diff --git a/soundcore-lib/src/packets/response.rs b/soundcore-lib/src/packets/response.rs index 329ea29..c6cc906 100644 --- a/soundcore-lib/src/packets/response.rs +++ b/soundcore-lib/src/packets/response.rs @@ -1,4 +1,4 @@ -use log::{error, warn}; +use log::error; use nom::error::VerboseError; pub use info::*; @@ -17,7 +17,7 @@ pub enum ResponsePacket { DeviceState(TaggedData), SoundModeUpdate(SoundModeUpdateResponse), DeviceInfo(DeviceInfoResponse), - Unknown + Unknown, } pub trait StateTransformationPacket { @@ -44,7 +44,7 @@ impl ResponsePacket { packet_header.kind, bytes ); ResponsePacket::Unknown - }, + } }) } @@ -58,7 +58,7 @@ impl ResponsePacket { ResponsePacketKind::StateUpdate => { let tagged_state_resp = parse_state_update_packet(bytes)?.1; let state = ResponsePacket::DeviceState(TaggedData { - tag: tagged_state_resp.tag.clone(), + tag: tagged_state_resp.tag, data: tagged_state_resp.data, }) .transform_state(&SoundcoreDeviceState::default()); @@ -83,7 +83,7 @@ impl StateTransformationPacket for ResponsePacket { match self { ResponsePacket::SoundModeUpdate(sound_mode_update) => { sound_mode_update.transform_state(state) - }, + } ResponsePacket::DeviceState(state_update) => state_update.data.transform_state(state), // No-op _ => state.clone(), diff --git a/soundcore-lib/src/packets/response/sound_mode.rs b/soundcore-lib/src/packets/response/sound_mode.rs index 09081cb..51deefe 100644 --- a/soundcore-lib/src/packets/response/sound_mode.rs +++ b/soundcore-lib/src/packets/response/sound_mode.rs @@ -1,12 +1,12 @@ use nom::{combinator::map, error::context}; use serde::{Deserialize, Serialize}; +use crate::api::SoundcoreDeviceState; +use crate::packets::StateTransformationPacket; use crate::{ models::SoundMode, parsers::{parse_sound_mode, ParseError, ParseResult}, }; -use crate::api::SoundcoreDeviceState; -use crate::packets::StateTransformationPacket; #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)] pub struct SoundModeUpdateResponse(pub SoundMode); diff --git a/soundcore-lib/src/packets/response/state.rs b/soundcore-lib/src/packets/response/state.rs index 156ddae..779bd46 100644 --- a/soundcore-lib/src/packets/response/state.rs +++ b/soundcore-lib/src/packets/response/state.rs @@ -1,4 +1,3 @@ -use enumflags2::BitFlags; use nom::{branch::alt, combinator::map, error::context}; use serde::{Deserialize, Serialize}; @@ -20,8 +19,8 @@ use crate::parsers::{TaggedData, TaggedParseResult}; use crate::{ api::DeviceFeatureSet, models::{ - AgeRange, Battery, ButtonModel, EQConfiguration, HearID, SideTone, SoundMode, - SoundcoreFeatureFlags, TouchTone, TwsStatus, WearDetection, + AgeRange, Battery, ButtonModel, EQConfiguration, HearID, SideTone, SoundMode, TouchTone, + TwsStatus, WearDetection, }, parsers::ParseError, }; diff --git a/soundcore-lib/src/packets/response/state/a3027.rs b/soundcore-lib/src/packets/response/state/a3027.rs index 5effa32..1bb120b 100644 --- a/soundcore-lib/src/packets/response/state/a3027.rs +++ b/soundcore-lib/src/packets/response/state/a3027.rs @@ -1,4 +1,3 @@ -use enumflags2::{make_bitflags, BitFlags}; use nom::{ combinator::{all_consuming, opt}, error::context, @@ -7,14 +6,15 @@ use nom::{ use serde::{Deserialize, Serialize}; use crate::{ - devices::a3027_features, models::{ - AgeRange, BaseHearID, DeviceFirmware, EQConfiguration, Gender, HearID, SerialNumber, - SingleBattery, SoundMode, SoundcoreFeatureFlags, StereoEQConfiguration, TwsStatus, - WearDetection, - }, parsers::{ + devices::a3027_features, + models::{ + AgeRange, BaseHearID, DeviceFirmware, Gender, HearID, SerialNumber, SingleBattery, + SoundMode, StereoEQConfiguration, TwsStatus, WearDetection, + }, + parsers::{ parse_base_hear_id, parse_bool, parse_dual_fw, parse_serial_number, parse_single_battery, u8_parser, - } + }, }; use crate::parsers::{ diff --git a/soundcore-lib/src/packets/response/state/a3028.rs b/soundcore-lib/src/packets/response/state/a3028.rs index b98027b..6f49f64 100644 --- a/soundcore-lib/src/packets/response/state/a3028.rs +++ b/soundcore-lib/src/packets/response/state/a3028.rs @@ -1,14 +1,15 @@ -use enumflags2::{make_bitflags, BitFlags}; use nom::{combinator::all_consuming, error::context, sequence::tuple}; use serde::{Deserialize, Serialize}; use crate::{ - devices::a3028_features, models::{ - AgeRange, BaseHearID, DeviceFirmware, EQConfiguration, Gender, HearID, SerialNumber, - SingleBattery, SoundMode, SoundcoreFeatureFlags, StereoEQConfiguration, TwsStatus, - }, parsers::{ + devices::a3028_features, + models::{ + AgeRange, BaseHearID, DeviceFirmware, Gender, HearID, SerialNumber, SingleBattery, + SoundMode, StereoEQConfiguration, TwsStatus, + }, + parsers::{ parse_base_hear_id, parse_dual_fw, parse_serial_number, parse_single_battery, u8_parser, - } + }, }; use crate::parsers::{ diff --git a/soundcore-lib/src/packets/response/state/a3029.rs b/soundcore-lib/src/packets/response/state/a3029.rs index 29f001b..509fbdb 100644 --- a/soundcore-lib/src/packets/response/state/a3029.rs +++ b/soundcore-lib/src/packets/response/state/a3029.rs @@ -1,4 +1,3 @@ -use enumflags2::{make_bitflags, BitFlags}; use nom::{combinator::all_consuming, error::context, number::complete::le_u8, sequence::tuple}; use serde::{Deserialize, Serialize}; @@ -10,8 +9,8 @@ use crate::parsers::{ use crate::types::SupportedModels; use crate::{ models::{ - AgeRange, BaseHearID, DeviceFirmware, EQConfiguration, Gender, HearID, SerialNumber, - SingleBattery, SoundMode, SoundcoreFeatureFlags, StereoEQConfiguration, TwsStatus, + AgeRange, BaseHearID, DeviceFirmware, Gender, HearID, SerialNumber, SingleBattery, + SoundMode, StereoEQConfiguration, TwsStatus, }, parsers::{ parse_base_hear_id, parse_dual_fw, parse_serial_number, parse_single_battery, u8_parser, diff --git a/soundcore-lib/src/packets/response/state/a3040.rs b/soundcore-lib/src/packets/response/state/a3040.rs index 527c0bc..60f7ddd 100644 --- a/soundcore-lib/src/packets/response/state/a3040.rs +++ b/soundcore-lib/src/packets/response/state/a3040.rs @@ -1,28 +1,23 @@ -use std::num::NonZeroUsize; - -use enumflags2::{make_bitflags, BitFlags}; -use nom::{bits, combinator::all_consuming, error::context, sequence::tuple}; use nom::{bytes::complete::take, number::complete::le_u8}; +use nom::{error::context, sequence::tuple}; use serde::{Deserialize, Serialize}; use crate::devices::a3040_features; use crate::models::{ - A3040ButtonModel, ButtonModel, EQConfiguration, PromptLanguage, SoundMode, - StereoEQConfiguration, TwsStatus, + A3040ButtonModel, ButtonModel, PromptLanguage, SoundMode, StereoEQConfiguration, TwsStatus, }; use crate::packets::DeviceStateResponse; use crate::parsers::{ bool_parser, parse_a3040_button_model, parse_adaptive_sound_mode_customizable_trans, - parse_auto_power_off_on, parse_fw, parse_hearing_protect, parse_mono_eq, parse_prompt_language, - parse_single_battery, parse_sound_mode, parse_stereo_eq, parse_stereo_eq_configuration, - u8_parser, TaggedData, TaggedParseResult, + parse_auto_power_off_on, parse_fw, parse_hearing_protect, parse_prompt_language, + parse_single_battery, parse_stereo_eq_configuration, u8_parser, TaggedData, TaggedParseResult, }; use crate::types::SupportedModels; use crate::{ models::{ AmbientSoundNotice, AutoPowerOff, BassUp, DeviceColor, FirmwareVer, HearingProtect, - InEarBeep, PowerOnBatteryNotice, SerialNumber, SingleBattery, SoundcoreFeatureFlags, - SupportTwoCnn, ThreeDimensionalEffect, TouchTone, WearDetection, LDAC, + InEarBeep, PowerOnBatteryNotice, SerialNumber, SingleBattery, SupportTwoCnn, + ThreeDimensionalEffect, TouchTone, WearDetection, LDAC, }, parsers::{parse_serial_number, ParseError}, }; @@ -132,7 +127,7 @@ pub fn parse_a3040_state_response<'a, E: ParseError<'a>>( }, }, )) - })(&bytes) + })(bytes) } impl From for DeviceStateResponse { diff --git a/soundcore-lib/src/packets/response/state/a3930.rs b/soundcore-lib/src/packets/response/state/a3930.rs index 03e7829..39079c2 100644 --- a/soundcore-lib/src/packets/response/state/a3930.rs +++ b/soundcore-lib/src/packets/response/state/a3930.rs @@ -1,4 +1,3 @@ -use enumflags2::{make_bitflags, BitFlags}; use nom::{ combinator::{all_consuming, opt}, error::context, @@ -8,11 +7,12 @@ use nom::{ use serde::{Deserialize, Serialize}; use crate::{ - devices::a3930_features, models::{ - A3909ButtonModel, AgeRange, Battery, ButtonModel, CustomHearID, DualBattery, - EQConfiguration, Gender, HearID, SideTone, SoundMode, SoundcoreFeatureFlags, - StereoEQConfiguration, TwsStatus, - }, parsers::u8_parser + devices::a3930_features, + models::{ + A3909ButtonModel, AgeRange, Battery, ButtonModel, CustomHearID, DualBattery, Gender, + HearID, SideTone, SoundMode, StereoEQConfiguration, TwsStatus, + }, + parsers::u8_parser, }; use crate::parsers::{ @@ -39,7 +39,6 @@ pub struct A3930StateResponse { pub hear_id_eq_index: Option<(u8, u8)>, // TODO: Parse this correctly } - impl From for DeviceStateResponse { fn from(value: A3930StateResponse) -> Self { DeviceStateResponse { diff --git a/soundcore-lib/src/packets/response/state/a3951.rs b/soundcore-lib/src/packets/response/state/a3951.rs index 42338e3..20df32c 100644 --- a/soundcore-lib/src/packets/response/state/a3951.rs +++ b/soundcore-lib/src/packets/response/state/a3951.rs @@ -1,4 +1,3 @@ -use enumflags2::{make_bitflags, BitFlags}; use nom::{ combinator::{all_consuming, opt}, error::context, @@ -8,17 +7,17 @@ use nom::{ use serde::{Deserialize, Serialize}; use crate::{ - devices::a3951_features, models::{ - A3909ButtonModel, AgeRange, Battery, ButtonModel, CustomHearID, DualBattery, - EQConfiguration, Gender, HearID, SideTone, SoundMode, SoundcoreFeatureFlags, - StereoEQConfiguration, TouchTone, TwsStatus, WearDetection, - }, parsers::u8_parser + devices::a3951_features, + models::{ + A3909ButtonModel, AgeRange, Battery, ButtonModel, CustomHearID, DualBattery, Gender, + HearID, SideTone, SoundMode, StereoEQConfiguration, TouchTone, TwsStatus, WearDetection, + }, + parsers::u8_parser, }; use crate::parsers::{ bool_parser, parse_a3909_button_model, parse_custom_hear_id, parse_dual_battery, parse_gender, - parse_sound_mode, parse_stereo_eq_configuration, ParseError, TaggedData, - TaggedParseResult, + parse_sound_mode, parse_stereo_eq_configuration, ParseError, TaggedData, TaggedParseResult, }; use crate::types::SupportedModels; @@ -42,8 +41,6 @@ pub struct A3951StateResponse { pub new_battery: Option<(u8, u8)>, } - - impl From for DeviceStateResponse { fn from(value: A3951StateResponse) -> Self { DeviceStateResponse { @@ -135,7 +132,6 @@ pub fn parse_a3951_state_response<'a, E: ParseError<'a>>( #[cfg(test)] mod a3951_state { - use super::*; const RESP_BYTES: [u8; 86] = [ 1, 1, 5, 5, 1, 0, 254, 254, 160, 150, 130, 120, 120, 120, 120, 120, 160, 150, 130, 120, diff --git a/soundcore-lib/src/parsers/auto_power.rs b/soundcore-lib/src/parsers/auto_power.rs index 7b1ce99..d40dfd1 100644 --- a/soundcore-lib/src/parsers/auto_power.rs +++ b/soundcore-lib/src/parsers/auto_power.rs @@ -10,7 +10,10 @@ pub fn parse_auto_power_off_on<'a, E: ParseError<'a>>( context( "parse_auto_power_off_on", map(tuple((parse_bool, le_u8)), |(enabled, index)| { - AutoPowerOff { enabled, index: index.clamp(0, 3) } + AutoPowerOff { + enabled, + index: index.clamp(0, 3), + } }), )(bytes) } diff --git a/soundcore-lib/src/parsers/eq.rs b/soundcore-lib/src/parsers/eq.rs index 1f825b0..f2a6a9f 100644 --- a/soundcore-lib/src/parsers/eq.rs +++ b/soundcore-lib/src/parsers/eq.rs @@ -4,7 +4,6 @@ use crate::models::{MonoEQ, StereoEQ}; use super::{ParseError, ParseResult}; - pub fn parse_mono_eq<'a, E: ParseError<'a>>( bands: usize, ) -> impl Fn(&'a [u8]) -> ParseResult { @@ -39,7 +38,7 @@ mod eq_parser { let bytes = [0x00, 0x10, 0xF0, 0x10, 0x00, 0x10, 0xF0, 0x10]; let expected = Ok(( &b""[..], - MonoEQ::from_signed_bytes(vec![-120, -104, 120, -104, -120, -104, 120, -104]) + MonoEQ::from_signed_bytes(vec![-120, -104, 120, -104, -120, -104, 120, -104]), )); let output = parse_mono_eq::>(8)(&bytes); @@ -56,7 +55,9 @@ mod eq_parser { let expected = Ok(( &b""[..], StereoEQ { - left: MonoEQ::from_signed_bytes(vec![-120, -120, -120, -120, -120, -120, -120, -120]), + left: MonoEQ::from_signed_bytes(vec![ + -120, -120, -120, -120, -120, -120, -120, -120, + ]), right: eq, }, )); diff --git a/soundcore-lib/src/parsers/hearid.rs b/soundcore-lib/src/parsers/hearid.rs index 75cb2fc..2e663c4 100644 --- a/soundcore-lib/src/parsers/hearid.rs +++ b/soundcore-lib/src/parsers/hearid.rs @@ -49,12 +49,12 @@ pub fn parse_custom_hear_id<'a, E: ParseError<'a>>( right: r_eq, }), }; - return CustomHearID { + CustomHearID { base, hearid_type, hearid_music_type, custom_values: eq, - }; + } }, ), )(bytes) diff --git a/soundcore-lib/src/parsers/hearing_protect.rs b/soundcore-lib/src/parsers/hearing_protect.rs index 77c1585..3774773 100644 --- a/soundcore-lib/src/parsers/hearing_protect.rs +++ b/soundcore-lib/src/parsers/hearing_protect.rs @@ -1,14 +1,16 @@ -use nom::{number::complete::le_u8, combinator::map, sequence::tuple, error::context}; +use nom::{combinator::map, error::context, number::complete::le_u8, sequence::tuple}; use crate::models::HearingProtect; -use super::{ParseError, parse_bool, ParseResult}; +use super::{parse_bool, ParseError, ParseResult}; -pub fn parse_hearing_protect<'a, E: ParseError<'a>>(bytes: &'a [u8]) -> ParseResult<'a, HearingProtect, E> { +pub fn parse_hearing_protect<'a, E: ParseError<'a>>( + bytes: &'a [u8], +) -> ParseResult<'a, HearingProtect, E> { context( "parse_hearing_protect", map(tuple((parse_bool, le_u8, le_u8)), |(enabled, db, freq)| { HearingProtect { enabled, db, freq } }), )(bytes) -} \ No newline at end of file +} diff --git a/soundcore-lib/src/parsers/prompt_language.rs b/soundcore-lib/src/parsers/prompt_language.rs index 6664bb3..47f510c 100644 --- a/soundcore-lib/src/parsers/prompt_language.rs +++ b/soundcore-lib/src/parsers/prompt_language.rs @@ -1,14 +1,16 @@ -use nom::{error::context, combinator::map_opt, number::complete::le_u8}; +use nom::{combinator::map_opt, error::context, number::complete::le_u8}; use crate::models::PromptLanguage; use super::{ParseError, ParseResult}; -pub fn parse_prompt_language<'a, E: ParseError<'a>>(bytes: &'a [u8]) -> ParseResult<'a, PromptLanguage, E> { +pub fn parse_prompt_language<'a, E: ParseError<'a>>( + bytes: &'a [u8], +) -> ParseResult<'a, PromptLanguage, E> { context( "parse_prompt_language", map_opt(le_u8, |prompt_language| { - PromptLanguage::from_repr(prompt_language.into()) + PromptLanguage::from_repr(prompt_language) }), )(bytes) -} \ No newline at end of file +} diff --git a/soundcore-lib/src/types.rs b/soundcore-lib/src/types.rs index cd7b088..8ca5444 100644 --- a/soundcore-lib/src/types.rs +++ b/soundcore-lib/src/types.rs @@ -3,8 +3,6 @@ use serde::{Deserialize, Serialize}; use strum::EnumString; use typeshare::typeshare; -use crate::error::SoundcoreLibError; - #[derive( Debug, Serialize, Deserialize, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, EnumString, )]