From 230d133f4d6e02d2631a3fcdcebe7675764c17fb Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 5 Oct 2021 15:55:11 +0200 Subject: Update an example --- examples/src/bin/ble_bas_peripheral.rs | 44 ++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'examples') 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 = 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; -- cgit v1.2.3