Keep advertising start/stop decisions in one place

advertising_stop() now just drops its request and lets advertising_refresh()
decide, so both sides are symmetric and only refresh knows when the radio
should be advertising.
This commit is contained in:
Jesse Hills
2026-09-03 10:53:36 +12:00
parent 47aaa21f8d
commit 073c64f3b6
2 changed files with 10 additions and 10 deletions
+9 -9
View File
@@ -107,19 +107,19 @@ void ESP32BLE::advertising_start() {
void ESP32BLE::advertising_stop() {
if (this->advertising_ref_count_ == 0)
return;
// Keep advertising while another component still needs it
if (--this->advertising_ref_count_ > 0)
return;
if (this->advertising_ == nullptr || !this->is_active())
return;
this->advertising_->stop();
this->advertising_ref_count_--;
this->advertising_refresh();
}
void ESP32BLE::advertising_refresh() {
if (this->advertising_ref_count_ == 0 || !this->is_active())
if (this->advertising_ == nullptr || !this->is_active())
return;
this->advertising_init_();
this->advertising_->start();
// Advertise while any component still needs it, otherwise stop
if (this->advertising_ref_count_ == 0) {
this->advertising_->stop();
} else {
this->advertising_->start();
}
}
void ESP32BLE::advertising_set_service_data(const std::vector<uint8_t> &data) {
+1 -1
View File
@@ -123,7 +123,7 @@ class ESP32BLE final : public Component {
void advertising_start();
/// Release a request made with advertising_start(); advertising stops at the last release.
void advertising_stop();
/// Re-apply the advertising payload, restarting advertising only if it is still requested.
/// Apply the current payload and request count: advertise while requested, otherwise stop.
void advertising_refresh();
void advertising_set_service_data(const std::vector<uint8_t> &data);
void advertising_set_manufacturer_data(const std::vector<uint8_t> &data);