rx netcode
This commit is contained in:
parent
736584f5d6
commit
4945b4d777
1 changed files with 80 additions and 74 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue