attempt to use dcf77_utils
This commit is contained in:
parent
841b7025bb
commit
e9050fa59e
3 changed files with 42 additions and 31 deletions
56
src/main.rs
56
src/main.rs
|
@ -6,7 +6,8 @@
|
|||
|
||||
mod static_mutex;
|
||||
|
||||
use defmt::*;
|
||||
use dcf77_utils::DCF77Utils;
|
||||
use defmt::{assert, info, println, unwrap};
|
||||
use defmt_rtt as _;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::{
|
||||
|
@ -62,39 +63,32 @@ async fn query_time(mut pon: POn, mut tco: Tco, interval: Duration) {
|
|||
pon.set_low();
|
||||
info!("Waiting");
|
||||
tco.wait_for_falling_edge().await;
|
||||
// for _ in 0 .. 10 {
|
||||
// info!("Receiving");
|
||||
// let mut bytes = 0u64;
|
||||
// for _ in 0 .. 60 {
|
||||
// bytes = (bytes << 1) | (tco.is_low() as u64);
|
||||
// Timer::after(Duration::from_millis(100)).await;
|
||||
// }
|
||||
// info!("DCF77: {:X}", bytes);
|
||||
// }
|
||||
info!("Receiving");
|
||||
|
||||
let mut dcf77 = DCF77Utils::new();
|
||||
let start = Instant::now();
|
||||
let mut next = start;
|
||||
for _ in 0 .. 120 {
|
||||
let mut bytes = 0u16;
|
||||
for _ in 0 .. 10 {
|
||||
bytes = (bytes << 1) | (tco.is_low() as u16);
|
||||
next += Duration::from_millis(100);
|
||||
Timer::at(next).await;
|
||||
loop {
|
||||
tco.wait_for_any_edge().await;
|
||||
let elapsed = start.elapsed();
|
||||
while elapsed.as_secs() > dcf77.get_second() as u64 {
|
||||
dcf77.increase_second();
|
||||
}
|
||||
dcf77.handle_new_edge(tco.is_low(), start.elapsed().as_millis() as u32);
|
||||
if dcf77.get_second() + 1 == dcf77.get_next_minute_length() {
|
||||
dcf77.decode_time();
|
||||
let datetime = dcf77.get_radio_datetime();
|
||||
println!(
|
||||
"{}.{}.{} {}:{}",
|
||||
datetime.get_day(),
|
||||
datetime.get_month(),
|
||||
datetime.get_year(),
|
||||
datetime.get_hour(),
|
||||
datetime.get_minute()
|
||||
);
|
||||
break;
|
||||
}
|
||||
println!(
|
||||
"{}{}{}{}{}{}{}{}{}{} ({})",
|
||||
(bytes >> 9) & 1,
|
||||
(bytes >> 8) & 1,
|
||||
(bytes >> 7) & 1,
|
||||
(bytes >> 6) & 1,
|
||||
(bytes >> 5) & 1,
|
||||
(bytes >> 4) & 1,
|
||||
(bytes >> 3) & 1,
|
||||
(bytes >> 2) & 1,
|
||||
(bytes >> 1) & 1,
|
||||
bytes & 1,
|
||||
start.elapsed().as_millis()
|
||||
);
|
||||
}
|
||||
|
||||
pon.set_high();
|
||||
|
||||
Timer::after(interval).await;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue