enable on start
This commit is contained in:
parent
91ed6eeb14
commit
ecd0800891
2 changed files with 19 additions and 4 deletions
|
@ -27,7 +27,7 @@ pub struct Response {
|
|||
pub uptime_micros: u64,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub enum SensorData {
|
||||
/// degrees per second
|
||||
Gyro(Vector3<f32>),
|
||||
|
|
|
@ -4,6 +4,7 @@ use anyhow::{Context, Result};
|
|||
use common::{Command, Response, BAUDRATE};
|
||||
use framed_codec::FramedCodec;
|
||||
use futures::{SinkExt, StreamExt};
|
||||
use tokio::sync::broadcast;
|
||||
use tokio_serial::SerialPortBuilderExt;
|
||||
use tokio_util::codec::Framed;
|
||||
|
||||
|
@ -13,6 +14,8 @@ mod framed_codec;
|
|||
async fn main() -> Result<()> {
|
||||
let mut serial = tokio_serial::new("/dev/ttyAMA0", BAUDRATE).open_native_async()?;
|
||||
|
||||
let (sensor_sender, sensor_data) = broadcast::channel(5);
|
||||
|
||||
serial.set_exclusive(false)?;
|
||||
|
||||
let (mut write, read) = Framed::new(serial, FramedCodec::new()).split();
|
||||
|
@ -21,11 +24,23 @@ async fn main() -> Result<()> {
|
|||
Ok(postcard::from_bytes::<Response>(&data.ok().context("decode err")?)?)
|
||||
});
|
||||
|
||||
println!("starting");
|
||||
write.send(Command::Enable).await?;
|
||||
|
||||
while let Some(data) = read.next().await {
|
||||
dbg!(data?);
|
||||
while let Some(Ok(data)) = read.next().await {
|
||||
if data.enabled {
|
||||
write.send(Command::FeedWatchdog).await?;
|
||||
|
||||
write.send(Command::Enable).await?;
|
||||
} else {
|
||||
println!("enabled southbridge");
|
||||
write.send(Command::Enable).await?;
|
||||
}
|
||||
|
||||
dbg!(&data);
|
||||
|
||||
if let Some(data) = data.sensor_data {
|
||||
let _ = sensor_sender.send(data);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue