Skip to content

Commit 6ca81b1

Browse files
Add ping and reboot in bindings.
1 parent 5720fe2 commit 6ca81b1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

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)