attempt to use dcf77_utils
This commit is contained in:
parent
841b7025bb
commit
e9050fa59e
3 changed files with 42 additions and 31 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -168,6 +168,15 @@ dependencies = [
|
||||||
"syn 2.0.37",
|
"syn 2.0.37",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dcf77_utils"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "824d8617af2b569a01b5498c76efa9dca0acba748d4b339d5fbe3c7e28cb4cfb"
|
||||||
|
dependencies = [
|
||||||
|
"radio_datetime_utils",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "defmt"
|
name = "defmt"
|
||||||
version = "0.3.5"
|
version = "0.3.5"
|
||||||
|
@ -225,6 +234,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cortex-m",
|
"cortex-m",
|
||||||
"cortex-m-rt",
|
"cortex-m-rt",
|
||||||
|
"dcf77_utils",
|
||||||
"defmt",
|
"defmt",
|
||||||
"defmt-rtt",
|
"defmt-rtt",
|
||||||
"embassy-executor",
|
"embassy-executor",
|
||||||
|
@ -691,6 +701,12 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "radio_datetime_utils"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "95cdd3b90edcd89072979b07d58b98573e6042d7d79f9b3c43aa14ceea645d6e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_core"
|
name = "rand_core"
|
||||||
version = "0.6.4"
|
version = "0.6.4"
|
||||||
|
|
|
@ -6,6 +6,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
|
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
|
||||||
cortex-m-rt = "0.7"
|
cortex-m-rt = "0.7"
|
||||||
|
dcf77_utils = "0.5"
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.3"
|
defmt-rtt = "0.3"
|
||||||
# potentially use executor-interrupt instead of executor-thread for cortex-m architectures
|
# potentially use executor-interrupt instead of executor-thread for cortex-m architectures
|
||||||
|
|
52
src/main.rs
52
src/main.rs
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
mod static_mutex;
|
mod static_mutex;
|
||||||
|
|
||||||
use defmt::*;
|
use dcf77_utils::DCF77Utils;
|
||||||
|
use defmt::{assert, info, println, unwrap};
|
||||||
use defmt_rtt as _;
|
use defmt_rtt as _;
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_stm32::{
|
use embassy_stm32::{
|
||||||
|
@ -62,39 +63,32 @@ async fn query_time(mut pon: POn, mut tco: Tco, interval: Duration) {
|
||||||
pon.set_low();
|
pon.set_low();
|
||||||
info!("Waiting");
|
info!("Waiting");
|
||||||
tco.wait_for_falling_edge().await;
|
tco.wait_for_falling_edge().await;
|
||||||
// for _ in 0 .. 10 {
|
info!("Receiving");
|
||||||
// info!("Receiving");
|
|
||||||
// let mut bytes = 0u64;
|
let mut dcf77 = DCF77Utils::new();
|
||||||
// for _ in 0 .. 60 {
|
|
||||||
// bytes = (bytes << 1) | (tco.is_low() as u64);
|
|
||||||
// Timer::after(Duration::from_millis(100)).await;
|
|
||||||
// }
|
|
||||||
// info!("DCF77: {:X}", bytes);
|
|
||||||
// }
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let mut next = start;
|
loop {
|
||||||
for _ in 0 .. 120 {
|
tco.wait_for_any_edge().await;
|
||||||
let mut bytes = 0u16;
|
let elapsed = start.elapsed();
|
||||||
for _ in 0 .. 10 {
|
while elapsed.as_secs() > dcf77.get_second() as u64 {
|
||||||
bytes = (bytes << 1) | (tco.is_low() as u16);
|
dcf77.increase_second();
|
||||||
next += Duration::from_millis(100);
|
|
||||||
Timer::at(next).await;
|
|
||||||
}
|
}
|
||||||
|
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!(
|
println!(
|
||||||
"{}{}{}{}{}{}{}{}{}{} ({})",
|
"{}.{}.{} {}:{}",
|
||||||
(bytes >> 9) & 1,
|
datetime.get_day(),
|
||||||
(bytes >> 8) & 1,
|
datetime.get_month(),
|
||||||
(bytes >> 7) & 1,
|
datetime.get_year(),
|
||||||
(bytes >> 6) & 1,
|
datetime.get_hour(),
|
||||||
(bytes >> 5) & 1,
|
datetime.get_minute()
|
||||||
(bytes >> 4) & 1,
|
|
||||||
(bytes >> 3) & 1,
|
|
||||||
(bytes >> 2) & 1,
|
|
||||||
(bytes >> 1) & 1,
|
|
||||||
bytes & 1,
|
|
||||||
start.elapsed().as_millis()
|
|
||||||
);
|
);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pon.set_high();
|
pon.set_high();
|
||||||
|
|
||||||
Timer::after(interval).await;
|
Timer::after(interval).await;
|
||||||
|
|
Loading…
Reference in a new issue