mirror of
https://github.com/esphome/esphome.git
synced 2025-04-07 03:10:27 +01:00
Manage global pointer better
This commit is contained in:
parent
e23caabb08
commit
8dd03a3dac
@ -58,7 +58,7 @@ void ESP32BLETracker::setup() {
|
|||||||
this->scanner_idle_ = true;
|
this->scanner_idle_ = true;
|
||||||
|
|
||||||
#ifdef USE_OTA
|
#ifdef USE_OTA
|
||||||
ota::global_ota_component->add_on_state_callback(
|
ota::get_global_ota_callback()->add_on_state_callback(
|
||||||
[this](ota::OTAState state, float progress, uint8_t error, ota::OTAComponent *comp) {
|
[this](ota::OTAState state, float progress, uint8_t error, ota::OTAComponent *comp) {
|
||||||
if (state == ota::OTA_STARTED) {
|
if (state == ota::OTA_STARTED) {
|
||||||
this->stop_scan();
|
this->stop_scan();
|
||||||
|
@ -23,7 +23,7 @@ static constexpr u_int16_t OTA_BLOCK_SIZE = 8192;
|
|||||||
|
|
||||||
void ESPHomeOTAComponent::setup() {
|
void ESPHomeOTAComponent::setup() {
|
||||||
#ifdef USE_OTA_STATE_CALLBACK
|
#ifdef USE_OTA_STATE_CALLBACK
|
||||||
ota::global_ota_component->register_ota(this);
|
ota::register_ota_platform(this);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
server_ = socket::socket_ip(SOCK_STREAM, 0);
|
server_ = socket::socket_ip(SOCK_STREAM, 0);
|
||||||
|
@ -4,7 +4,16 @@ namespace esphome {
|
|||||||
namespace ota {
|
namespace ota {
|
||||||
|
|
||||||
#ifdef USE_OTA_STATE_CALLBACK
|
#ifdef USE_OTA_STATE_CALLBACK
|
||||||
OTAGlobalCallback *global_ota_component = new OTAGlobalCallback(); // NOLINT
|
OTAGlobalCallback *global_ota_callback{nullptr};
|
||||||
|
|
||||||
|
OTAGlobalCallback *get_global_ota_callback() {
|
||||||
|
if (global_ota_callback == nullptr) {
|
||||||
|
global_ota_callback = new OTAGlobalCallback();
|
||||||
|
}
|
||||||
|
return global_ota_callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void register_ota_platform(OTAComponent *ota_caller) { get_global_ota_callback()->register_ota(ota_caller); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace ota
|
} // namespace ota
|
||||||
|
@ -81,7 +81,8 @@ class OTAGlobalCallback {
|
|||||||
CallbackManager<void(OTAState, float, uint8_t, OTAComponent *)> state_callback_{};
|
CallbackManager<void(OTAState, float, uint8_t, OTAComponent *)> state_callback_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
extern OTAGlobalCallback *global_ota_component; // NOLINT
|
OTAGlobalCallback *get_global_ota_callback();
|
||||||
|
void register_ota_platform(OTAComponent *ota_caller);
|
||||||
#endif
|
#endif
|
||||||
std::unique_ptr<ota::OTABackend> make_ota_backend();
|
std::unique_ptr<ota::OTABackend> make_ota_backend();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user