bt_scan_init()

bt_scan_init()

Description

Initializes Bluetooth scan module.

Syntax

bt_scan_init(scan_params[], connect_if_match);

Parameters

Variable

Array structure

Input

scan_params[]

.type

Scan type. Available options include:

BT_SCAN_TYPE_PASSIVE - passive scanning.

BT_SCAN_TYPE_ACTIVE - active scanning.

.options

Scan options. Available options include:

BT_SCAN_OPT_NONE - A convenience value indicating no options have been selected.

Additional options will be introduced in future iterations.

.interval

Scan interval value (N) is required to fall within the range of 4 to 16384 (0x04 to 0x4000), inclusive, and is converted into milliseconds using the formula: N * 0.625 ms.

For instance, if a value of 10 is provided, the resulting window duration would be calculated as 10 * 0.625 = 6.25 ms.

To facilitate quick initialization, the following convenience values have been included:

BT_SCAN_INTERVAL_FAST: Corresponds to an interval duration of 60 ms.

BT_SCAN_INTERVAL_SLOW_1: Corresponds to an interval duration of 1.28 s.

BT_SCAN_INTERVAL_SLOW_2: Corresponds to an interval duration of 2.56 s.

.window

Scan window value (N) is required to fall within the range of 4 to 16384 (0x04 to 0x4000), inclusive, and is converted into milliseconds using the formula: N * 0.625 ms. It is imperative that the Scan Window duration is equal to or less than the Scan Interval.

For instance, if a value of 10 is provided, the resulting window duration would be calculated as 10 * 0.625 = 6.25 ms.

To facilitate quick initialization, the following convenience values have been included:

BT_SCAN_WINDOW_FAST: Corresponds to a duration of 30 ms.

BT_SCAN_WINDOW_SLOW: Corresponds to a duration of 11.25 ms.

.timeout

This parameter dictates the duration for which the scanner will continue scanning before automatically halting. Assigning a value of zero will deactivate the timeout feature. Alternatively, specifying a numerical value, such as 2000, signifies that the scanner will cease scanning after 2 seconds. This timeout value can be adjusted in increments of 10 milliseconds. Notably, if a value like 5999 is provided, it will be rounded down to 5990.

Maximum value 0xFFFF (655350 ms)

.interval_coded

Scan interval value (N) is required to fall within the range of 4 to 16384 (0x04 to 0x4000), inclusive, and is converted into milliseconds using the formula: N * 0.625 ms.

For instance, if a value of 10 is provided, the resulting window duration would be calculated as 10 * 0.625 = 6.25 ms.

Specify a value of zero to utilize the identical scan window duration as the Low Energy (LE) 1M Physical Layer (PHY) scan.

.window_coded

Scan window value (N) is required to fall within the range of 4 to 16384 (0x04 to 0x4000), inclusive, and is converted into milliseconds using the formula: N * 0.625 ms. It is imperative that the Scan Window duration is equal to or less than the Scan Interval.

For instance, if a value of 10 is provided, the resulting window duration would be calculated as 10 * 0.625 = 6.25 ms.

Specify a value of zero to utilize the identical scan window duration as the Low Energy (LE) 1M Physical Layer (PHY) scan.

connect_if_match

 

This variable is used when a user searches for a device using filters. Upon finding the first matching device, it will attempt to establish a connection. Accepts only two possible values: true or false.

Returns

Return value

Return explanation

SCRIPT_OPERATION_SUCCESS

Successfully initialized Bluetooth scan module.

SCRIPT_OPERATION_FAILED

Failed initialize Bluetooth scan module.

SCRIPT_PARAM_INVALID

Invalid parameters. This error means that one or more incorrect parameters was passed into the function.

Function call example

#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> #include <bluetooth> new scan_parameters[.type, .options, .interval, .window, .timeout, .interval_coded, .window_coded]; main() { scan_parameters[.type] = BT_SCAN_TYPE_ACTIVE; scan_parameters[.options] = BT_ADV_OPT_NONE; scan_parameters[.interval] = BT_SCAN_INTERVAL_FAST; scan_parameters[.window] = BT_SCAN_WINDOW_FAST; scan_parameters[.timeout] = 0; scan_parameters[.interval_coded] = 0; scan_parameters[.window_coded] = 0; bt_init(); bt_scan_init(scan_parameters, false); for(;;) { Delay(100); } }