1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-12 23:03:46 +01:00
This commit is contained in:
J. Nick Koston
2025-10-09 10:39:41 -10:00
parent 8853593a7b
commit 36bcd8c204

View File

@@ -15,6 +15,10 @@
#include <freertos/task.h> #include <freertos/task.h>
#include <nvs_flash.h> #include <nvs_flash.h>
#ifdef USE_ARDUINO
#include <esp32-hal-bt.h>
#endif
namespace esphome::esp32_ble { namespace esphome::esp32_ble {
static const char *const TAG = "esp32_ble"; static const char *const TAG = "esp32_ble";
@@ -132,6 +136,12 @@ void ESP32BLE::advertising_init_() {
bool ESP32BLE::ble_setup_() { bool ESP32BLE::ble_setup_() {
esp_err_t err; esp_err_t err;
#ifdef USE_ARDUINO
if (!btStart()) {
ESP_LOGE(TAG, "btStart failed: %d", esp_bt_controller_get_status());
return false;
}
#else
if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) { if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) {
// start bt controller // start bt controller
if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE) { if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE) {
@@ -156,6 +166,7 @@ bool ESP32BLE::ble_setup_() {
return false; return false;
} }
} }
#endif
esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT);
@@ -247,6 +258,12 @@ bool ESP32BLE::ble_dismantle_() {
return false; return false;
} }
#ifdef USE_ARDUINO
if (!btStop()) {
ESP_LOGE(TAG, "btStop failed: %d", esp_bt_controller_get_status());
return false;
}
#else
if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_IDLE) { if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_IDLE) {
// stop bt controller // stop bt controller
if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED) { if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED) {
@@ -270,6 +287,7 @@ bool ESP32BLE::ble_dismantle_() {
return false; return false;
} }
} }
#endif
return true; return true;
} }