Skip to content

Commit fdadb5a

Browse files
committed
adding default arguments to factory_reset, renaming conserve_id to conserve_id_only
1 parent 0ef13a7 commit fdadb5a

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

src/dynamixel_protocol/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,18 @@ impl DynamixelProtocolHandler {
137137
&self,
138138
serial_port: &mut dyn serialport::SerialPort,
139139
id: u8,
140-
conserve_id: bool,
140+
conserve_id_only: bool,
141141
conserve_id_and_baudrate: bool,
142142
) -> Result<()> {
143143
match &self.protocol {
144144
ProtocolKind::V1(p) => {
145-
if conserve_id || conserve_id_and_baudrate {
145+
if conserve_id_only || conserve_id_and_baudrate {
146146
return Err(Box::new(CommunicationErrorKind::Unsupported));
147147
}
148-
p.factory_reset(serial_port, id, conserve_id, conserve_id_and_baudrate)
148+
p.factory_reset(serial_port, id, conserve_id_only, conserve_id_and_baudrate)
149149
}
150150
ProtocolKind::V2(p) => {
151-
p.factory_reset(serial_port, id, conserve_id, conserve_id_and_baudrate)
151+
p.factory_reset(serial_port, id, conserve_id_only, conserve_id_and_baudrate)
152152
}
153153
}
154154
}
@@ -378,12 +378,12 @@ trait Protocol<P: Packet> {
378378
&self,
379379
port: &mut dyn SerialPort,
380380
id: u8,
381-
conserve_id: bool,
381+
conserve_id_only: bool,
382382
conserve_id_and_baudrate: bool,
383383
) -> Result<()> {
384384
self.send_instruction_packet(
385385
port,
386-
P::factory_reset_packet(id, conserve_id, conserve_id_and_baudrate).as_ref(),
386+
P::factory_reset_packet(id, conserve_id_only, conserve_id_and_baudrate).as_ref(),
387387
)?;
388388
self.read_status_packet(port, id).map(|_| ())
389389
}

src/dynamixel_protocol/packet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub trait Packet {
1313
fn reboot_packet(id: u8) -> Box<dyn InstructionPacket<Self>>;
1414
fn factory_reset_packet(
1515
id: u8,
16-
conserve_id: bool,
16+
conserve_id_only: bool,
1717
conserve_id_and_baudrate: bool,
1818
) -> Box<dyn InstructionPacket<Self>>;
1919

src/dynamixel_protocol/v1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl Packet for PacketV1 {
3333

3434
fn factory_reset_packet(
3535
id: u8,
36-
_conserve_id: bool,
36+
_conserve_id_only: bool,
3737
_conserve_id_and_baudrate: bool,
3838
) -> Box<dyn InstructionPacket<Self>> {
3939
Box::new(InstructionPacketV1 {

src/dynamixel_protocol/v2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ impl Packet for PacketV2 {
4949

5050
fn factory_reset_packet(
5151
id: u8,
52-
conserve_id: bool,
52+
conserve_id_only: bool,
5353
conserve_id_and_baudrate: bool,
5454
) -> Box<dyn InstructionPacket<Self>> {
5555
// See https://emanual.robotis.com/docs/en/dxl/protocol2/
56-
let param = match (conserve_id, conserve_id_and_baudrate) {
56+
let param = match (conserve_id_only, conserve_id_and_baudrate) {
5757
(false, false) => 0xFF,
5858
(true, false) => 0x01,
5959
(true, true) => 0x02,

src/servo/servo_macro.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ macro_rules! generate_special_instructions {
138138
pub fn factory_reset(
139139
&mut self,
140140
id: u8,
141-
conserve_id: bool,
141+
conserve_id_only: bool,
142142
conserve_id_and_baudrate: bool,
143143
) -> $crate::Result<()> {
144144
let dph = self.dph.as_ref().unwrap();
145145
let serial_port = self.serial_port.as_mut().unwrap().as_mut();
146-
dph.factory_reset(serial_port, id, conserve_id, conserve_id_and_baudrate)
146+
dph.factory_reset(serial_port, id, conserve_id_only, conserve_id_and_baudrate)
147147
}
148148
}
149149
}
@@ -274,13 +274,18 @@ macro_rules! generate_addr_read_write {
274274
.map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(e.to_string()))
275275
}
276276

277+
#[pyo3(signature = (
278+
id,
279+
conserve_id_only = true,
280+
conserve_id_and_baudrate = true
281+
))]
277282
pub fn factory_reset(
278283
&self,
279284
id: u8,
280-
conserve_id: bool,
285+
conserve_id_only: bool,
281286
conserve_id_and_baudrate: bool,
282287
) -> PyResult<()> {
283-
self.0.lock().unwrap().factory_reset(id, conserve_id, conserve_id_and_baudrate)
288+
self.0.lock().unwrap().factory_reset(id, conserve_id_only, conserve_id_and_baudrate)
284289
.map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(e.to_string()))
285290
}
286291
}

0 commit comments

Comments
 (0)