mirror of
https://github.com/esphome/esphome.git
synced 2025-09-17 10:42:21 +01:00
[esp32_ble_tracker] Simplify BLE client state machine by removing READY_TO_CONNECT
This commit is contained in:
@@ -43,13 +43,6 @@ void BLEClientBase::setup() {
|
|||||||
void BLEClientBase::set_state(espbt::ClientState st) {
|
void BLEClientBase::set_state(espbt::ClientState st) {
|
||||||
ESP_LOGV(TAG, "[%d] [%s] Set state %d", this->connection_index_, this->address_str_.c_str(), (int) st);
|
ESP_LOGV(TAG, "[%d] [%s] Set state %d", this->connection_index_, this->address_str_.c_str(), (int) st);
|
||||||
ESPBTClient::set_state(st);
|
ESPBTClient::set_state(st);
|
||||||
|
|
||||||
if (st == espbt::ClientState::READY_TO_CONNECT) {
|
|
||||||
// Enable loop for state processing
|
|
||||||
this->enable_loop();
|
|
||||||
// Connect immediately instead of waiting for next loop
|
|
||||||
this->connect();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BLEClientBase::loop() {
|
void BLEClientBase::loop() {
|
||||||
@@ -111,6 +104,8 @@ void BLEClientBase::connect() {
|
|||||||
ESP_LOGI(TAG, "[%d] [%s] 0x%02x Connecting", this->connection_index_, this->address_str_.c_str(),
|
ESP_LOGI(TAG, "[%d] [%s] 0x%02x Connecting", this->connection_index_, this->address_str_.c_str(),
|
||||||
this->remote_addr_type_);
|
this->remote_addr_type_);
|
||||||
this->paired_ = false;
|
this->paired_ = false;
|
||||||
|
// Enable loop for state processing
|
||||||
|
this->enable_loop();
|
||||||
|
|
||||||
// Determine connection parameters based on connection type
|
// Determine connection parameters based on connection type
|
||||||
if (this->connection_type_ == espbt::ConnectionType::V3_WITHOUT_CACHE) {
|
if (this->connection_type_ == espbt::ConnectionType::V3_WITHOUT_CACHE) {
|
||||||
@@ -168,7 +163,7 @@ void BLEClientBase::unconditional_disconnect() {
|
|||||||
this->log_gattc_warning_("esp_ble_gattc_close", err);
|
this->log_gattc_warning_("esp_ble_gattc_close", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->state_ == espbt::ClientState::READY_TO_CONNECT || this->state_ == espbt::ClientState::DISCOVERED) {
|
if (this->state_ == espbt::ClientState::DISCOVERED) {
|
||||||
this->set_address(0);
|
this->set_address(0);
|
||||||
this->set_state(espbt::ClientState::IDLE);
|
this->set_state(espbt::ClientState::IDLE);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -51,8 +51,6 @@ const char *client_state_to_string(ClientState state) {
|
|||||||
return "IDLE";
|
return "IDLE";
|
||||||
case ClientState::DISCOVERED:
|
case ClientState::DISCOVERED:
|
||||||
return "DISCOVERED";
|
return "DISCOVERED";
|
||||||
case ClientState::READY_TO_CONNECT:
|
|
||||||
return "READY_TO_CONNECT";
|
|
||||||
case ClientState::CONNECTING:
|
case ClientState::CONNECTING:
|
||||||
return "CONNECTING";
|
return "CONNECTING";
|
||||||
case ClientState::CONNECTED:
|
case ClientState::CONNECTED:
|
||||||
@@ -795,7 +793,7 @@ void ESP32BLETracker::try_promote_discovered_clients_() {
|
|||||||
#ifdef USE_ESP32_BLE_SOFTWARE_COEXISTENCE
|
#ifdef USE_ESP32_BLE_SOFTWARE_COEXISTENCE
|
||||||
this->update_coex_preference_(true);
|
this->update_coex_preference_(true);
|
||||||
#endif
|
#endif
|
||||||
client->set_state(ClientState::READY_TO_CONNECT);
|
client->connect();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -159,8 +159,6 @@ enum class ClientState : uint8_t {
|
|||||||
IDLE,
|
IDLE,
|
||||||
// Device advertisement found.
|
// Device advertisement found.
|
||||||
DISCOVERED,
|
DISCOVERED,
|
||||||
// Device is discovered and the scanner is stopped
|
|
||||||
READY_TO_CONNECT,
|
|
||||||
// Connection in progress.
|
// Connection in progress.
|
||||||
CONNECTING,
|
CONNECTING,
|
||||||
// Initial connection established.
|
// Initial connection established.
|
||||||
@@ -313,7 +311,6 @@ class ESP32BLETracker : public Component,
|
|||||||
counts.discovered++;
|
counts.discovered++;
|
||||||
break;
|
break;
|
||||||
case ClientState::CONNECTING:
|
case ClientState::CONNECTING:
|
||||||
case ClientState::READY_TO_CONNECT:
|
|
||||||
counts.connecting++;
|
counts.connecting++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Reference in New Issue
Block a user