10000 Tue Mar 28 18:55:13 CDT 2017 · mwerschy/esp32-snippets@fc15f44 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc15f44

Browse files
author
kolban
committed
Tue Mar 28 18:55:13 CDT 2017
1 parent b15185b commit fc15f44

File tree

335 files changed

+24062
-19
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

335 files changed

+24062
-19
lines changed

cpp_utils/BLE.cpp

Lines changed: 404 additions & 0 deletions
Large diffs are not rendered by default.

cpp_utils/BLE.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* BLE.h
3+
*
4+
* Created on: Mar 16, 2017
5+
* Author: kolban
6+
*/
7+
8+
#ifndef MAIN_BLE_H_
9+
#define MAIN_BLE_H_
10+
#include "sdkconfig.h"
11+
#if defined(CONFIG_BT_ENABLED)
12+
#include <esp_gap_ble_api.h> // ESP32 BLE
13+
#include <esp_gattc_api.h> // ESP32 BLE
14+
#include <map> // Part of C++ STL
15+
16+
#include "BLEDevice.h"
17+
#include "BLEUtils.h"
18+
/**
19+
* @brief %BLE functions.
20+
*/
21+
class BLE {
22+
public:
23+
BLE();
24+
virtual ~BLE();
25+
static void dumpDevices();
26+
static std::map<ble_address, BLEDevice> getDevices();
27+
28+
static void init();
29+
static void scan(int duration, esp_ble_scan_type_t scan_type = BLE_SCAN_TYPE_PASSIVE);
30+
static esp_gatt_if_t getGattcIF();
31+
}; // class BLE
32+
33+
#endif // CONFIG_BT_ENABLED
34+
#endif /* MAIN_BLE_H_ */

cpp_utils/BLECharacteristic.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* BLECharacteristic.cpp
3+
*
4+
* Created on: Mar 26, 2017
5+
* Author: kolban
6+
*/
7+
8+
#include "sdkconfig.h"
9+
#if defined(CONFIG_BT_ENABLED)
10+
#include <esp_log.h>
11+
#include <esp_err.h>
12+
#include "BLECharacteristic.h"
13+
14+
extern "C" {
15+
char *espToString(esp_err_t value);
16+
}
17+
18+
static char tag[] = "BLECharacteristic";
19+
20+
BLECharacteristic::BLECharacteristic(
21+
uint16_t conn_id,
22+
esp_gatt_srvc_id_t srvc_id,
23+
esp_gatt_id_t char_id,
24+
esp_gatt_char_prop_t char_prop ) {
25+
m_conn_id = conn_id;
26+
m_srvc_id = srvc_id;
27+
m_char_id = char_id;
28+
m_char_prop = char_prop;
29+
}
30+
31+
BLECharacteristic::~BLECharacteristic() {
32+
}
33+
34+
void BLECharacteristic::nextCharacterisic(esp_gatt_if_t gattc_if) {
35+
esp_err_t errRc = esp_ble_gattc_get_characteristic(
36+
gattc_if,
37+
m_conn_id,
38+
&m_srvc_id,
39+
&m_char_id
40+
);
41+
if (errRc != ESP_OK) {
42+
ESP_LOGE(tag, "esp_ble_gattc_get_characteristic: rc=%d %s", errRc, espToString(errRc));
43+
return;
44+
}
45+
}
46+
#endif // CONFIG_BT_ENABLED

cpp_utils/BLECharacteristic.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* BLECharacteristic.h
3+
*
4+
* Created on: Mar 26, 2017
5+
* Author: kolban
6+
*/
7+
8+
#ifndef COMPONENTS_CPP_UTILS_BLECHARACTERISTIC_H_
9+
#define COMPONENTS_CPP_UTILS_BLECHARACTERISTIC_H_
10+
#include "sdkconfig.h"
11+
#if defined(CONFIG_BT_ENABLED)
12+
#include <esp_gattc_api.h>
13+
14+
15+
16+
17+
class BLECharacteristic {
18+
public:
19+
BLECharacteristic(
20+
uint16_t conn_id,
21+
esp_gatt_srvc_id_t srvc_id,
22+
esp_gatt_id_t char_id,
23+
esp_gatt_char_prop_t char_prop );
24+
virtual ~BLECharacteristic();
25+
26+
esp_gatt_srvc_id_t getSrvcId() {
27+
return m_srvc_id;
28+
}
29+
30+
esp_gatt_id_t getCharId() {
31+
return m_char_id;
32+
}
33+
34+
bool isAuth() {
35+
return m_char_prop & ESP_GATT_CHAR_PROP_BIT_AUTH;
36+
}
37+
bool isBroadcast() {
38+
return m_char_prop & ESP_GATT_CHAR_PROP_BIT_BROADCAST;
39+
}
40+
bool isExtProp() {
41+
return m_char_prop & ESP_GATT_CHAR_PROP_BIT_EXT_PROP;
42+
}
43+
bool isIndicate() {
44+
return m_char_prop & ESP_GATT_CHAR_PROP_BIT_INDICATE;
45+
}
46+
bool isNotify() {
47+
return m_char_prop & ESP_GATT_CHAR_PROP_BIT_NOTIFY;
48+
}
49+
bool isRead() {
50+
return m_char_prop & ESP_GATT_CHAR_PROP_BIT_READ;
51+
}
52+
53+
bool isWrite() {
54+
return m_char_prop & ESP_GATT_CHAR_PROP_BIT_WRITE;
55+
}
56+
bool isWrite_NR() {
57+
return m_char_prop & ESP_GATT_CHAR_PROP_BIT_WRITE_NR;
58+
}
59+
60+
void nextCharacterisic(esp_gatt_if_t gattc_if);
61+
62+
private:
63+
esp_gatt_char_prop_t m_char_prop;
64+
uint16_t m_conn_id;
65+
esp_gatt_srvc_id_t m_srvc_id;
66+
67+
// Contains esp_bt_uuid_t uuid and uint8_t inst_id
68+
esp_gatt_id_t m_char_id;
69+
};
70+
#endif // CONFIG_BT_ENABLED
71+
#endif /* COMPONENTS_CPP_UTILS_BLECHARACTERISTIC_H_ */

0 commit comments

Comments
 (0)
0