From a72e02b84405422516cd85247a1950b3d42efaf2 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Wed, 23 Apr 2025 10:19:15 +0000 Subject: [PATCH] reverted the revert #6640 + increased speed, bleutooth is stable now on reconnection cold booth etc , GPS is still not working though --- arch/esp32/esp32.ini | 2 +- src/main.cpp | 3 ++- src/nimble/NimbleBluetooth.cpp | 17 +++++++++-------- variants/tbeam/variant.h | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/arch/esp32/esp32.ini b/arch/esp32/esp32.ini index 5e15cb451..35f3a5a1c 100644 --- a/arch/esp32/esp32.ini +++ b/arch/esp32/esp32.ini @@ -50,7 +50,7 @@ lib_deps = # renovate: datasource=git-refs depName=meshtastic-esp32_https_server packageName=https://github.com/meshtastic/esp32_https_server gitBranch=master https://github.com/meshtastic/esp32_https_server/archive/896f1771ceb5979987a0b41028bf1b4e7aad419b.zip # renovate: datasource=custom.pio depName=NimBLE-Arduino packageName=h2zero/library/NimBLE-Arduino - h2zero/NimBLE-Arduino@^1.4.3 + h2zero/NimBLE-Arduino@^2.2.3 # renovate: datasource=git-refs depName=libpax packageName=https://github.com/dbinfrago/libpax gitBranch=master https://github.com/dbinfrago/libpax/archive/3cdc0371c375676a97967547f4065607d4c53fd1.zip # renovate: datasource=custom.pio depName=XPowersLib packageName=lewisxhe/library/XPowersLib diff --git a/src/main.cpp b/src/main.cpp index f7a163915..3704681fe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1292,8 +1292,9 @@ void setup() PowerFSM_setup(); // we will transition to ON in a couple of seconds, FIXME, only do this for cold boots, not waking from SDS powerFSMthread = new PowerFSMThread(); -#if !HAS_TFT +#if !HAS_TFT && !USE_ST7796 setCPUFast(false); // 80MHz is fine for our slow peripherals + LOG_DEBUG("SLOW-CPU-SPEED"); #endif #ifdef ARDUINO_ARCH_ESP32 diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index 009439f25..208d8ae3c 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -49,7 +49,7 @@ static uint8_t lastToRadio[MAX_TO_FROM_RADIO_SIZE]; class NimbleBluetoothToRadioCallback : public NimBLECharacteristicCallbacks { - virtual void onWrite(NimBLECharacteristic *pCharacteristic) + virtual void onWrite(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo &connInfo) { LOG_DEBUG("To Radio onwrite"); auto val = pCharacteristic->getValue(); @@ -66,7 +66,7 @@ class NimbleBluetoothToRadioCallback : public NimBLECharacteristicCallbacks class NimbleBluetoothFromRadioCallback : public NimBLECharacteristicCallbacks { - virtual void onRead(NimBLECharacteristic *pCharacteristic) + virtual void onRead(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo &connInfo) { uint8_t fromRadioBytes[meshtastic_FromRadio_size]; size_t numBytes = bluetoothPhoneAPI->getFromRadio(fromRadioBytes); @@ -79,7 +79,7 @@ class NimbleBluetoothFromRadioCallback : public NimBLECharacteristicCallbacks class NimbleBluetoothServerCallback : public NimBLEServerCallbacks { - virtual uint32_t onPassKeyRequest() + virtual uint32_t onPassKeyDisplay() { uint32_t passkey = config.bluetooth.fixed_pin; @@ -125,7 +125,7 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks return passkey; } - virtual void onAuthenticationComplete(ble_gap_conn_desc *desc) + virtual void onAuthenticationComplete(NimBLEConnInfo &connInfo) { LOG_INFO("BLE authentication complete"); @@ -138,9 +138,9 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks } } - virtual void onDisconnect(NimBLEServer *pServer, ble_gap_conn_desc *desc) + virtual void onDisconnect(NimBLEServer *pServer, NimBLEConnInfo &connInfo, int reason) { - LOG_INFO("BLE disconnect"); + LOG_INFO("BLE disconnect. Reason %i", reason); bluetoothStatus->updateStatus( new meshtastic::BluetoothStatus(meshtastic::BluetoothStatus::ConnectionState::DISCONNECTED)); @@ -191,7 +191,7 @@ int NimbleBluetooth::getRssi() if (bleServer && isConnected()) { auto service = bleServer->getServiceByUUID(MESH_SERVICE_UUID); uint16_t handle = service->getHandle(); - return NimBLEDevice::getClientByID(handle)->getRssi(); + return NimBLEDevice::getClientByHandle(handle)->getRssi(); } return 0; // FIXME figure out where to source this } @@ -216,6 +216,7 @@ void NimbleBluetooth::setup() NimbleBluetoothServerCallback *serverCallbacks = new NimbleBluetoothServerCallback(); bleServer->setCallbacks(serverCallbacks, true); + bleServer->advertiseOnDisconnect(true); setupService(); startAdvertising(); } @@ -259,7 +260,7 @@ void NimbleBluetooth::setupService() BatteryCharacteristic = batteryService->createCharacteristic( // 0x2A19 is the Battery Level characteristic) (uint16_t)0x2a19, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY, 1); - NimBLE2904 *batteryLevelDescriptor = (NimBLE2904 *)BatteryCharacteristic->createDescriptor((uint16_t)0x2904); + NimBLE2904 *batteryLevelDescriptor = (NimBLE2904 *)BatteryCharacteristic->create2904(); batteryLevelDescriptor->setFormat(NimBLE2904::FORMAT_UINT8); batteryLevelDescriptor->setNamespace(1); batteryLevelDescriptor->setUnit(0x27ad); diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index 1a86afed1..28cac821e 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -57,7 +57,7 @@ #define CANNED_MESSAGE_MODULE_ENABLE 1 #define USE_VIRTUAL_KEYBOARD 1 -#define MESHTASTIC_EXCLUDE_BLUETOOTH 1 +// #define MESHTASTIC_EXCLUDE_BLUETOOTH 1 #define ST7796_NSS 25 #define ST7796_RS 13 // DC