rx netcode

This commit is contained in:
Andy Killorin 2025-01-18 14:26:13 -05:00
commit 4945b4d777
Signed by: ank
GPG key ID: 23F9463ECB67FE8C

View file

@ -2,6 +2,7 @@ use core::sync::atomic::{AtomicU8, Ordering};
use core::task::Poll;
use core::{cell::RefCell, mem::transmute};
use common::SensorData;
use embassy_executor::Executor;
use embassy_rp::peripherals::{I2C0, I2C1};
use embassy_time::{Delay, Duration, Instant, Timer};
@ -37,19 +38,6 @@ enum PollState {
Gyro,
}
#[derive(Clone, Debug)]
pub struct SensorData {
/// distance, mm
tof1: Option<u16>,
/// distance, mm
tof2: Option<u16>,
/// acceleration, rad/s
gyro: Option<Vector3<f32>>,
/// acceleration, g
accel: Option<Vector3<f32>>,
updated: Instant,
}
#[embassy_executor::task]
async fn init_sensors(mut hardware: SensorHardware) {
let bus = RefCell::new(hardware.bus_tof);
@ -72,8 +60,8 @@ async fn init_sensors(mut hardware: SensorHardware) {
tof2: None,
gyro: None,
accel: None,
updated: Instant::now(),
};
let mut updated_ts = Instant::now();
loop {
let mut updated = false;
@ -102,10 +90,10 @@ async fn init_sensors(mut hardware: SensorHardware) {
updated = true;
}
if updated {
data.updated = Instant::now();
updated_ts = Instant::now();
}
POLL_STATE.store(PollState::None as u8, Ordering::SeqCst);
CHANNEL.send(data.clone()).await;
CHANNEL.send((data.clone(), updated_ts.clone())).await;
}
}