3#ifdef ESPHOME_THREAD_MULTI_ATOMICS
10 if (candidate ==
nullptr || reference ==
nullptr)
14 while (*candidate >=
'0' && *candidate <=
'9') {
15 a = a * 10 +
static_cast<uint32_t>(*candidate -
'0');
19 while (*reference >=
'0' && *reference <=
'9') {
20 b = b * 10 +
static_cast<uint32_t>(*reference -
'0');
26 const bool a_more = (*candidate ==
'.');
27 const bool b_more = (*reference ==
'.');
32 if (!a_more && !b_more)
38#ifdef ESPHOME_THREAD_MULTI_ATOMICS
40static std::atomic<uint32_t> update_locked{0};
42static bool update_lock_test_and_set() {
return update_locked.exchange(1) == 0; }
43static void update_lock_clear() { update_locked.store(0); }
45static bool update_locked =
false;
47#ifdef ESPHOME_THREAD_MULTI_NO_ATOMICS
49static Mutex &update_lock_mutex() {
55static bool update_lock_test_and_set() {
56#ifdef ESPHOME_THREAD_MULTI_NO_ATOMICS
57 LockGuard guard(update_lock_mutex());
68static void update_lock_clear() {
69#ifdef ESPHOME_THREAD_MULTI_NO_ATOMICS
70 LockGuard guard(update_lock_mutex());
72 update_locked =
false;
78 this->
held_ = update_lock_test_and_set();
91#ifdef USE_OTA_STATE_LISTENER
105 static_assert(
OTA_ERROR <= 0xFF,
"OTAState must fit in 8 bits for packing");
107 static_cast<uint16_t
>(progress * 100.0f);
108 this->
defer([
this, packed]() {
109 this->
notify_state_(
static_cast<OTAState>(packed >> 24),
static_cast<float>(packed & 0xFFFF) / 100.0f,
110 static_cast<uint8_t
>(packed >> 16));
116 listener->on_ota_state(
state, progress, error);
void defer(const char *name, std::function< void()> &&f)
Defer a callback to the next loop() call with a const char* name.
void notify_state_deferred_(OTAState state, float progress, uint8_t error)
Notify state with deferral to main loop (for thread safety).
std::vector< OTAStateListener * > state_listeners_
void notify_state_(OTAState state, float progress, uint8_t error)
Global callback that aggregates OTA state from all OTA components.
void notify_ota_state(OTAState state, float progress, uint8_t error, OTAComponent *component)
static void force_release()
Tests only.
bool try_acquire()
Returns false if held elsewhere.
bool version_is_older(const char *candidate, const char *reference)
Compare two dotted-numeric version strings (such as "1.2.3").
OTAGlobalCallback * get_global_ota_callback()
OTAGlobalCallback * global_ota_callback