Skip to content

Commit

Permalink
Use heapless
Browse files Browse the repository at this point in the history
  • Loading branch information
taks committed Apr 15, 2024
1 parent bab0fbb commit 4f475f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ embedded-svc = { version = "0.27", default-features = false }
bitflags = { version = "2.4.1" }
bstr = { version = "1.8.0", default-features = false }
embassy-sync = { version = "0.5.0" }
heapless = "0.8.0"
num_enum = { version = "0.7", default-features = false }
once_cell = { version = "1.19.0", default-features = false }
uuid = { version = "1", default-features = false, features = ["macro-diagnostics"] }
Expand Down
11 changes: 6 additions & 5 deletions src/server/ble_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ use alloc::{boxed::Box, sync::Arc, vec::Vec};
use core::{cell::UnsafeCell, ffi::c_void};

const BLE_HS_CONN_HANDLE_NONE: u16 = esp_idf_sys::BLE_HS_CONN_HANDLE_NONE as _;
const MAX_CONNECTIONS: usize = esp_idf_sys::CONFIG_BT_NIMBLE_MAX_CONNECTIONS as _;

#[allow(clippy::type_complexity)]
pub struct BLEServer {
pub(crate) started: bool,
advertise_on_disconnect: bool,
services: Vec<Arc<Mutex<BLEService>>>,
notify_characteristic: Vec<&'static mut BLECharacteristic>,
connections: Vec<u16>,
indicate_wait: [u16; esp_idf_sys::CONFIG_BT_NIMBLE_MAX_CONNECTIONS as _],
connections: heapless::Vec<u16, MAX_CONNECTIONS>,
indicate_wait: [u16; MAX_CONNECTIONS],

on_connect: Option<Box<dyn FnMut(&mut Self, &BLEConnDesc) + Send + Sync>>,
on_disconnect: Option<Box<dyn FnMut(&BLEConnDesc, Result<(), BLEError>) + Send + Sync>>,
Expand All @@ -31,8 +32,8 @@ impl BLEServer {
advertise_on_disconnect: true,
services: Vec::new(),
notify_characteristic: Vec::new(),
connections: Vec::new(),
indicate_wait: [BLE_HS_CONN_HANDLE_NONE; esp_idf_sys::CONFIG_BT_NIMBLE_MAX_CONNECTIONS as _],
connections: heapless::Vec::new(),
indicate_wait: [BLE_HS_CONN_HANDLE_NONE; MAX_CONNECTIONS],
on_connect: None,
on_disconnect: None,
on_passkey_request: None,
Expand Down Expand Up @@ -251,7 +252,7 @@ impl BLEServer {
esp_idf_sys::BLE_GAP_EVENT_CONNECT => {
let connect = unsafe { &event.__bindgen_anon_1.connect };
if connect.status == 0 {
server.connections.push(connect.conn_handle);
server.connections.push(connect.conn_handle).unwrap();

if let Ok(desc) = ble_gap_conn_find(connect.conn_handle) {
let server = UnsafeCell::new(server);
Expand Down

0 comments on commit 4f475f7

Please sign in to comment.