diff options
author | Ulf Lilleengen <ulf.lilleengen@gmail.com> | 2021-10-05 15:55:11 +0200 |
---|---|---|
committer | Ulf Lilleengen <ulf.lilleengen@gmail.com> | 2021-10-05 15:55:11 +0200 |
commit | 230d133f4d6e02d2631a3fcdcebe7675764c17fb (patch) | |
tree | eaf44c0bc830fefb3baf27d89c359ddf7738d877 /examples/src/bin/ble_bas_peripheral.rs | |
parent | f291131f082a37a4a36eca84e5322b9ea1718749 (diff) | |
download | nrf-softdevice-230d133f4d6e02d2631a3fcdcebe7675764c17fb.zip |
Update an example
Diffstat (limited to 'examples/src/bin/ble_bas_peripheral.rs')
-rw-r--r-- | examples/src/bin/ble_bas_peripheral.rs | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/examples/src/bin/ble_bas_peripheral.rs b/examples/src/bin/ble_bas_peripheral.rs index 8793c82..2b8fe8a 100644 --- a/examples/src/bin/ble_bas_peripheral.rs +++ b/examples/src/bin/ble_bas_peripheral.rs @@ -14,7 +14,7 @@ use defmt::*; use embassy::executor::Executor; use embassy::util::Forever; -use nrf_softdevice::ble::{gatt_server, peripheral}; +use nrf_softdevice::ble::{gatt_server::{self, Server}, peripheral}; use nrf_softdevice::{raw, Softdevice}; static EXECUTOR: Forever<Executor> = Forever::new(); @@ -57,27 +57,31 @@ async fn bluetooth_task(sd: &'static Softdevice) { info!("advertising done!"); // Run the GATT server on the connection. This returns when the connection gets disconnected. - let res = gatt_server::run(&conn, &server, |e| match e { - BatteryServiceEvent::BatteryLevelWrite(val) => { - info!("wrote battery level: {}", val); - if let Err(e) = server.battery_level_notify(&conn, val + 1) { - info!("send notification error: {:?}", e); + let res = gatt_server::run(&conn, |e| { + server.on_event(&e, |e| match e { + BatteryServiceEvent::BatteryLevelWrite(val) => { + info!("wrote battery level: {}", val); + if let Err(e) = server.battery_level_notify(&conn, val + 1) { + info!("send notification error: {:?}", e); + } } - } - BatteryServiceEvent::FooWrite(val) => { - info!("wrote battery level: {}", val); - if let Err(e) = server.foo_notify(&conn, val + 1) { - info!("send notification error: {:?}", e); + BatteryServiceEvent::FooWrite(val) => { + info!("wrote battery level: {}", val); + if let Err(e) = server.foo_notify(&conn, val + 1) { + info!("send notification error: {:?}", e); + } } - } - BatteryServiceEvent::BatteryLevelNotificationsEnabled => { - info!("battery notifications enabled") - } - BatteryServiceEvent::BatteryLevelNotificationsDisabled => { - info!("battery notifications disabled") - } - BatteryServiceEvent::FooNotificationsEnabled => info!("foo notifications enabled"), - BatteryServiceEvent::FooNotificationsDisabled => info!("foo notifications disabled"), + BatteryServiceEvent::BatteryLevelNotificationsEnabled => { + info!("battery notifications enabled") + } + BatteryServiceEvent::BatteryLevelNotificationsDisabled => { + info!("battery notifications disabled") + } + BatteryServiceEvent::FooNotificationsEnabled => info!("foo notifications enabled"), + BatteryServiceEvent::FooNotificationsDisabled => { + info!("foo notifications disabled") + } + }) }) .await; |