Skip to content

Commit 5d3eb65

Browse files
committed
Use designated initializer for NimBLEScan::m_scanParams and guard disable_observer_mode field for ESP-IDF >= 5.4.2
The NimBLEScan constructor previously used positional struct initialization, which no longer matches the ble_gap_disc_params layout in newer ESP-IDF versions (>= 5.4.2) where the field `disable_observer_mode` was added. This is caused by -Wmissing-field-initializers. Switch to designated initializers to make the field assignments explicit and more robust across ESP-IDF/NimBLE revisions. The new field is only initialized when building against ESP-IDF 5.4.2 or later to maintain backwards compatibility.
1 parent 002abf9 commit 5d3eb65

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/NimBLEScan.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,20 @@ static NimBLEScanCallbacks defaultScanCallbacks;
3232
*/
3333
NimBLEScan::NimBLEScan()
3434
: m_pScanCallbacks{&defaultScanCallbacks},
35-
// default interval + window, no whitelist scan filter,not limited scan, no scan response, filter_duplicates
36-
m_scanParams{0, 0, BLE_HCI_SCAN_FILT_NO_WL, 0, 1, 1},
35+
m_scanParams{
36+
.itvl = 0, // default interval
37+
.window = 0, // default window
38+
.filter_policy = BLE_HCI_SCAN_FILT_NO_WL, // no whitelist scan filter
39+
.limited = 0, // no limited scan
40+
.passive = 1, // no scan response
41+
.filter_duplicates = 1, // filter duplicates
42+
# if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 2)
43+
.disable_observer_mode = 0, // observer role enabled
44+
# endif
45+
},
3746
m_pTaskData{nullptr},
38-
m_maxResults{0xFF} {}
47+
m_maxResults{0xFF} {
48+
}
3949

4050
/**
4151
* @brief Scan destructor, release any allocated resources.

0 commit comments

Comments
 (0)