diff --git a/interface/src/auto.rs b/interface/src/auto.rs index 5a382e5..9c84841 100644 --- a/interface/src/auto.rs +++ b/interface/src/auto.rs @@ -1,22 +1,34 @@ use std::{collections::VecDeque, ops::{Deref, Div, Index, Range, Sub}}; -use common::{CamState, ControlPacket, SensorData}; +use common::{CamState, ControlPacket, SensorData, TelemetryPacket}; use anyhow::Result; +use tokio::sync::{broadcast, mpsc, watch}; pub struct AutoConfig { turn_gain: f32, auto_fire_distance: f32, } +#[derive(Clone)] pub struct AutoInterface { + command_sender: Option>, + data_receiver: watch::Receiver, } impl AutoInterface { /// change active command, fails if not in control pub fn run_command(&self, command: ControlPacket) -> Result<()> {unimplemented!()} - pub fn sensor_data(&self) -> SensorData {unimplemented!()} - pub fn cam_state(&self) -> CamState {unimplemented!()} - pub async fn sensor_update(&self) -> SensorData {unimplemented!()} + pub fn sensor_data(&mut self) -> SensorData { + self.data_receiver.borrow_and_update().sensors.clone() + } + pub fn cam_state(&mut self) -> CamState { + self.data_receiver.borrow_and_update().cam_state.clone() + } + pub async fn sensor_update(&mut self) -> SensorData { + self.data_receiver.changed().await.unwrap(); + self.data_receiver.borrow().sensors.clone() + + } /// disable auto pub fn disable(&self) {unimplemented!()} /// request auto enable, fails if the driver does not grant it