mirror of
https://github.com/esphome/esphome.git
synced 2026-08-24 07:06:20 +00:00
Merge branch 'esp32-tracker-parser-cleanup' into esp32-tracker-retire-scanner-listener
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#ifndef CONFIG_ESP_HOSTED_ENABLE_BT_BLUEDROID
|
||||
#include <esp_bt.h>
|
||||
#include <esp_mac.h>
|
||||
#else
|
||||
#include "esphome/components/watchdog/watchdog.h"
|
||||
#include <cinttypes>
|
||||
@@ -674,6 +675,23 @@ void ESP32BLE::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gat
|
||||
}
|
||||
#endif
|
||||
|
||||
void ESP32BLE::get_mac_msb_first(uint8_t out[6]) {
|
||||
#ifdef CONFIG_ESP_HOSTED_ENABLE_BT_BLUEDROID
|
||||
// The adapter MAC lives in the remote chip's efuse, so only the running
|
||||
// stack knows it.
|
||||
const uint8_t *mac = esp_bt_dev_get_address();
|
||||
if (mac != nullptr) {
|
||||
memcpy(out, mac, 6);
|
||||
} else {
|
||||
memset(out, 0, 6);
|
||||
}
|
||||
#else
|
||||
// IDF owns the BT-offset derivation (base + 2 with four universal MACs,
|
||||
// base + 1 with two); works before the BT stack is up.
|
||||
esp_read_mac(out, ESP_MAC_BT);
|
||||
#endif
|
||||
}
|
||||
|
||||
float ESP32BLE::get_setup_priority() const { return setup_priority::BLUETOOTH; }
|
||||
|
||||
void ESP32BLE::dump_config() {
|
||||
|
||||
@@ -108,6 +108,9 @@ class ESP32BLE final : public Component {
|
||||
void setup() override;
|
||||
void loop() override;
|
||||
void dump_config() override;
|
||||
/// Adapter MAC in printable (MSB-first) order. Hosted controllers only
|
||||
/// know it once the stack is up; all-zero means unavailable.
|
||||
void get_mac_msb_first(uint8_t out[6]);
|
||||
float get_setup_priority() const override;
|
||||
void set_name(const char *name) { this->name_ = name; }
|
||||
|
||||
|
||||
@@ -9,9 +9,7 @@
|
||||
|
||||
#ifndef CONFIG_ESP_HOSTED_ENABLE_BT_BLUEDROID
|
||||
#include <esp_bt.h>
|
||||
#include <esp_mac.h>
|
||||
#endif
|
||||
#include <esp_bt_device.h>
|
||||
#include <esp_bt_defs.h>
|
||||
#include <esp_bt_main.h>
|
||||
#include <esp_gap_ble_api.h>
|
||||
@@ -20,7 +18,6 @@
|
||||
#include <freertos/task.h>
|
||||
#include <nvs_flash.h>
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef USE_OTA
|
||||
#include "esphome/components/ota/ota_backend.h"
|
||||
@@ -288,24 +285,6 @@ void ESP32BLETracker::register_listener(ble_device_base::ESPBTDeviceListener *li
|
||||
#endif
|
||||
}
|
||||
|
||||
void ESP32BLETracker::get_adapter_mac(uint8_t out[6]) {
|
||||
#ifdef CONFIG_ESP_HOSTED_ENABLE_BT_BLUEDROID
|
||||
// Hosted controller (esp32-p4): the adapter MAC lives in the remote chip's
|
||||
// efuse, so only the running stack knows it; ESP_MAC_BT does not exist
|
||||
// here. Null before init becomes all-zero, the proxy's unavailable state.
|
||||
const uint8_t *mac = esp_bt_dev_get_address();
|
||||
if (mac != nullptr) {
|
||||
memcpy(out, mac, 6);
|
||||
} else {
|
||||
memset(out, 0, 6);
|
||||
}
|
||||
#else
|
||||
// IDF owns the BT-offset derivation (base + 2 with four universal MACs,
|
||||
// base + 1 with two); works before the BT stack is up.
|
||||
esp_read_mac(out, ESP_MAC_BT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ESP32BLETracker::register_listener(ESPBTDeviceListener *listener) {
|
||||
#ifdef ESPHOME_ESP32_BLE_TRACKER_LISTENER_COUNT
|
||||
listener->set_parent(this);
|
||||
|
||||
@@ -196,7 +196,7 @@ class ESP32BLETracker final : public Component,
|
||||
return {/* active_scan = */ true, /* merges_scan_response = */ true, /* gatt = */ true,
|
||||
/* scan_mode_switch = */ false};
|
||||
}
|
||||
void get_adapter_mac(uint8_t out[6]) override;
|
||||
void get_adapter_mac(uint8_t out[6]) override { this->parent_->get_mac_msb_first(out); }
|
||||
bool scan_running() override { return this->scanner_state_ == ScannerState::RUNNING; }
|
||||
bool scan_active() override { return this->scan_active_; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user