-
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
16 changed files
with
1,317 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import '@testing-library/jest-dom'; | ||
import { vi } from 'vitest'; | ||
|
||
vi.mock('zustand'); |
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,4 @@ | ||
mod feature_set; | ||
mod state; | ||
|
||
pub use 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Proof of concept for splitting up the state into features | ||
pub struct HearIDFeature {} | ||
|
||
pub struct DeviceInfoFeature { | ||
// fw, sn, button_model, host_device, side_tone, age_range, | ||
} | ||
|
||
pub struct SoundFeatures { | ||
// bassup, | ||
} | ||
|
||
pub struct PowerFeatures { | ||
// battery_level, | ||
// battery_status, | ||
// auto_power_off, | ||
// power_on_battery_notice, | ||
} |
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,30 @@ | ||
use env_logger::{Builder, Target}; | ||
use log::LevelFilter; | ||
|
||
use soundcore_lib::ble::{BLEConnectionFactory, BLEConnectionManager}; | ||
use soundcore_lib::device_manager::create_device_manager; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
Builder::new() | ||
.target(Target::Stdout) | ||
.filter_level(LevelFilter::Trace) | ||
.init(); | ||
let manager = create_device_manager().await; | ||
let scan_res = manager.ble_scan(None).await?; | ||
println!("{:?}", scan_res); | ||
let device = scan_res.iter().find(|d| d.descriptor.name.contains("Q45")).unwrap(); | ||
let connection = manager.connect(device.clone()).await?; | ||
|
||
let mut state_channel = connection.state_channel().await; | ||
|
||
while let Ok(()) = state_channel.changed().await { | ||
println!("{:?}", state_channel.borrow_and_update()); | ||
} | ||
// let registry = BtlePlugDeviceRegistry::new().await?; | ||
// let scan_res = registry.scan(None).await?; | ||
// println!("{:?}", scan_res); | ||
// let q45 = scan_res.iter().find(|d| d.name.contains("Q45")).unwrap(); | ||
// let _connection = registry.connect(q45.clone(), None).await?; | ||
Ok(()) | ||
} |
This file was deleted.
Oops, something went wrong.
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,52 @@ | ||
use soundcore_lib::{packets::ResponsePacket, types::SupportedModels}; | ||
|
||
#[test] | ||
fn should_parse_state_update() { | ||
let packet = ResponsePacket::from_bytes(&test_data::a3040::anc); | ||
match packet { | ||
Ok(ResponsePacket::DeviceState(state)) => { | ||
// TODO: Assert state | ||
assert_eq!(state.tag, SupportedModels::A3040); | ||
println!("{:?}", state.data); | ||
} | ||
Err(err) => panic!("Failed to parse state update packet"), | ||
_ => panic!("Parsed as wrong packet type"), | ||
} | ||
} | ||
|
||
#[test] | ||
fn should_parse_sound_mode_update_packet() { | ||
// Normal | ||
{ | ||
let packet = ResponsePacket::from_bytes(&test_data::a3040::SOUND_MODE_UPDATE_NORMAL); | ||
match packet { | ||
Ok(ResponsePacket::SoundModeUpdate(state)) => { | ||
todo!() | ||
} | ||
Err(_err) => panic!("Failed to parse state update packet"), | ||
_ => panic!("Parsed as wrong packet type"), | ||
} | ||
} | ||
// Noise Cancelling | ||
{ | ||
let packet = ResponsePacket::from_bytes(&test_data::a3040::SOUND_MODE_UPDATE_NOISE_CANCELLING); | ||
match packet { | ||
Ok(ResponsePacket::SoundModeUpdate(state)) => { | ||
todo!() | ||
} | ||
Err(_err) => panic!("Failed to parse state update packet"), | ||
_ => panic!("Parsed as wrong packet type"), | ||
} | ||
} | ||
// Transparency | ||
{ | ||
let packet = ResponsePacket::from_bytes(&test_data::a3040::SOUND_MODE_UPDATE_TRANSPARENCY); | ||
match packet { | ||
Ok(ResponsePacket::SoundModeUpdate(state)) => { | ||
todo!() | ||
} | ||
Err(_err) => panic!("Failed to parse state update packet"), | ||
_ => panic!("Parsed as wrong packet type"), | ||
} | ||
} | ||
} |
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,45 @@ | ||
import * as zustand from 'zustand'; | ||
import { act } from '@testing-library/react'; | ||
import { afterEach } from 'node:test'; | ||
import { vi } from 'vitest'; | ||
|
||
const { create: actualCreate, createStore: actualCreateStore } = | ||
await vi.importActual<typeof zustand>('zustand'); | ||
|
||
export const storeResetFns = new Set<() => void>(); | ||
|
||
const createUncurried = <T>(stateCreator: zustand.StateCreator<T>) => { | ||
const store = actualCreate(stateCreator); | ||
const initialState = store.getInitialState(); | ||
storeResetFns.add(() => { | ||
store.setState(initialState, true); | ||
}); | ||
return store; | ||
}; | ||
|
||
export const create = (<T>(stateCreator: zustand.StateCreator<T>) => { | ||
return typeof stateCreator === 'function' ? createUncurried(stateCreator) : createUncurried; | ||
}) as typeof zustand.create; | ||
|
||
const createStoreUncurried = <T>(stateCreator: zustand.StateCreator<T>) => { | ||
const store = actualCreateStore(stateCreator); | ||
const initialState = store.getInitialState(); | ||
storeResetFns.add(() => { | ||
store.setState(initialState, true); | ||
}); | ||
return store; | ||
}; | ||
|
||
export const createStore = (<T>(stateCreator: zustand.StateCreator<T>) => { | ||
return typeof stateCreator === 'function' | ||
? createStoreUncurried(stateCreator) | ||
: createStoreUncurried; | ||
}) as typeof zustand.createStore; | ||
|
||
afterEach(() => { | ||
act(() => { | ||
storeResetFns.forEach((resetFn) => { | ||
resetFn(); | ||
}); | ||
}); | ||
}); |
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,22 @@ | ||
import { describe, it } from 'vitest'; | ||
import { useSoundcoreStore } from './useSoundcoreStore'; | ||
import { Event } from '@tauri-apps/api/event'; | ||
import { BridgeResponse } from '../types/tauri-backend'; | ||
|
||
describe('useSoundcoreStore', () => { | ||
describe('handleAsyncBridgeEvent', () => { | ||
it('should call the handler for the given kind', () => { | ||
const store = useSoundcoreStore(); | ||
const event: Event<BridgeResponse> = { | ||
event: 'test', | ||
windowLabel: 'test', | ||
id: 0, | ||
payload: { | ||
kind: 'scanResult', | ||
payload: [] | ||
} | ||
}; | ||
store.handleAsyncBridgeEvent(event); | ||
}); | ||
}); | ||
}); |
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,14 @@ | ||
import { defineConfig, mergeConfig } from 'vitest/config'; | ||
import viteConfig from './vite.config'; | ||
|
||
export default mergeConfig( | ||
viteConfig, | ||
defineConfig({ | ||
test: { | ||
globals: true, | ||
environment: 'jsdom', | ||
setupFiles: ['./setup-vitest.ts'], | ||
root: 'src/' | ||
} | ||
}) | ||
); |
Oops, something went wrong.