fix ble latency

This commit is contained in:
J. Nick Koston
2025-11-01 15:02:26 -05:00
parent 69af4cddb5
commit 32ea82060d
2 changed files with 18 additions and 7 deletions
+13
View File
@@ -723,6 +723,19 @@ void ESP32BLE::cleanup_event_notification_() {
}
}
void ESP32BLE::drain_event_notifications_() {
// Called from main loop to drain any pending notifications
// Must check is_socket_ready() to avoid blocking on empty socket
if (this->notify_fd_ >= 0 && App.is_socket_ready(this->notify_fd_)) {
char buffer[BLE_EVENT_NOTIFY_DRAIN_BUFFER_SIZE];
// Drain all pending notifications with non-blocking reads
// Multiple BLE events may have triggered multiple writes, so drain until EWOULDBLOCK
while (lwip_recvfrom(this->notify_fd_, buffer, sizeof(buffer), 0, nullptr, nullptr) > 0) {
// Just draining, no action needed
}
}
}
#endif // USE_SOCKET_SELECT_SUPPORT
uint64_t ble_addr_to_uint64(const esp_bd_addr_t address) {
+5 -7
View File
@@ -167,10 +167,10 @@ class ESP32BLE : public Component {
#endif
#ifdef USE_SOCKET_SELECT_SUPPORT
void setup_event_notification_(); // Create notification socket
void cleanup_event_notification_(); // Close and unregister socket
inline void notify_main_loop_(); // Wake up select() from BLE thread (hot path - inlined)
inline void drain_event_notifications_(); // Read pending notifications in main loop (hot path - inlined)
void setup_event_notification_(); // Create notification socket
void cleanup_event_notification_(); // Close and unregister socket
inline void notify_main_loop_(); // Wake up select() from BLE thread (hot path - inlined)
void drain_event_notifications_(); // Read pending notifications in main loop
#endif
private:
@@ -248,9 +248,7 @@ inline void ESP32BLE::notify_main_loop_() {
inline void ESP32BLE::drain_event_notifications_() {
// Called from main loop to drain any pending notifications
// Must check is_socket_ready() to avoid blocking on empty socket
// Requires App to be defined - include esphome/core/application.h in .cpp files that use this
extern esphome::Application App;
if (this->notify_fd_ >= 0 && App.is_socket_ready(this->notify_fd_)) {
if (this->notify_fd_ >= 0 && esphome::App.is_socket_ready(this->notify_fd_)) {
char buffer[BLE_EVENT_NOTIFY_DRAIN_BUFFER_SIZE];
// Drain all pending notifications with non-blocking reads
// Multiple BLE events may have triggered multiple writes, so drain until EWOULDBLOCK