File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed
Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -68,12 +68,13 @@ let cmd = PositionCommand::new()
6868For more control, you can specify a transport explicitly:
6969
7070``` rust,no_run
71- use moteus::{BlockingController, TransportOptions};
71+ use moteus::{BlockingController, Transport};
72+ use moteus::transport::socketcan::SocketCan;
7273
7374fn main() -> Result<(), moteus::Error> {
74- let opts = TransportOptions:: new()
75- .socketcan_interfaces(vec!["can0"]);
76- let mut ctrl = BlockingController::with_options(1, &opts );
75+ let transport = Transport::from_device(SocketCan:: new("can0")?);
76+ let mut ctrl = BlockingController::new(1)
77+ .transport(transport );
7778
7879 ctrl.set_stop()?;
7980 Ok(())
Original file line number Diff line number Diff line change @@ -476,6 +476,26 @@ fn compute_parent_indices(devices: &[Box<dyn TransportDevice>]) -> Vec<usize> {
476476}
477477
478478impl Transport {
479+ /// Creates a transport from a single device.
480+ ///
481+ /// This is the simplest way to create a transport when you know
482+ /// exactly which device to use.
483+ ///
484+ /// # Example
485+ ///
486+ /// ```no_run
487+ /// use moteus::transport::socketcan::SocketCan;
488+ /// use moteus::Transport;
489+ ///
490+ /// fn main() -> Result<(), moteus::Error> {
491+ /// let transport = Transport::from_device(SocketCan::new("can0")?);
492+ /// Ok(())
493+ /// }
494+ /// ```
495+ pub fn from_device ( device : impl TransportDevice + ' static ) -> Self {
496+ Self :: new ( vec ! [ Box :: new( device) ] )
497+ }
498+
479499 /// Creates a new transport from a list of devices.
480500 ///
481501 /// The devices will be assigned sequential IDs starting from 0.
You can’t perform that action at this time.
0 commit comments