-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcble.c
53 lines (42 loc) · 1.25 KB
/
cble.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <flipper/flipper.h>
#include <flipper/screen.h>
#include <flipper/ble.h>
// BLE scanning callback
void ble_scan_callback(ble_gap_evt_adv_report_t *report, void *context) {
int *devices_count = (int *)context;
(*devices_count)++;
}
int main(void) {
// Initialize Flipper Zero
flipper_init();
// Initialize screen
screen_init();
screen_clear();
screen_print("Scanning BLE devices...");
// Initialize BLE
ble_init();
int devices_count = 0;
// Set up scanning parameters
ble_scan_parameters_t scan_params = {
.interval = 0x00A0,
.window = 0x0050,
.filter_policy = BLE_SCAN_FILTER_ALLOW_ALL,
.active = 1,
.timeout = 10, // Scan for 10 seconds
.callback = ble_scan_callback,
.context = &devices_count,
};
// Start scanning for BLE devices
ble_scan_start(&scan_params);
// Wait for the scan to complete
delay_ms(scan_params.timeout * 1000);
// Print the number of devices found
screen_clear();
screen_print("BLE devices found:");
screen_printf("\n\n%d", devices_count);
// Deinitialize
ble_deinit();
screen_deinit();
flipper_deinit();
return 0;
}