Fix BLE pairing display and RX gain defaults

This commit is contained in:
mikecarper committed 2026-08-10 19:42:44 -07:00
1 parent 968ca3363b
commit 2ff1166c15
22 files changed
+297 -39

No files matched your search

+14 -1
View File
@@ -90,6 +90,18 @@ public:
return false;
}
bool isBluetoothConnected() const {
if (!_enabled) return false;
for (auto iface : _interfaces) {
if (iface.instance && iface.type == InterfaceType::Bluetooth
&& iface.instance->isEnabled() && iface.instance->isConnected()) {
return true;
}
}
return false;
}
// enable all interfaces
void enable() override {
_enabled = true;
@@ -181,7 +193,8 @@ public:
bool takePairingRequest() override {
for (auto iface : _interfaces) {
if (iface.instance && iface.instance->isEnabled()
if (iface.instance && iface.type == InterfaceType::Bluetooth
&& iface.instance->isEnabled()
&& iface.instance->takePairingRequest()) {
return true;
}
+7 -1
View File
@@ -35,6 +35,7 @@ static bool isBondAuthenticationFailure(uint8_t reason) {
void SerialBLEInterface::onConnect(uint16_t connection_handle) {
BLE_DEBUG_PRINTLN("SerialBLEInterface: connected handle=0x%04X", connection_handle);
if (instance) {
instance->_pairingRequestPending.store(false, std::memory_order_release);
instance->_conn_handle = connection_handle;
instance->_isDeviceConnected = false;
instance->_security_timer.start(millis());
@@ -46,6 +47,7 @@ void SerialBLEInterface::onDisconnect(uint16_t connection_handle, uint8_t reason
BLE_DEBUG_PRINTLN("SerialBLEInterface: disconnected handle=0x%04X reason=%u", connection_handle, reason);
if (instance) {
if (instance->_conn_handle == connection_handle) {
instance->_pairingRequestPending.store(false, std::memory_order_release);
instance->_conn_handle = BLE_CONN_HANDLE_INVALID;
instance->_isDeviceConnected = false;
instance->_security_timer.cancel();
@@ -99,9 +101,11 @@ void SerialBLEInterface::onSecured(uint16_t connection_handle) {
}
bool SerialBLEInterface::onPairingPasskey(uint16_t connection_handle, uint8_t const passkey[6], bool match_request) {
(void)connection_handle;
(void)passkey;
BLE_DEBUG_PRINTLN("SerialBLEInterface: pairing passkey request match=%d", match_request);
if (instance && instance->isValidConnection(connection_handle)) {
instance->_pairingRequestPending.store(true, std::memory_order_release);
}
return true;
}
@@ -397,6 +401,7 @@ bool SerialBLEInterface::isAdvertising() const {
void SerialBLEInterface::enable() {
if (_isEnabled) return;
_pairingRequestPending.store(false, std::memory_order_release);
_isEnabled = true;
clearBuffers();
_last_health_check = millis();
@@ -413,6 +418,7 @@ void SerialBLEInterface::disconnect() {
void SerialBLEInterface::disable() {
_isEnabled = false;
_pairingRequestPending.store(false, std::memory_order_release);
BLE_DEBUG_PRINTLN("SerialBLEInterface: disable");
Bluefruit.Advertising.restartOnDisconnect(false);
+5
View File
@@ -4,6 +4,7 @@
#include "../BleTxStallWatchdog.h"
#include "SecuritySessionTimer.h"
#include <bluefruit.h>
#include <atomic>
#ifndef BLE_TX_POWER
#define BLE_TX_POWER 4
@@ -20,6 +21,7 @@ class SerialBLEInterface : public BaseSerialInterface {
ble_gap_addr_t _peer_address = {};
bool _peer_address_valid;
bool _bond_removed_for_connection;
std::atomic<bool> _pairingRequestPending{false};
SecuritySessionTimer _security_timer;
mesh::BleTxStallWatchdog _tx_stall_watchdog;
mesh::BleDisconnectRecovery _tx_disconnect_recovery;
@@ -83,6 +85,9 @@ public:
bool isReadBusy() const override;
bool isWriteBusy() const override;
bool hasPendingIO() const override;
bool takePairingRequest() override {
return _pairingRequestPending.exchange(false, std::memory_order_acq_rel);
}
size_t writeFrame(const uint8_t src[], size_t len) override;
size_t checkRecvFrame(uint8_t dest[]) override;
};
+2
View File
@@ -16,6 +16,8 @@ inline void lr11x0ResetAGC(LR11x0* radio, float freqMHz) {
radio->calibrateImageRejection(freqMHz - 4.0f, freqMHz + 4.0f);
#ifdef RX_BOOSTED_GAIN
// Fallback for callers without a runtime override. RadioLibWrapper::resetAGC()
// reapplies its cached radio.rxgain selection before receive mode resumes.
radio->setRxBoostedGainMode(RX_BOOSTED_GAIN);
#endif
}
@@ -0,0 +1,33 @@
#pragma once
#include <stdint.h>
namespace mesh {
namespace radio {
// SX126x targets use SX126X_RX_BOOSTED_GAIN while LR11xx and several other
// radios use RX_BOOSTED_GAIN. Keep persisted first-install defaults aligned
// with whichever target-level setting initialized the physical radio.
constexpr uint8_t selectRxBoostedGainDefault(bool sx_configured,
int sx_value,
bool generic_configured,
int generic_value,
uint8_t fallback = 1) {
return sx_configured ? (sx_value ? 1 : 0)
: (generic_configured ? (generic_value ? 1 : 0)
: (fallback ? 1 : 0));
}
inline uint8_t configuredRxBoostedGainDefault() {
#ifdef SX126X_RX_BOOSTED_GAIN
return selectRxBoostedGainDefault(true, SX126X_RX_BOOSTED_GAIN,
false, 0);
#elif defined(RX_BOOSTED_GAIN)
return selectRxBoostedGainDefault(false, 0, true, RX_BOOSTED_GAIN);
#else
return selectRxBoostedGainDefault(false, 0, false, 0);
#endif
}
} // namespace radio
} // namespace mesh
+2
View File
@@ -26,6 +26,8 @@ inline void sx126xResetAGC(SX126x* radio) {
radio->setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH);
#endif
#ifdef SX126X_RX_BOOSTED_GAIN
// Fallback for callers without a runtime override. RadioLibWrapper::resetAGC()
// reapplies its cached radio.rxgain selection before receive mode resumes.
radio->setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN);
#endif
#ifdef SX126X_REGISTER_PATCH