This commit is contained in:
Anton Sergunov 2024-05-09 03:52:38 +00:00
parent 5035a1f40e
commit 67c03b02af

View file

@ -26,9 +26,12 @@ static const char *const TAG = "sntp";
std::vector<std::pair<optional<struct timeval>, sntp_sync_status_t>> callback_args_; std::vector<std::pair<optional<struct timeval>, sntp_sync_status_t>> callback_args_;
static std::function<void(struct timeval *tv)> g_sync_callback = nullptr; void sntp_sync_time_cb(struct timeval *tv) {
callback_args_.push_back({});
void sntp_sync_time_cb(struct timeval *tv) { g_sync_callback(tv); } if (tv)
callback_args_.back().first = *tv;
callback_args_.back().second = sntp_get_sync_status();
}
void SNTPComponent::setup() { void SNTPComponent::setup() {
#ifndef USE_HOST #ifndef USE_HOST
@ -54,13 +57,6 @@ void SNTPComponent::setup() {
sntp_set_sync_interval(this->get_update_interval()); sntp_set_sync_interval(this->get_update_interval());
#endif #endif
g_sync_callback = [](struct timeval *tv) {
callback_args_.push_back({});
if (tv)
callback_args_.back().first = *tv;
callback_args_.back().second = sntp_get_sync_status();
};
ESP_LOGD(TAG, "Set notification callback"); ESP_LOGD(TAG, "Set notification callback");
sntp_set_time_sync_notification_cb(sntp_sync_time_cb); sntp_set_time_sync_notification_cb(sntp_sync_time_cb);