From 126954c2edee391e174e55caab0b068384c17cd6 Mon Sep 17 00:00:00 2001 From: Mike Robbins Date: Sun, 19 Oct 2025 11:10:14 -0400 Subject: [PATCH] NimbleBluetooth: reuse BLE_HS_CONN_HANDLE_NONE instead of creating a different constant to represent no connection --- src/nimble/NimbleBluetooth.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index 4c9590103..6238031f6 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -49,7 +49,7 @@ NimBLECharacteristic *logRadioCharacteristic; NimBLEServer *bleServer; static bool passkeyShowing; -static std::atomic nimbleBluetoothConnHandle{-1}; // actual handles are uint16_t, so -1 means "no connection" +static std::atomic nimbleBluetoothConnHandle{BLE_HS_CONN_HANDLE_NONE}; // BLE_HS_CONN_HANDLE_NONE means "no connection" class BluetoothPhoneAPI : public PhoneAPI, public concurrency::OSThread { @@ -178,9 +178,9 @@ class BluetoothPhoneAPI : public PhoneAPI, public concurrency::OSThread // Prefer high throughput during config/setup, at the cost of high power consumption (for a few seconds) if (bleServer && isConnected()) { - int32_t conn_handle = nimbleBluetoothConnHandle.load(); - if (conn_handle != -1) { - requestHighThroughputConnection(static_cast(conn_handle)); + uint16_t conn_handle = nimbleBluetoothConnHandle.load(); + if (conn_handle != BLE_HS_CONN_HANDLE_NONE) { + requestHighThroughputConnection(conn_handle); } } } @@ -191,9 +191,9 @@ class BluetoothPhoneAPI : public PhoneAPI, public concurrency::OSThread // Switch to lower power consumption BLE connection params for steady-state use after config/setup is complete if (bleServer && isConnected()) { - int32_t conn_handle = nimbleBluetoothConnHandle.load(); - if (conn_handle != -1) { - requestLowerPowerConnection(static_cast(conn_handle)); + uint16_t conn_handle = nimbleBluetoothConnHandle.load(); + if (conn_handle != BLE_HS_CONN_HANDLE_NONE) { + requestLowerPowerConnection(conn_handle); } } } @@ -710,7 +710,7 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks // Clear the last ToRadio packet buffer to avoid rejecting first packet from new connection memset(lastToRadio, 0, sizeof(lastToRadio)); - nimbleBluetoothConnHandle = -1; // -1 means "no connection" + nimbleBluetoothConnHandle = BLE_HS_CONN_HANDLE_NONE; // BLE_HS_CONN_HANDLE_NONE means "no connection" #ifdef NIMBLE_TWO // Restart Advertising