Compare commits

..

No commits in common. "3c7a6186d4ac04482393a569d15a1ba3f74b3aed" and "841b7025bbca763d5c52fbfcc71827bb33ca7e16" have entirely different histories.

View file

@ -3,14 +3,10 @@
#![feature(async_fn_track_caller, type_alias_impl_trait)] #![feature(async_fn_track_caller, type_alias_impl_trait)]
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
#![forbid(elided_lifetimes_in_paths, unsafe_code)] #![forbid(elided_lifetimes_in_paths, unsafe_code)]
// STOP HIGHLIGHTING MY ENTIRE CODE RED YOU MOTHERFUCKING PEACE OF GARBAGE SOFTWARE
// SOMETIMES I AM WRITING CODE BEFORE I INSERT A BREAK SOMEWHERE
// ARE YOU AWARE THAT CODING DOESN'T PRODUCE FINISHED CODE IN A MILLISECOND???????
#![allow(clippy::never_loop, unreachable_code)]
mod static_mutex; mod static_mutex;
use defmt::{info, println, unwrap}; use defmt::*;
use defmt_rtt as _; use defmt_rtt as _;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_stm32::{ use embassy_stm32::{
@ -65,75 +61,43 @@ async fn query_time(mut pon: POn, mut tco: Tco, interval: Duration) {
loop { loop {
pon.set_low(); pon.set_low();
info!("Waiting"); info!("Waiting");
tco.wait_for_falling_edge().await;
// we need to find the minute marker // for _ in 0 .. 10 {
// that means we won't receive a transmission for an entire second // info!("Receiving");
tco.wait_for_rising_edge().await; // let mut bytes = 0u64;
loop { // for _ in 0 .. 60 {
tco.wait_for_falling_edge().await; // bytes = (bytes << 1) | (tco.is_low() as u64);
let start = Instant::now(); // Timer::after(Duration::from_millis(100)).await;
tco.wait_for_rising_edge().await; // }
// our starting edge should have at least 800ms from the previous second, // info!("DCF77: {:X}", bytes);
// and then a full second. // }
if start.elapsed().as_millis() > 1500 { let start = Instant::now();
break; 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;
} }
}
let mut start = Instant::now();
info!("Receiving");
// we always start on the rising edge, with `start` set already
const SECONDS: usize = 60;
let mut bytes = [0u64; SECONDS];
let mut timing = [0u64; SECONDS];
let mut i = 0;
while i < SECONDS {
tco.wait_for_falling_edge().await;
bytes[i] = start.elapsed().as_millis();
tco.wait_for_rising_edge().await;
timing[i] = start.elapsed().as_millis();
start = Instant::now();
// verify that the transmission wasn't just noise of the previous one
if i > 0 && bytes[i] < 100 && timing[i - 1] - bytes[i - 1] < 100 {
bytes[i - 1] += timing[i - 1] + bytes[i];
timing[i - 1] += timing[i];
}
// and verify that the transmission wasn't a minute marker
else if timing[i] >= 1500 {
info!("Retrying");
i = 0;
}
// otherwise advance the second
else {
i += 1;
}
}
pon.set_high();
info!("Done");
let mut garbage = false;
for i in 0 .. SECONDS {
let data = match (bytes[i], timing[i]) {
(75 ..= 174, 900 ..= 1100) => "0",
(175 ..= 300, 900 ..= 1100) => "1",
_ => {
garbage = true;
"GARBAGE"
}
};
println!( println!(
"Bit {:02}: on for {:04} ms of {:04} ms total -- {:02}: {}", "{}{}{}{}{}{}{}{}{}{} ({})",
i, bytes[i], timing[i], i, data (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()
); );
Timer::after(Duration::from_millis(50)).await;
} }
pon.set_high();
if !garbage { Timer::after(interval).await;
Timer::after(interval).await;
}
} }
} }
@ -144,7 +108,7 @@ async fn main(spawner: Spawner) {
let pon = Output::new(p.PA0, Level::High, Speed::Low); let pon = Output::new(p.PA0, Level::High, Speed::Low);
let tco = ExtiInput::new(Input::new(p.PA1, Pull::None), p.EXTI1); let tco = ExtiInput::new(Input::new(p.PA1, Pull::None), p.EXTI1);
unwrap!(spawner.spawn(query_time(pon, tco, Duration::from_secs(120)))); unwrap!(spawner.spawn(query_time(pon, tco, Duration::from_secs(300))));
LED.init(Output::new(p.PA5, Level::Low, Speed::Low)).await; LED.init(Output::new(p.PA5, Level::Low, Speed::Low)).await;
let button = ExtiInput::new(Input::new(p.PC13, Pull::Up), p.EXTI13); let button = ExtiInput::new(Input::new(p.PC13, Pull::Up), p.EXTI13);