20 lines
685 B
Rust
20 lines
685 B
Rust
use esp_idf_svc::{
|
|
hal::delay::FreRtos,
|
|
sntp::{EspSntp, SyncStatus},
|
|
};
|
|
use log::info;
|
|
|
|
/// Delay between checks of the initial NTP sync check, in milliseconds.
|
|
const SNTP_STATUS_POLL_INTVL: u32 = 2000;
|
|
|
|
/// Blocks until the SNTP client reports successful synchronization.
|
|
///
|
|
/// Note that the SNTP client's status flag is reset after it is read. Calling
|
|
/// this function twice will cause the second invocation to wait for the next
|
|
/// synchronization event.
|
|
pub(crate) fn wait_for_sync(client: &EspSntp) {
|
|
while client.get_sync_status() != SyncStatus::Completed {
|
|
info!("Waiting for SNTP to sync...");
|
|
FreeRtos::delay_ms(SNTP_STATUS_POLL_INTVL);
|
|
}
|
|
}
|