diff options
author | Ulf Lilleengen <ulf.lilleengen@gmail.com> | 2021-10-06 18:43:55 +0200 |
---|---|---|
committer | Ulf Lilleengen <ulf.lilleengen@gmail.com> | 2021-10-06 18:43:55 +0200 |
commit | 8d78ed20f1313d00d8727f41383413a13c23d457 (patch) | |
tree | 754cfb7251bbf7d727b54aa4c82926554e312f76 /examples/src/bin/ble_bas_peripheral.rs | |
parent | 230d133f4d6e02d2631a3fcdcebe7675764c17fb (diff) | |
download | nrf-softdevice-8d78ed20f1313d00d8727f41383413a13c23d457.zip |
Simplify API
Diffstat (limited to 'examples/src/bin/ble_bas_peripheral.rs')
-rw-r--r-- | examples/src/bin/ble_bas_peripheral.rs | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/examples/src/bin/ble_bas_peripheral.rs b/examples/src/bin/ble_bas_peripheral.rs index 2b8fe8a..c8b70a0 100644 --- a/examples/src/bin/ble_bas_peripheral.rs +++ b/examples/src/bin/ble_bas_peripheral.rs @@ -14,7 +14,10 @@ use defmt::*; use embassy::executor::Executor; use embassy::util::Forever; -use nrf_softdevice::ble::{gatt_server::{self, Server}, peripheral}; +use nrf_softdevice::ble::{ + gatt_server::{self, Server}, + peripheral, +}; use nrf_softdevice::{raw, Softdevice}; static EXECUTOR: Forever<Executor> = Forever::new(); @@ -57,31 +60,32 @@ 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, |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); - } + let res = gatt_server::run(&conn, |e| match server.on_event(e) { + Some(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); - } + } + Some(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") - } - }) + } + Some(BatteryServiceEvent::BatteryLevelNotificationsEnabled) => { + info!("battery notifications enabled") + } + Some(BatteryServiceEvent::BatteryLevelNotificationsDisabled) => { + info!("battery notifications disabled") + } + Some(BatteryServiceEvent::FooNotificationsEnabled) => { + info!("foo notifications enabled") + } + Some(BatteryServiceEvent::FooNotificationsDisabled) => { + info!("foo notifications disabled") + } + None => {} }) .await; |