diff options
author | Albert Skog <mail@albertskog.se> | 2021-10-15 12:34:47 +0200 |
---|---|---|
committer | Albert Skog <mail@albertskog.se> | 2021-10-15 12:34:47 +0200 |
commit | 182b9001189deca80e3840b6c989cbc37623991d (patch) | |
tree | 358d1d5ed6f9aaef0a6b622bb9b36f65b4a115d5 /examples/src/bin/ble_peripheral_onoff.rs | |
parent | fd48489c0ffc58c8ae02d32d9904162a2777df3c (diff) | |
parent | bf4f7a143d38713922d9bd5ff1a983c4c7290c10 (diff) | |
download | nrf-softdevice-182b9001189deca80e3840b6c989cbc37623991d.zip |
Merge branch 'master' into feature/indications
Diffstat (limited to 'examples/src/bin/ble_peripheral_onoff.rs')
-rw-r--r-- | examples/src/bin/ble_peripheral_onoff.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/examples/src/bin/ble_peripheral_onoff.rs b/examples/src/bin/ble_peripheral_onoff.rs index 47b9dfd..32eac93 100644 --- a/examples/src/bin/ble_peripheral_onoff.rs +++ b/examples/src/bin/ble_peripheral_onoff.rs @@ -28,13 +28,18 @@ async fn softdevice_task(sd: &'static Softdevice) { sd.run().await; } -#[nrf_softdevice::gatt_server(uuid = "9e7312e0-2354-11eb-9f10-fbc30a62cf38")] +#[nrf_softdevice::gatt_service(uuid = "9e7312e0-2354-11eb-9f10-fbc30a62cf38")] struct FooService { #[characteristic(uuid = "9e7312e0-2354-11eb-9f10-fbc30a63cf38", read, write, notify)] foo: u16, } -async fn run_bluetooth(sd: &'static Softdevice, server: &FooService) { +#[nrf_softdevice::gatt_server] +struct Server { + foo: FooService, +} + +async fn run_bluetooth(sd: &'static Softdevice, server: &Server) { #[rustfmt::skip] let adv_data = &[ 0x02, 0x01, raw::BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE as u8, @@ -57,13 +62,13 @@ async fn run_bluetooth(sd: &'static Softdevice, server: &FooService) { info!("advertising done!"); let res = gatt_server::run(&conn, server, |e| match e { - FooServiceEvent::FooWrite(val) => { + ServerEvent::Foo(FooServiceEvent::FooWrite(val)) => { info!("wrote foo level: {}", val); - if let Err(e) = server.foo_notify(&conn, val + 1) { + if let Err(e) = server.foo.foo_notify(&conn, val + 1) { info!("send notification error: {:?}", e); } } - FooServiceEvent::FooCccdWrite { notifications } => { + ServerEvent::Foo(FooServiceEvent::FooCccdWrite { notifications }) => { info!("foo notifications: {}", notifications) } }) @@ -77,7 +82,7 @@ async fn run_bluetooth(sd: &'static Softdevice, server: &FooService) { #[embassy::task] async fn bluetooth_task(sd: &'static Softdevice, button1: AnyPin, button2: AnyPin) { - let server: FooService = unwrap!(gatt_server::register(sd)); + let server: Server = unwrap!(gatt_server::register(sd)); info!("Bluetooth is OFF"); info!("Press nrf52840-dk button 1 to enable, button 2 to disable"); |