mirror of
https://github.com/meshtastic/firmware.git
synced 2025-05-06 13:48:29 +00:00
move bluetooth enable
This commit is contained in:
parent
abdc4dfae8
commit
107b56a346
@ -1,4 +1,3 @@
|
|||||||
#include "MeshBluetoothService.h"
|
|
||||||
#include "PowerFSM.h"
|
#include "PowerFSM.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "esp_task_wdt.h"
|
#include "esp_task_wdt.h"
|
||||||
@ -10,30 +9,6 @@
|
|||||||
#include <nvs.h>
|
#include <nvs.h>
|
||||||
#include <nvs_flash.h>
|
#include <nvs_flash.h>
|
||||||
|
|
||||||
bool bluetoothOn;
|
|
||||||
|
|
||||||
// Enable/disable bluetooth.
|
|
||||||
void setBluetoothEnable(bool on)
|
|
||||||
{
|
|
||||||
if (on != bluetoothOn) {
|
|
||||||
DEBUG_MSG("Setting bluetooth enable=%d\n", on);
|
|
||||||
|
|
||||||
bluetoothOn = on;
|
|
||||||
if (on) {
|
|
||||||
Serial.printf("Pre BT: %u heap size\n", ESP.getFreeHeap());
|
|
||||||
// ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
|
|
||||||
reinitBluetooth();
|
|
||||||
} else {
|
|
||||||
// We have to totally teardown our bluetooth objects to prevent leaks
|
|
||||||
stopMeshBluetoothService(); // Must do before shutting down bluetooth
|
|
||||||
deinitBLE();
|
|
||||||
destroyMeshBluetoothService(); // must do after deinit, because it frees our service
|
|
||||||
Serial.printf("Shutdown BT: %u heap size\n", ESP.getFreeHeap());
|
|
||||||
// ESP_ERROR_CHECK( heap_trace_stop() );
|
|
||||||
// heap_trace_dump();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void getMacAddr(uint8_t *dmac)
|
void getMacAddr(uint8_t *dmac)
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "BluetoothUtil.h"
|
#include "BluetoothUtil.h"
|
||||||
#include "BluetoothSoftwareUpdate.h"
|
#include "BluetoothSoftwareUpdate.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
#include "esp_bt.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <BLE2902.h>
|
#include <BLE2902.h>
|
||||||
#include <Update.h>
|
#include <Update.h>
|
||||||
@ -179,7 +180,10 @@ void deinitBLE()
|
|||||||
|
|
||||||
ret = ble_gatts_reset(); // Teardown the service tables, so the next restart assigns the same handle numbers
|
ret = ble_gatts_reset(); // Teardown the service tables, so the next restart assigns the same handle numbers
|
||||||
assert(ret == ESP_OK);
|
assert(ret == ESP_OK);
|
||||||
|
#if 0
|
||||||
|
auto ret = esp_bt_controller_disable();
|
||||||
|
assert(ret == ESP_OK);
|
||||||
|
#endif
|
||||||
DEBUG_MSG("Done shutting down bluetooth\n");
|
DEBUG_MSG("Done shutting down bluetooth\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,11 +499,9 @@ void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
|
|||||||
// This routine is called multiple times, once each time we come back from sleep
|
// This routine is called multiple times, once each time we come back from sleep
|
||||||
void reinitBluetooth()
|
void reinitBluetooth()
|
||||||
{
|
{
|
||||||
DEBUG_MSG("Starting bluetooth\n");
|
|
||||||
esp_log_level_set("BTDM_INIT", ESP_LOG_VERBOSE);
|
|
||||||
|
|
||||||
auto isFirstTime = !bluetoothPhoneAPI;
|
auto isFirstTime = !bluetoothPhoneAPI;
|
||||||
|
|
||||||
|
DEBUG_MSG("Starting bluetooth\n");
|
||||||
if (isFirstTime) {
|
if (isFirstTime) {
|
||||||
bluetoothPhoneAPI = new BluetoothPhoneAPI();
|
bluetoothPhoneAPI = new BluetoothPhoneAPI();
|
||||||
bluetoothPhoneAPI->init();
|
bluetoothPhoneAPI->init();
|
||||||
@ -530,8 +532,8 @@ void reinitBluetooth()
|
|||||||
ble_svc_gap_init();
|
ble_svc_gap_init();
|
||||||
ble_svc_gatt_init();
|
ble_svc_gatt_init();
|
||||||
|
|
||||||
res = ble_gatts_count_cfg(
|
res = ble_gatts_count_cfg(gatt_svr_svcs); // assigns handles? see docstring for note about clearing the handle list
|
||||||
gatt_svr_svcs); // assigns handles? see docstring for note about clearing the handle list before calling SLEEP SUPPORT
|
// before calling SLEEP SUPPORT
|
||||||
assert(res == 0);
|
assert(res == 0);
|
||||||
|
|
||||||
res = ble_gatts_add_svcs(gatt_svr_svcs);
|
res = ble_gatts_add_svcs(gatt_svr_svcs);
|
||||||
@ -546,3 +548,26 @@ void reinitBluetooth()
|
|||||||
|
|
||||||
nimble_port_freertos_init(ble_host_task);
|
nimble_port_freertos_init(ble_host_task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool bluetoothOn;
|
||||||
|
|
||||||
|
// Enable/disable bluetooth.
|
||||||
|
void setBluetoothEnable(bool on)
|
||||||
|
{
|
||||||
|
if (on != bluetoothOn) {
|
||||||
|
DEBUG_MSG("Setting bluetooth enable=%d\n", on);
|
||||||
|
|
||||||
|
bluetoothOn = on;
|
||||||
|
if (on) {
|
||||||
|
Serial.printf("Pre BT: %u heap size\n", ESP.getFreeHeap());
|
||||||
|
// ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
|
||||||
|
reinitBluetooth();
|
||||||
|
} else {
|
||||||
|
// We have to totally teardown our bluetooth objects to prevent leaks
|
||||||
|
deinitBLE();
|
||||||
|
Serial.printf("Shutdown BT: %u heap size\n", ESP.getFreeHeap());
|
||||||
|
// ESP_ERROR_CHECK( heap_trace_stop() );
|
||||||
|
// heap_trace_dump();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user