summaryrefslogtreecommitdiff
path: root/examples/src/bin/ble_bas_peripheral.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <dirbaio@dirbaio.net>2020-11-10 14:15:39 +0100
committerDario Nieuwenhuis <dirbaio@dirbaio.net>2020-11-10 14:15:39 +0100
commit1c15bd7677a77ba8a453ac3723d0153b0120d473 (patch)
tree100329b88906a9da4c232f592460c8cb2935a9e5 /examples/src/bin/ble_bas_peripheral.rs
parent3dffe02f75a691ed56579c28f83cc9ff405f01bf (diff)
downloadnrf-softdevice-1c15bd7677a77ba8a453ac3723d0153b0120d473.zip
update examples to anyfmt
Diffstat (limited to 'examples/src/bin/ble_bas_peripheral.rs')
-rw-r--r--examples/src/bin/ble_bas_peripheral.rs44
1 files changed, 27 insertions, 17 deletions
diff --git a/examples/src/bin/ble_bas_peripheral.rs b/examples/src/bin/ble_bas_peripheral.rs
index da80644..d734ce8 100644
--- a/examples/src/bin/ble_bas_peripheral.rs
+++ b/examples/src/bin/ble_bas_peripheral.rs
@@ -6,6 +6,7 @@
mod example_common;
use example_common::*;
+use anyfmt::{panic, *};
use core::mem;
use cortex_m_rt::entry;
use defmt::info;
@@ -26,11 +27,13 @@ async fn softdevice_task(sd: &'static Softdevice) {
struct BatteryService {
#[characteristic(uuid = "2a19", read, write, notify)]
battery_level: u8,
+ #[characteristic(uuid = "3a4a1f7e-22d8-11eb-a3aa-1b3b1d4e4a0d", read, write, notify)]
+ foo: u16,
}
#[task]
async fn bluetooth_task(sd: &'static Softdevice, config: peripheral::Config) {
- let server: BatteryService = gatt_server::register(sd).dewrap();
+ let server: BatteryService = unwrap!(gatt_server::register(sd));
#[rustfmt::skip]
let adv_data = &[
0x02, 0x01, raw::BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE as u8,
@@ -43,16 +46,17 @@ async fn bluetooth_task(sd: &'static Softdevice, config: peripheral::Config) {
];
loop {
- let conn = peripheral::advertise(
- sd,
- peripheral::ConnectableAdvertisement::ScannableUndirected {
- adv_data,
- scan_data,
- },
- config,
- )
- .await
- .dewrap();
+ let conn = unwrap!(
+ peripheral::advertise(
+ sd,
+ peripheral::ConnectableAdvertisement::ScannableUndirected {
+ adv_data,
+ scan_data,
+ },
+ config,
+ )
+ .await
+ );
info!("advertising done!");
@@ -64,12 +68,20 @@ async fn bluetooth_task(sd: &'static Softdevice, config: peripheral::Config) {
info!("send notification error: {:?}", e);
}
}
+ BatteryServiceEvent::FooWrite(val) => {
+ info!("wrote battery level: {:u16}", 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"),
})
.await;
@@ -92,9 +104,9 @@ fn main() -> ! {
}),
conn_gap: Some(raw::ble_gap_conn_cfg_t {
conn_count: 6,
- event_length: 6,
+ event_length: 24,
}),
- conn_gatt: Some(raw::ble_gatt_conn_cfg_t { att_mtu: 128 }),
+ conn_gatt: Some(raw::ble_gatt_conn_cfg_t { att_mtu: 256 }),
gatts_attr_tab_size: Some(raw::ble_gatts_cfg_attr_tab_size_t {
attr_tab_size: 32768,
}),
@@ -121,10 +133,8 @@ fn main() -> ! {
let sd = Softdevice::enable(sdp, &config);
let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev));
- executor.spawn(softdevice_task(sd)).dewrap();
- executor
- .spawn(bluetooth_task(sd, peripheral::Config::default()))
- .dewrap();
+ unwrap!(executor.spawn(softdevice_task(sd)));
+ unwrap!(executor.spawn(bluetooth_task(sd, peripheral::Config::default())));
loop {
executor.run();