Skip to content

Commit ea5f53e

Browse files
Merge pull request #101 from pollen-robotics/100-add-reboot-message-in-python-binding
Add ping and reboot in bindings.
2 parents c240313 + ff0aeef commit ea5f53e

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustypot"
3-
version = "1.2.0"
3+
version = "1.3.0"
44
edition = "2021"
55
license = "Apache-2.0"
66
authors = ["Pollen Robotics"]

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Version 1.3.0
2+
3+
- Add reboot support in core library.
4+
- Add ping and reboot support in python bindings.
5+
16
## Version 1.2.0
27

38
- Add support for AX motors (see https://github.com/pollen-robotics/rustypot/pull/93, thanks to @kacper-uminski)

src/servo/servo_macro.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ macro_rules! generate_servo {
4141
use pyo3_stub_gen::derive::*;
4242

4343
$crate::generate_protocol_constructor!($servo_name, $protocol);
44+
$crate::generate_ping_reboot!($servo_name);
4445
$crate::generate_addr_read_write!($servo_name);
4546

4647
$(
@@ -117,6 +118,27 @@ macro_rules! generate_protocol_constructor {
117118
};
118119
}
119120

121+
#[macro_export]
122+
macro_rules! generate_ping_reboot {
123+
($servo_macro:ident) => {
124+
paste::paste! {
125+
impl [<$servo_macro:camel Controller>] {
126+
pub fn ping(&mut self, id: u8) -> $crate::Result<bool> {
127+
let dph = self.dph.as_ref().unwrap();
128+
let serial_port = self.serial_port.as_mut().unwrap().as_mut();
129+
dph.ping(serial_port, id)
130+
}
131+
132+
pub fn reboot(&mut self, id: u8) -> $crate::Result<bool> {
133+
let dph = self.dph.as_ref().unwrap();
134+
let serial_port = self.serial_port.as_mut().unwrap().as_mut();
135+
dph.reboot(serial_port, id)
136+
}
137+
}
138+
}
139+
};
140+
}
141+
120142
#[macro_export]
121143
macro_rules! generate_addr_read_write {
122144
($servo_name:ident) => {
@@ -230,6 +252,16 @@ macro_rules! generate_addr_read_write {
230252
.map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(e.to_string()))?;
231253
Ok(())
232254
}
255+
256+
pub fn ping(&self, id: u8) -> PyResult<bool> {
257+
self.0.lock().unwrap().ping(id)
258+
.map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(e.to_string()))
259+
}
260+
261+
pub fn reboot(&self, id: u8) -> PyResult<bool> {
262+
self.0.lock().unwrap().reboot(id)
263+
.map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(e.to_string()))
264+
}
233265
}
234266
}
235267
};

0 commit comments

Comments
 (0)