mirror of
https://github.com/esphome/esphome.git
synced 2026-02-27 17:34:22 -07:00
dry
This commit is contained in:
@@ -444,27 +444,30 @@ void ESP32BLE::loop() {
|
||||
ESP_LOGV(TAG, "gap_event_handler - %d", gap_event);
|
||||
#ifdef ESPHOME_ESP32_BLE_GAP_EVENT_HANDLER_COUNT
|
||||
{
|
||||
// Determine which union member to use based on event type.
|
||||
// All event structures are properly laid out in memory per ESP-IDF.
|
||||
// The reinterpret_cast operations are safe because:
|
||||
// 1. Structure sizes match ESP-IDF expectations (verified by static_assert in ble_event.h)
|
||||
// 2. Status fields are at offset 0 (verified by static_assert in ble_event.h)
|
||||
// 3. The struct already contains our copy of the data (copied in BLEEvent constructor)
|
||||
esp_ble_gap_cb_param_t *param;
|
||||
// clang-format off
|
||||
switch (gap_event) {
|
||||
// All three scan complete events have the same structure with just status
|
||||
// The scan_complete struct matches ESP-IDF's layout exactly, so this reinterpret_cast is safe
|
||||
// This is verified at compile-time by static_assert checks in ble_event.h
|
||||
// The struct already contains our copy of the status (copied in BLEEvent constructor)
|
||||
GAP_SCAN_COMPLETE_EVENTS:
|
||||
param = reinterpret_cast<esp_ble_gap_cb_param_t *>(&ble_event->event_.gap.scan_complete);
|
||||
break;
|
||||
|
||||
// All advertising complete events have the same structure with just status
|
||||
GAP_ADV_COMPLETE_EVENTS:
|
||||
param = reinterpret_cast<esp_ble_gap_cb_param_t *>(&ble_event->event_.gap.adv_complete);
|
||||
break;
|
||||
|
||||
case ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT:
|
||||
param = reinterpret_cast<esp_ble_gap_cb_param_t *>(&ble_event->event_.gap.read_rssi_complete);
|
||||
break;
|
||||
|
||||
GAP_SECURITY_EVENTS:
|
||||
param = reinterpret_cast<esp_ble_gap_cb_param_t *>(&ble_event->event_.gap.security);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user