Skip to content

Commit

Permalink
Merge pull request #239 from HaoboGu/fix/split_profile_switch
Browse files Browse the repository at this point in the history
Receive keys from peri when running dummy service
  • Loading branch information
HaoboGu authored Jan 6, 2025
2 parents f649352 + 2fe4049 commit 21e4e33
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions rmk/src/ble/nrf/bonder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ impl MultiBonder {

if let Some(slot_num) = saved_slot_num_for_conn {
if slot_num != current_profile {
debug!(
"Bonded device {} is not on active profile {}",
addr, current_profile
);
return false;
}
}
Expand Down
6 changes: 5 additions & 1 deletion rmk/src/ble/nrf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,11 @@ pub async fn initialize_nrf_ble_keyboard_and_run<
if let Ok(Some(StorageData::ActiveBleProfile(profile))) =
read_storage!(storage, &(StorageKeys::ActiveBleProfile as u32), buf)
{
debug!("Loaded active profile: {}", profile);
ACTIVE_PROFILE.store(profile, Ordering::SeqCst);
} else {
// If no saved active profile, use 0 as default
debug!("Loaded default active profile",);
ACTIVE_PROFILE.store(0, Ordering::SeqCst);
};

Expand Down Expand Up @@ -567,7 +569,9 @@ pub(crate) async fn run_dummy_keyboard<
warn!("Dummy service receives")
}
};

// Even for dummy service, we need to set the connection state to true.
// So that we can receive the matrix scan result from split, which might be used for profile switching
CONNECTION_STATE.store(true, Ordering::Release);
match select4(matrix_fut, keyboard_fut, storage_fut, dummy_communication).await {
Either4::First(_) => (),
Either4::Second(_) => (),
Expand Down
1 change: 1 addition & 0 deletions rmk/src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ impl<'a, const ROW: usize, const COL: usize, const NUM_LAYER: usize>
// Get user key id
let id = key as u8 - KeyCode::User0 as u8;
if id < 8 {
info!("Switch to profile: {}", id);
// User0~7: Swtich to the specific profile
BLE_PROFILE_CHANNEL
.send(BleProfileAction::SwitchProfile(id))
Expand Down
2 changes: 1 addition & 1 deletion rmk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub(crate) static KEYBOARD_STATE: AtomicBool = AtomicBool::new(false);
/// - 1: BLE
/// - Other: reserved
pub(crate) static CONNECTION_TYPE: AtomicU8 = AtomicU8::new(0);
/// Whethe the connection is ready.
/// Whether the connection is ready.
/// After the connection is ready, the matrix starts scanning
pub(crate) static CONNECTION_STATE: AtomicBool = AtomicBool::new(false);

Expand Down
2 changes: 2 additions & 0 deletions rmk/src/split/nrf/central.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ pub(crate) async fn run_ble_client(
embassy_time::Timer::after_millis(200).await;
};

info!("Connected to peripheral");

let ble_client: BleSplitCentralClient = match gatt_client::discover(&conn).await {
Ok(client) => client,
Err(e) => {
Expand Down
1 change: 1 addition & 0 deletions rmk/src/split/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl<S: SplitWriter + SplitReader> SplitPeripheral<S> {
// Currently only handle the central state message
Ok(split_message) => match split_message {
SplitMessage::ConnectionState(state) => {
info!("Received connection state update: {}", state);
CONNECTION_STATE.store(state, core::sync::atomic::Ordering::Release);
}
_ => (),
Expand Down

0 comments on commit 21e4e33

Please sign in to comment.