switched to a state instead of change architecture

southbridge currently hangs, embassy does not make
such things easy to diagnose
This commit is contained in:
Andy Killorin 2025-02-14 17:24:43 -05:00
commit cc18f76e55
Signed by: ank
GPG key ID: 23F9463ECB67FE8C

View file

@ -1,7 +1,7 @@
use std::time::Duration;
use anyhow::Context;
use common::{Command, SensorData};
use common::{RobotState, SensorData};
use gilrs::{Axis, Event, Gilrs};
use nalgebra::Vector3;
use tokio::{io::{AsyncReadExt, AsyncWriteExt, BufWriter}, net::{tcp::OwnedReadHalf, TcpStream}, task::JoinHandle, time::{sleep, Instant}};
@ -18,7 +18,7 @@ async fn main() -> anyhow::Result<()> {
let a = gamepad.button_code(gilrs::Button::South).context("no a")?;
let mut last_a = false;
let server = "130.215.211.79:3322";
let server = "pelican.dyn.wpi.edu:3322";
let mut robot = TcpStream::connect(server).await?;
robot.set_nodelay(true)?;
@ -66,26 +66,20 @@ async fn main() -> anyhow::Result<()> {
ly = 0.0;
rx = 0.0;
}
let black = Vector3::repeat(0u8);
let green = Vector3::new(254u8, 0, 254);
let color = if a {green} else {black};
let cmd = Command::Twist(ly, rx);
println!("twist");
let cmd = RobotState {
drive: (ly, rx),
underglow: color,
};
let encoded = postcard::to_stdvec(&cmd)?;
robot_controller.write_u32(encoded.len() as u32).await?;
robot_controller.write_all(&encoded).await?;
if a != last_a {
let black = Vector3::repeat(0u8);
let green = Vector3::new(254u8, 0, 254);
let cmd = Command::SetLed(if a {green} else {black});
let encoded = postcard::to_stdvec(&cmd)?;
robot_controller.write_u32(encoded.len() as u32).await?;
robot_controller.write_all(&encoded).await?;
println!("led");
}
last_a = a;
if let Err(e) = robot_controller.flush().await {
println!("flush fail: {e}, reconnecting");
robot = TcpStream::connect(server).await?;
@ -98,7 +92,7 @@ async fn main() -> anyhow::Result<()> {
robot_controller = BufWriter::new(robot);
};
sleep(Duration::from_millis(65)).await;
sleep(Duration::from_millis(25)).await;
}
}