Skip to content

Commit

Permalink
Reorder dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
elotom committed Apr 12, 2023
1 parent 7b777e4 commit 7db231f
Show file tree
Hide file tree
Showing 26 changed files with 116 additions and 85 deletions.
31 changes: 18 additions & 13 deletions examples/gatt_server.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::sync::{Arc, RwLock};

use esp_idf_svc::ble::{
gatt_server::{Characteristic, Profile, Service, GLOBAL_GATT_SERVER},
utilities::{AttributePermissions, BleUuid, CharacteristicProperties},
use std::sync::{Arc, Mutex, RwLock};

use esp_idf_svc::{
ble::{
self,
gatt_server::{Characteristic, Profile, Service, GLOBAL_GATT_SERVER},
utilities::{AttributePermissions, BleUuid, CharacteristicProperties},
},
nvs::{EspDefaultNvs, EspDefaultNvsPartition},
};

use esp_idf_sys::{esp_get_free_heap_size, esp_get_free_internal_heap_size};
Expand Down Expand Up @@ -99,14 +103,15 @@ fn main() {
.service(&service)
.build();

GLOBAL_GATT_SERVER
.lock()
.unwrap()
.profile(profile)
.device_name("ESP32-GATT-Server")
.appearance(ble::utilities::Appearance::WristWornPulseOximeter)
.advertise_service(&service)
.start();
match &mut *GLOBAL_GATT_SERVER.lock() {
Some(gatt_server) => gatt_server
.profile(profile)
.device_name("ESP32-GATT-Server")
.appearance(ble::utilities::Appearance::WristWornPulseOximeter)
.advertise_service(&service)
.start(),
None => panic!("GATT server not initialized"),
};

std::thread::spawn(move || {
let mut counter = 0;
Expand Down
19 changes: 10 additions & 9 deletions src/ble/gatt_server/characteristic.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
use crate::{
ble::gatt_server::descriptor::Descriptor,
ble::utilities::{AttributeControl, AttributePermissions, BleUuid, CharacteristicProperties},
nvs::EspDefaultNvs,
};
use core::fmt::Formatter;

use std::sync::{Arc, Mutex, RwLock};

use ::log::{debug, warn};

use esp_idf_sys::{
esp_attr_control_t, esp_attr_value_t, esp_ble_gatts_add_char,
esp_ble_gatts_cb_param_t_gatts_read_evt_param, esp_ble_gatts_cb_param_t_gatts_write_evt_param,
esp_ble_gatts_set_attr_value, esp_nofail,
};
use log::{debug, warn};
use std::{
fmt::Formatter,
sync::{Arc, Mutex, RwLock},

use crate::{
ble::gatt_server::descriptor::Descriptor,
ble::utilities::{AttributeControl, AttributePermissions, BleUuid, CharacteristicProperties},
nvs::EspDefaultNvs,
};

type WriteCallback = dyn Fn(Vec<u8>, esp_ble_gatts_cb_param_t_gatts_write_evt_param) + Send + Sync;
Expand Down
4 changes: 2 additions & 2 deletions src/ble/gatt_server/custom_attributes.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::sync::{Arc, Mutex};

use ::log::debug;

use crate::{
ble::gatt_server::Descriptor,
ble::utilities::{AttributePermissions, BleUuid},
nvs::EspDefaultNvs,
};

use log::debug;

impl Descriptor {
/// Creates a new descriptor with the `0x2901` UUID, and the description string as its value.
///
Expand Down
8 changes: 5 additions & 3 deletions src/ble/gatt_server/descriptor.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use alloc::fmt;

use std::{
collections::HashMap,
sync::{Arc, RwLock},
};

use crate::ble::utilities::{AttributeControl, AttributePermissions, BleUuid};
use ::log::{debug, info, warn};

use alloc::fmt;
use esp_idf_sys::{
esp_attr_control_t, esp_attr_value_t, esp_ble_gatts_add_char_descr,
esp_ble_gatts_cb_param_t_gatts_read_evt_param, esp_ble_gatts_cb_param_t_gatts_write_evt_param,
esp_ble_gatts_set_attr_value, esp_nofail,
};
use log::{debug, info, warn};

use crate::ble::utilities::{AttributeControl, AttributePermissions, BleUuid};

type DescriptorWriteCallback =
dyn Fn(Vec<u8>, esp_ble_gatts_cb_param_t_gatts_write_evt_param) + Send + Sync;
Expand Down
6 changes: 3 additions & 3 deletions src/ble/gatt_server/gap_event_handler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use ::log::{debug, info, warn};

use esp_idf_sys::{
esp_ble_gap_cb_param_t, esp_ble_gap_start_advertising, esp_bt_status_t_ESP_BT_STATUS_SUCCESS,
esp_gap_ble_cb_event_t, esp_gap_ble_cb_event_t_ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT,
Expand All @@ -7,9 +9,7 @@ use esp_idf_sys::{
esp_gap_ble_cb_event_t_ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT, esp_nofail,
};

use log::{debug, info, warn};

use super::GattServer;
use crate::ble::gatt_server::GattServer;

impl GattServer {
pub(crate) extern "C" fn gap_event_handler(
Expand Down
10 changes: 5 additions & 5 deletions src/ble/gatt_server/gatts_event_handler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::ble::gatt_server::{GattServer, Profile};
mod profile;
mod server;

use ::log::{debug, warn};

#[allow(clippy::wildcard_imports)]
use esp_idf_sys::*;
use log::{debug, warn};

mod profile;
mod server;
use crate::ble::gatt_server::{GattServer, Profile};

impl GattServer {
/// The main GATT server event loop.
Expand Down
6 changes: 4 additions & 2 deletions src/ble/gatt_server/gatts_event_handler/profile/add_char.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use ::log::{info, warn};

use esp_idf_sys::*;

use crate::ble::gatt_server::Profile;
use crate::ble::utilities::BleUuid;
use esp_idf_sys::*;
use log::{info, warn};

impl Profile {
pub(crate) fn on_char_add(&mut self, param: esp_ble_gatts_cb_param_t_gatts_add_char_evt_param) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use ::log::{info, warn};

use esp_idf_sys::*;

use crate::ble::gatt_server::Profile;
use crate::ble::utilities::BleUuid;
use esp_idf_sys::*;
use log::{info, warn};

impl Profile {
pub(crate) fn on_char_add_descr(
Expand Down
1 change: 0 additions & 1 deletion src/ble/gatt_server/gatts_event_handler/profile/conf.rs

This file was deleted.

6 changes: 4 additions & 2 deletions src/ble/gatt_server/gatts_event_handler/profile/create.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use ::log::{info, warn};

use esp_idf_sys::*;

use crate::ble::gatt_server::Profile;
use crate::ble::utilities::BleUuid;
use esp_idf_sys::*;
use log::{info, warn};

impl Profile {
pub(crate) fn on_create(&mut self, param: esp_ble_gatts_cb_param_t_gatts_create_evt_param) {
Expand Down
1 change: 0 additions & 1 deletion src/ble/gatt_server/gatts_event_handler/profile/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod add_char;
mod add_char_descr;
mod conf;
mod create;
mod read;
mod reg;
Expand Down
6 changes: 4 additions & 2 deletions src/ble/gatt_server/gatts_event_handler/profile/read.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use ::log::debug;

use esp_idf_sys::*;

use crate::ble::gatt_server::Profile;
use crate::ble::utilities::AttributeControl;
use esp_idf_sys::*;
use log::debug;

impl Profile {
pub(crate) fn on_read(
Expand Down
6 changes: 4 additions & 2 deletions src/ble/gatt_server/gatts_event_handler/profile/reg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::ble::gatt_server::Profile;
use ::log::{info, warn};

use esp_idf_sys::*;
use log::{info, warn};

use crate::ble::gatt_server::Profile;

impl Profile {
pub(crate) fn on_reg(&mut self, param: esp_ble_gatts_cb_param_t_gatts_reg_evt_param) {
Expand Down
6 changes: 4 additions & 2 deletions src/ble/gatt_server/gatts_event_handler/profile/start.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::ble::gatt_server::Profile;
use ::log::{debug, warn};

use esp_idf_sys::*;
use log::{debug, warn};

use crate::ble::gatt_server::Profile;

impl Profile {
pub(crate) fn on_start(&mut self, param: esp_ble_gatts_cb_param_t_gatts_start_evt_param) {
Expand Down
6 changes: 4 additions & 2 deletions src/ble/gatt_server/gatts_event_handler/profile/write.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use ::log::debug;

use esp_idf_sys::*;

use crate::ble::gatt_server::Profile;
use crate::ble::utilities::AttributeControl;
use esp_idf_sys::*;
use log::debug;

impl Profile {
#[allow(clippy::too_many_lines)]
Expand Down
3 changes: 2 additions & 1 deletion src/ble/gatt_server/gatts_event_handler/server/connect.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use ::log::info;

use crate::ble::gatt_server::GattServer;
use crate::ble::utilities::Connection;
use log::info;

impl GattServer {
pub(crate) fn on_connect(
Expand Down
3 changes: 2 additions & 1 deletion src/ble/gatt_server/gatts_event_handler/server/disconnect.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ::log::info;

use crate::ble::gatt_server::GattServer;
use log::info;

impl GattServer {
pub(crate) fn on_disconnect(
Expand Down
3 changes: 2 additions & 1 deletion src/ble/gatt_server/gatts_event_handler/server/mtu.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ::log::debug;

use crate::ble::gatt_server::GattServer;
use log::debug;

impl GattServer {
#[allow(clippy::unused_self)]
Expand Down
7 changes: 4 additions & 3 deletions src/ble/gatt_server/gatts_event_handler/server/reg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::ble::gatt_server::GattServer;
#[allow(clippy::wildcard_imports)]
use ::log::debug;

use esp_idf_sys::*;
use log::debug;

use crate::ble::gatt_server::GattServer;

impl GattServer {
pub(crate) fn on_reg(
Expand Down
3 changes: 2 additions & 1 deletion src/ble/gatt_server/gatts_event_handler/server/response.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ::log::debug;

use crate::ble::gatt_server::GattServer;
use log::debug;

impl GattServer {
#[allow(clippy::unused_self)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use ::log::{debug, warn};

use esp_idf_sys::*;

use crate::ble::gatt_server::GattServer;
use crate::ble::utilities::BleUuid;
use esp_idf_sys::*;
use log::{debug, warn};

impl GattServer {
#[allow(clippy::too_many_lines)]
Expand Down
29 changes: 14 additions & 15 deletions src/ble/gatt_server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
//! The GATT server.

#![allow(clippy::cast_possible_truncation)]
// Structs.
mod characteristic;
mod descriptor;
mod profile;
mod service;

// Custom stuff.
mod custom_attributes;

// Event handler.
mod gap_event_handler;
mod gatts_event_handler;

use alloc::{boxed::Box, sync::Arc};
use std::{collections::HashSet, sync::RwLock};

use ::log::{info, warn};

use esp_idf_sys::*;
use log::{info, warn};

use crate::{
ble::utilities::{Appearance, Connection},
Expand All @@ -18,19 +30,6 @@ pub use descriptor::Descriptor;
pub use profile::Profile;
pub use service::Service;

// Structs.
mod characteristic;
mod descriptor;
mod profile;
mod service;

// Custom stuff.
mod custom_attributes;

// Event handler.
mod gap_event_handler;
mod gatts_event_handler;

type Singleton<T> = Mutex<Option<Box<T>>>;

/// The GATT server singleton.
Expand Down
6 changes: 4 additions & 2 deletions src/ble/gatt_server/profile.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::sync::{Arc, RwLock};

use crate::ble::gatt_server::service::Service;
use ::log::debug;

use esp_idf_sys::*;
use log::debug;

use crate::ble::gatt_server::service::Service;

/// Represents a GATT profile.
///
Expand Down
13 changes: 7 additions & 6 deletions src/ble/gatt_server/service.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use core::fmt::Formatter;
use std::sync::{Arc, RwLock};

use ::log::debug;

use esp_idf_sys::*;

use crate::{
ble::gatt_server::characteristic::Characteristic, ble::gatt_server::descriptor::Descriptor,
ble::utilities::BleUuid,
};
use esp_idf_sys::*;
use log::debug;
use std::{
fmt::Formatter,
sync::{Arc, RwLock},
};

/// Represents a GATT service.
#[derive(Debug, Clone)]
Expand Down
3 changes: 2 additions & 1 deletion src/ble/utilities/attribute_control.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use esp_idf_sys::*;
use std::sync::Arc;

use esp_idf_sys::*;

#[derive(Clone)]
pub(crate) enum AttributeControl {
ResponseByApp(
Expand Down
3 changes: 2 additions & 1 deletion src/ble/utilities/characteristic_properties.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ::log::warn;

use esp_idf_sys::*;
use log::warn;

/// Represents the properties of a [`Characteristic`].
///
Expand Down

0 comments on commit 7db231f

Please sign in to comment.