Skip to content

Commit

Permalink
fix PinMode command prefix and deser impl
Browse files Browse the repository at this point in the history
  • Loading branch information
beni69 committed Jul 25, 2023
1 parent 7ec5d7c commit 90ef9f0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
24 changes: 24 additions & 0 deletions client/examples/gpio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use roblib::gpio::{Gpio, Mode};
use roblib_client::{logger::init_log, transports::udp::Udp, Result, Robot};
use std::{thread::sleep, time::Duration};

const P: u8 = 3;

fn main() -> Result<()> {
init_log(Some("debug"));

let ip = std::env::args()
.nth(1)
.unwrap_or_else(|| "localhost:1110".into());

let robot = Robot::new(Udp::connect(ip)?);

log::info!("set pin mode");
robot.pin_mode(P, Mode::Output)?;
let mut state = false;
loop {
state = !state;
robot.write_pin(P, state)?;
sleep(Duration::from_secs(1));
}
}
9 changes: 8 additions & 1 deletion roblib/src/cmd/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl Serialize for Concrete {
#[cfg(feature = "gpio")]
Self::PinMode(c) => {
let mut s = serializer.serialize_struct("Concrete", 2)?;
s.serialize_field("prefix", &cmd::ReadPin::PREFIX)?;
s.serialize_field("prefix", &cmd::PinMode::PREFIX)?;
s.serialize_field("cmd", &c)?;
s.end()
}
Expand Down Expand Up @@ -350,6 +350,13 @@ impl<'de> Deserialize<'de> for Concrete {
Ok(Concrete::UltraSensor(cmd))
}

#[cfg(feature = "gpio")]
cmd::PinMode::PREFIX => {
let cmd = seq
.next_element()?
.ok_or_else(|| de::Error::invalid_length(0, &self))?;
Ok(Concrete::PinMode(cmd))
}
#[cfg(feature = "gpio")]
cmd::ReadPin::PREFIX => {
let cmd = seq
Expand Down
2 changes: 1 addition & 1 deletion roblib/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Command for Unsubscribe {
#[derive(Command, serde::Serialize, serde::Deserialize)]
pub struct Nop;
impl Command for Nop {
const PREFIX: char = 'n';
const PREFIX: char = '0';
type Return = ();
}

Expand Down
6 changes: 3 additions & 3 deletions roblib/src/gpio/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use roblib_macro::Command;
#[derive(Command, serde::Serialize, serde::Deserialize)]
pub struct PinMode(pub u8, pub super::Mode);
impl Command for PinMode {
const PREFIX: char = 'r';
const PREFIX: char = 'p';
type Return = ();
}

Expand All @@ -18,14 +18,14 @@ impl Command for ReadPin {
#[derive(Command, serde::Serialize, serde::Deserialize)]
pub struct WritePin(pub u8, pub bool);
impl Command for WritePin {
const PREFIX: char = 'p';
const PREFIX: char = 'w';
type Return = ();
}

#[derive(Command, serde::Serialize, serde::Deserialize)]
pub struct Pwm(pub u8, pub f64, pub f64);
impl Command for Pwm {
const PREFIX: char = 'w';
const PREFIX: char = 'W';
type Return = ();
}

Expand Down

1 comment on commit 90ef9f0

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Artifacts

View all

base roland
aarch64-unknown-linux-gnu Download Download
armv7-unknown-linux-gnueabihf Download Download
x86_64-pc-windows-msvc Download Download
x86_64-unknown-linux-gnu Download Download

Please sign in to comment.