Skip to content

Commit 9db0561

Browse files
committed
removed unnecessary component and display output updated
1 parent a11f762 commit 9db0561

File tree

13 files changed

+79
-238
lines changed

13 files changed

+79
-238
lines changed

components/ble/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ set(srcs "gap.c" "gatt.c" "ble.c")
22

33
idf_component_register(SRCS "${srcs}"
44
INCLUDE_DIRS "include"
5-
REQUIRES bt nimble_peripheral_utils ssd1306 crsf nvs_flash battery
5+
REQUIRES bt ssd1306 crsf nvs_flash battery
66
PRIV_REQUIRES )

components/ble/ble.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ void initBLE(){
4848
//BLE_SM_IO_CAP_KEYBOARD_ONLY = Keyboard only
4949
//BLE_SM_IO_CAP_NO_IO = just work
5050
//BLE_SM_IO_CAP_KEYBOARD_DISP = Keyboard and display
51-
ble_hs_cfg.sm_io_cap = BLE_SM_IO_CAP_NO_IO;
51+
//BLE_SM_IO_CAP_KEYBOARD_ONLY && BLE_SM_IO_CAP_KEYBOARD_DISP not implemented
52+
ble_hs_cfg.sm_io_cap = BLE_SM_IO_CAP_DISP_YES_NO;
5253
/*Security Manager secure connections flag
5354
if set proper flag in pairing request/response will be set. this results in using LE Secure Connections for pairing if also supported by remote device. Fallback to legacy pairing if not supported by remote.*/
5455
ble_hs_cfg.sm_sc = 1;

components/ble/gap.c

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ int bleGAPEevent(struct ble_gap_event *event, void *arg) {
9292
ssd1306_clear();
9393
ssd1306_display();
9494

95-
9695
struct ble_gap_upd_params connectionParameters = {
9796
//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.
9897
.itvl_min = (int)(11.25/1.25), //1.25ms units; laut apple 11.25 minimum fuer hid
@@ -167,6 +166,10 @@ int bleGAPEevent(struct ble_gap_event *event, void *arg) {
167166
case BLE_GAP_EVENT_ENC_CHANGE:
168167
ESP_LOGI(tag_GAP, "encryption change event; status=%d ",
169168
event->enc_change.status);
169+
if(event->enc_change.status == 0){
170+
ssd1306_setConnectedImage();
171+
ssd1306_display();
172+
}
170173
break;
171174
case BLE_GAP_EVENT_REPEAT_PAIRING:
172175
/* We already have a bond with the peer, but it is attempting to
@@ -187,46 +190,46 @@ int bleGAPEevent(struct ble_gap_event *event, void *arg) {
187190
break;
188191

189192
case BLE_GAP_EVENT_PASSKEY_ACTION:
193+
//https://community.nxp.com/t5/Wireless-Connectivity-Knowledge/KW36-Enabling-Out-Of-Band-Pairing-on-a-Bluetooth-LE-Central-and/tac-p/1238698
190194
ESP_LOGI(tag_GAP, "PASSKEY_ACTION_EVENT started \n");
191195

192196
struct ble_sm_io pkey = {0};
193197
int key = 0;
194198

195199
if (event->passkey.params.action == BLE_SM_IOACT_DISP) {
200+
//BLE_SM_IO_CAP_DISP_ONLY option
196201
pkey.action = event->passkey.params.action;
197-
pkey.passkey = 123456; // This is the passkey to be entered on peer
198-
ESP_LOGI(tag_GAP, "Enter passkey %d on the peer side", (int)pkey.passkey);
202+
pkey.passkey = 123456;
203+
204+
ssd1306_clear();
205+
ssd1306_setString("PIN",48,0);
206+
ssd1306_setString("123456",31,18);
207+
ssd1306_display();
208+
//display passkey for the other side 123456
209+
199210
rc = ble_sm_inject_io(event->passkey.conn_handle, &pkey);
200211
ESP_LOGI(tag_GAP, "ble_sm_inject_io result: %d\n", rc);
201212
} else if (event->passkey.params.action == BLE_SM_IOACT_NUMCMP) {
202-
ESP_LOGI(tag_GAP, "Passkey on device's display: %d", (int)event->passkey.params.numcmp);
203-
ESP_LOGI(tag_GAP, "Accept or reject the passkey through console in this format -> key Y or key N");
213+
//BLE_SM_IO_CAP_DISP_YES_NO option
214+
215+
//gegenseite kann auch mit yes oder no bestätigen den pin
216+
//verify with buttons Yes or No --> add timeout after x seconds
217+
char pinStr[12];
218+
snprintf(pinStr, 12,"%d", (int)event->passkey.params.numcmp);
219+
ssd1306_clear();
220+
ssd1306_setString(pinStr,0,0);
221+
ssd1306_setString("ja",0,18);
222+
ssd1306_setString("nein",128-43,18);
223+
ssd1306_display();
224+
204225
pkey.action = event->passkey.params.action;
205-
if (scli_receive_key(&key)) {
206-
pkey.numcmp_accept = key;
226+
if (true) {
227+
pkey.numcmp_accept = true;
207228
} else {
208229
pkey.numcmp_accept = 0;
209230
ESP_LOGE(tag_GAP, "Timeout! Rejecting the key");
210231
}
211-
rc = ble_sm_inject_io(event->passkey.conn_handle, &pkey);
212-
ESP_LOGI(tag_GAP, "ble_sm_inject_io result: %d\n", rc);
213-
} else if (event->passkey.params.action == BLE_SM_IOACT_OOB) {
214-
static uint8_t tem_oob[16] = {0};
215-
pkey.action = event->passkey.params.action;
216-
for (int i = 0; i < 16; i++) {
217-
pkey.oob[i] = tem_oob[i];
218-
}
219-
rc = ble_sm_inject_io(event->passkey.conn_handle, &pkey);
220-
ESP_LOGI(tag_GAP, "ble_sm_inject_io result: %d\n", rc);
221-
} else if (event->passkey.params.action == BLE_SM_IOACT_INPUT) {
222-
ESP_LOGI(tag_GAP, "Enter the passkey through console in this format-> key 123456");
223-
pkey.action = event->passkey.params.action;
224-
if (scli_receive_key(&key)) {
225-
pkey.passkey = key;
226-
} else {
227-
pkey.passkey = 0;
228-
ESP_LOGE(tag_GAP, "Timeout! Passing 0 as the key");
229-
}
232+
230233
rc = ble_sm_inject_io(event->passkey.conn_handle, &pkey);
231234
ESP_LOGI(tag_GAP, "ble_sm_inject_io result: %d\n", rc);
232235
}
@@ -235,6 +238,10 @@ int bleGAPEevent(struct ble_gap_event *event, void *arg) {
235238
//Represents a transmitted ATT notification or indication, or a
236239
//completed indication transaction.
237240
return 0;
241+
case BLE_GAP_EVENT_IDENTITY_RESOLVED:
242+
ssd1306_setConnectedImage();
243+
ssd1306_display();
244+
return 0;
238245
default:
239246
ESP_LOGI(tag_GAP, "GAP EVENT ID: %d\n",event->type);
240247
}

components/ble/include/gap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <string.h>
55

66
#include "host/ble_hs.h"
7-
#include "esp_peripheral.h"
87

98
#include "esp_log.h"
109

components/nimble_peripheral_utils/CMakeLists.txt

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

components/nimble_peripheral_utils/esp_peripheral.h

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

components/nimble_peripheral_utils/misc.c

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

components/nimble_peripheral_utils/scli.c

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

components/ssd1306/include/ssd1306.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,6 @@ void ssd1306_display();
7575
void ssd1306_setPixel(uint8_t x, uint8_t y, bool status);
7676
void ssd1306_setChar(char c, uint8_t x, uint8_t y);
7777
void ssd1306_setString(const char* str, uint8_t x, uint8_t y);
78+
void ssd1306_setConnectedImage();
7879

7980
#endif
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef SSD1306_IMAGES_H
2+
#define SSD1306_IMAGES_H
3+
4+
//drawn in: https://www.pixilart.com/draw
5+
//converted from png to bitstring with: https://www.dcode.fr/binary-image
6+
//convert bitstring to hex array: Bin2Hex.py <filename> in tools folder
7+
8+
const uint8_t connectedImage[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xF8,0xFC,0xFC,0xFC,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFC,0xFC,0xFC,0xF8,0xF8,0xF0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xE0,0xE0,0x60,0x60,0x60,0x60,0xE0,0xC0,0xC0,0xC0,0xC0,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0xF0,0xFC,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x06,0x06,0x06,0x06,0x06,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0xF0,0xE0,0xE0,0x60,0x60,0x60,0x70,0x30,0x30,0x30,0x38,0x18,0x18,0x18,0x18,0x18,0x1C,0x0C,0x0E,0x0E,0x06,0x06,0x06,0x06,0x0E,0x0C,0x0C,0x0C,0x0C,0x0C,0x1C,0x1C,0x18,0x18,0x38,0x38,0x30,0x30,0x70,0xE0,0xE0,0xC0,0x80,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x03,0x03,0x07,0x06,0x0E,0x0E,0x0C,0x1C,0x18,0x18,0x18,0x18,0x18,0x1C,0x0C,0x0C,0x0C,0x0C,0x0E,0x0E,0x06,0x06,0x06,0x07,0x03,0x03,0x03,0x03,0x01,0x01,0x0F,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x60,0x60,0x60,0x60,0x60,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x1F,0x3F,0x3F,0x3F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x00,0x00,0x00,0x00,0x00,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x3F,0x3F,0x3F,0x1F,0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
9+
10+
#endif

0 commit comments

Comments
 (0)