Compare commits
No commits in common. "3c7a6186d4ac04482393a569d15a1ba3f74b3aed" and "841b7025bbca763d5c52fbfcc71827bb33ca7e16" have entirely different histories.
3c7a6186d4
...
841b7025bb
1 changed files with 34 additions and 70 deletions
98
src/main.rs
98
src/main.rs
|
@ -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,77 +61,45 @@ async fn query_time(mut pon: POn, mut tco: Tco, interval: Duration) {
|
||||||
loop {
|
loop {
|
||||||
pon.set_low();
|
pon.set_low();
|
||||||
info!("Waiting");
|
info!("Waiting");
|
||||||
|
|
||||||
// we need to find the minute marker
|
|
||||||
// that means we won't receive a transmission for an entire second
|
|
||||||
tco.wait_for_rising_edge().await;
|
|
||||||
loop {
|
|
||||||
tco.wait_for_falling_edge().await;
|
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);
|
||||||
|
// }
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
tco.wait_for_rising_edge().await;
|
let mut next = start;
|
||||||
// our starting edge should have at least 800ms from the previous second,
|
for _ in 0 .. 120 {
|
||||||
// and then a full second.
|
let mut bytes = 0u16;
|
||||||
if start.elapsed().as_millis() > 1500 {
|
for _ in 0 .. 10 {
|
||||||
break;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(spawner: Spawner) {
|
async fn main(spawner: Spawner) {
|
||||||
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue