diff --git a/common/Cargo.toml b/common/Cargo.toml index fa02773..9b344b6 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" edition = "2024" [dependencies] +serde = { version = "1.0.219", default-features = false, features = ["serde_derive", "derive"] } diff --git a/common/src/lib.rs b/common/src/lib.rs index b93cf3f..209b243 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,14 +1,8 @@ -pub fn add(left: u64, right: u64) -> u64 { - left + right -} +#![no_std] +use serde::Deserialize; -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } +#[derive(Deserialize, Default)] +pub struct Command { + pub left: f32, + pub right: f32, } diff --git a/robot-controller/Cargo.lock b/robot-controller/Cargo.lock index f5302f4..d1fb248 100644 --- a/robot-controller/Cargo.lock +++ b/robot-controller/Cargo.lock @@ -105,6 +105,13 @@ dependencies = [ "thiserror", ] +[[package]] +name = "common" +version = "0.1.0" +dependencies = [ + "serde", +] + [[package]] name = "critical-section" version = "1.2.0" @@ -238,6 +245,7 @@ version = "0.1.0" dependencies = [ "arduino-hal", "avr-device", + "common", "embedded-hal 1.0.0", "nb 1.1.0", "panic-halt", diff --git a/robot-controller/Cargo.toml b/robot-controller/Cargo.toml index 6c2bb1c..e9e1993 100644 --- a/robot-controller/Cargo.toml +++ b/robot-controller/Cargo.toml @@ -18,6 +18,7 @@ embedded-hal = "1.0" avr-device = "0.7.0" serde = { version = "1.0.219", default-features = false, features = ["serde_derive", "derive"] } postcard = "1.1.2" +common = { path = "../common" } [dependencies.arduino-hal] git = "https://github.com/rahix/avr-hal" diff --git a/robot-controller/src/main.rs b/robot-controller/src/main.rs index 509b889..215b5a6 100644 --- a/robot-controller/src/main.rs +++ b/robot-controller/src/main.rs @@ -12,8 +12,8 @@ use arduino_hal::pac::USART0; use arduino_hal::port::mode::*; use arduino_hal::prelude::*; use avr_device::interrupt::{self, Mutex}; +use common::Command; use panic_halt as _; -use serde::Deserialize; fn shift_out(data_pin: &mut Pin, clock_pin: &mut Pin, data: &u8) { for i in 0..8 { @@ -157,12 +157,6 @@ fn main() -> ! { } } -#[derive(Deserialize, Default)] -struct Command { - left: f32, - right: f32, -} - fn decode_command() -> Command { let mut input = interrupt::free(|cs| { INPUT_LINE.borrow(cs).borrow().clone()