diff --git a/examples/nimble_scanner/main.c b/examples/nimble_scanner/main.c index f7ca6db35c..14f4f98122 100644 --- a/examples/nimble_scanner/main.c +++ b/examples/nimble_scanner/main.c @@ -30,6 +30,9 @@ #include "nimble_scanner.h" #include "nimble_scanlist.h" +/* default scan interval */ +#define DEFAULT_SCAN_INTERVAL_MS 30 + /* default scan duration (1s) */ #define DEFAULT_DURATION_MS (1 * MS_PER_SEC) @@ -39,6 +42,7 @@ int _cmd_scan(int argc, char **argv) if ((argc == 2) && (memcmp(argv[1], "help", 4) == 0)) { printf("usage: %s [timeout in ms]\n", argv[0]); + return 0; } if (argc >= 2) { @@ -46,11 +50,11 @@ int _cmd_scan(int argc, char **argv) } nimble_scanlist_clear(); - printf("Scanning for %"PRIu32" ms now ...", timeout); - nimble_scanner_set_scan_duration(timeout); + printf("Scanning for %"PRIu32" ms now ...\n", timeout); nimble_scanner_start(); ztimer_sleep(ZTIMER_MSEC, timeout); - puts(" done\n\nResults:"); + nimble_scanner_stop(); + puts("Done, results:"); nimble_scanlist_print(); puts(""); @@ -69,18 +73,19 @@ int main(void) /* in this example, we want Nimble to scan 'full time', so we set the * window equal the interval */ - struct ble_gap_disc_params scan_params = { - .itvl = BLE_GAP_LIM_DISC_SCAN_INT, - .window = BLE_GAP_LIM_DISC_SCAN_WINDOW, - .filter_policy = 0, /* don't use */ - .limited = 0, /* no limited discovery */ - .passive = 0, /* no passive scanning */ - . filter_duplicates = 0, /* no duplicate filtering */ + nimble_scanner_cfg_t params = { + .itvl_ms = DEFAULT_SCAN_INTERVAL_MS, + .win_ms = DEFAULT_SCAN_INTERVAL_MS, +#if IS_USED(MODULE_NIMBLE_PHY_CODED) + .flags = NIMBLE_SCANNER_PHY_1M | NIMBLE_SCANNER_PHY_CODED, +#else + .flags = NIMBLE_SCANNER_PHY_1M, +#endif }; /* initialize the nimble scanner */ nimble_scanlist_init(); - nimble_scanner_init(&scan_params, nimble_scanlist_update); + nimble_scanner_init(¶ms, nimble_scanlist_update); /* start shell */ char line_buf[SHELL_DEFAULT_BUFSIZE];