Skip to content

Commit ee2de56

Browse files
committed
small changes
1 parent 6b8c3a1 commit ee2de56

File tree

9 files changed

+26
-41
lines changed

9 files changed

+26
-41
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
build/
2-
sdkconfig
2+
sdkconfig
3+
sdkconfig.old

components/ble/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ set(srcs "gap.c" "gatt.c" "ble.c")
33
idf_component_register(SRCS "${srcs}"
44
INCLUDE_DIRS "include"
55
REQUIRES bt
6-
PRIV_REQUIRES nimble_peripheral_utils)
6+
PRIV_REQUIRES nimble_peripheral_utils ssd1306)

components/ble/ble.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ void initBLE(){
7676
void bleOnSync(void){
7777
int rc;
7878

79-
/* Generate a non-resolvable private address. */
80-
//ble_app_set_addr();
81-
8279
ble_hs_pvcy_rpa_config(1);
8380

8481
/* Make sure we have proper identity address set (public preferred) */
@@ -90,7 +87,12 @@ void bleOnSync(void){
9087
assert(rc == 0);
9188

9289
uint8_t addr_val[6] = {0};
93-
rc = ble_hs_id_copy_addr(bleAddressType, addr_val, NULL);
90+
if(BLE_HS_ENOADDR == ble_hs_id_copy_addr(BLE_ADDR_PUBLIC, addr_val, NULL)) {
91+
ble_hs_id_copy_addr(BLE_ADDR_RANDOM, addr_val, NULL);
92+
ESP_LOGI(tag_BLE, "Device Address-Type: random");
93+
} else {
94+
ESP_LOGI(tag_BLE, "Device Address-Type: public");
95+
}
9496

9597
ESP_LOGI(tag_BLE, "Device Address: ");
9698
print_addr(addr_val);

components/ble/gap.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
* o Undirected connectable mode
77
*/
88
void bleAdvertise(void){
9+
ssd1306_clear();
10+
ssd1306_setString("Connecting",10,9);
11+
ssd1306_display();
12+
913
struct ble_gap_adv_params adv_params;
1014
struct ble_hs_adv_fields fields;
1115
int rc;
@@ -81,6 +85,10 @@ int bleGAPEevent(struct ble_gap_event *event, void *arg) {
8185
/* Connection failed; resume advertising */
8286
bleAdvertise();
8387
} else {
88+
ssd1306_clear();
89+
ssd1306_display();
90+
91+
8492
struct ble_gap_upd_params connectionParameters = {
8593
//itvl: These determine how often the devices will "ping-pong" each other and also when they will send any data required. So if you set the value to something like 20, that would mean packets are sent every 25ms, which will obviously consume more power than say a value of 80 (100ms). The reason for the min max values is so the devices can negotiate a compromise for the best possible communication, you can set these to the same value if you prefer.
8694
.itvl_min = (int)(11.25/1.25), //1.25ms units; laut apple 11.25 minimum fuer hid
@@ -101,15 +109,20 @@ int bleGAPEevent(struct ble_gap_event *event, void *arg) {
101109

102110
case BLE_GAP_EVENT_DISCONNECT:
103111
ESP_LOGI(tag_GAP, "disconnect; reason=%d\n", event->disconnect.reason);
112+
ESP_LOGI(tag_GAP, "%d",event->disconnect.conn.conn_handle);
113+
print_addr(event->disconnect.conn.peer_id_addr.val);
104114
//531 = Remote User Terminated Connection
115+
//517 = Authentication Failure
105116

106117
/* Connection terminated; resume advertising */
107118
bleAdvertise();
108119
break;
109120

110121
case BLE_GAP_EVENT_ADV_COMPLETE:
111122
ESP_LOGI(tag_GAP, "adv complete; reason = %d\n", event->adv_complete.reason);
112-
bleAdvertise();
123+
if(event->adv_complete.reason != 0){
124+
bleAdvertise();
125+
}
113126
break;
114127

115128
case BLE_GAP_EVENT_SUBSCRIBE:
@@ -149,7 +162,7 @@ int bleGAPEevent(struct ble_gap_event *event, void *arg) {
149162
* establish a new secure link. This app sacrifices security for
150163
* convenience: just throw away the old bond and accept the new link.
151164
*/
152-
ESP_LOGI(tag_GAP, "establisch new secure link");
165+
ESP_LOGI(tag_GAP, "establish new secure link");
153166

154167
/* Delete the old bond. */
155168
rc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc);

components/ble/include/gap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "gatt.h"
1212
#include "ble.h"
13+
#include "ssd1306.h"
1314

1415
static const char *tag_GAP = "SimLinkModule_GAP";
1516
static const ble_uuid16_t hid_service_uuid = BLE_UUID16_INIT(0x1812);

main/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
idf_component_register(SRCS "main.c" "gatt_svr.c"
1+
idf_component_register(SRCS "main.c"
22
INCLUDE_DIRS ".")

main/blehr_sens.h

Lines changed: 0 additions & 8 deletions
This file was deleted.

main/gatt_svr.c

Lines changed: 0 additions & 8 deletions
This file was deleted.

main/main.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,6 @@ static xTimerHandle blehr_tx_timer;
1111

1212
static bool volumeUp = true;
1313

14-
static void
15-
ble_app_set_addr(void)
16-
{
17-
ble_addr_t addr;
18-
int rc;
19-
20-
/* generate new non-resolvable private address */
21-
rc = ble_hs_id_gen_rnd(0, &addr);
22-
assert(rc == 0);
23-
24-
/* set generated address */
25-
rc = ble_hs_id_set_rnd(addr.val);
26-
27-
assert(rc == 0);
28-
}
29-
3014
/**
3115
* Utility function to log an array of bytes.
3216
*/

0 commit comments

Comments
 (0)