Skip to content

Commit

Permalink
expose characteristic handle to make GattEvent Read and Write nicer (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
jamessizeland authored Nov 21, 2024
1 parent f800da0 commit 224f371
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 16 additions & 1 deletion examples/apps/src/ble_bas_peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,29 @@ async fn advertise_task<C: Controller>(
let conn = advertiser.accept().await?;
info!("[adv] connection established");
let mut tick: u8 = 0;
let level = server.battery_service.level;
loop {
match select(conn.next(), Timer::after(Duration::from_secs(2))).await {
Either::First(event) => match event {
ConnectionEvent::Disconnected { reason } => {
info!("[adv] disconnected: {:?}", reason);
break;
}
_ => {}
ConnectionEvent::Gatt { event, .. } => match event {
GattEvent::Read { value_handle } => {
if value_handle == level.handle {
let value = server.get(&level);
info!("[gatt] Read Event to Level Characteristic: {:?}", value);
}
},
GattEvent::Write { value_handle } => {
if value_handle == level.handle {
let value = server.get(&level);
info!("[gatt] Write Event to Level Characteristic: {:?}", value);
}
},
},

},
Either::Second(_) => {
tick = tick.wrapping_add(1);
Expand Down
3 changes: 2 additions & 1 deletion host/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,8 @@ impl<'r, 'd, M: RawMutex, const MAX: usize> Drop for ServiceBuilder<'r, 'd, M, M
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Characteristic<T: GattValue> {
pub(crate) cccd_handle: Option<u16>,
pub(crate) handle: u16,
/// Handle value assigned to this characteristic when it is added to the Gatt Attribute Table
pub handle: u16,
pub(crate) phantom: PhantomData<T>,
}

Expand Down

0 comments on commit 224f371

Please sign in to comment.