pub struct LegoPort { /* private fields */ }Expand description
Lego ports
Implementations§
Source§impl LegoPort
impl LegoPort
Sourcepub fn get<T: Port>(port: T) -> Ev3Result<Self>
pub fn get<T: Port>(port: T) -> Ev3Result<Self>
Try to get a Self on the given port. Returns None if port is not used or another device is connected.
Get the port device for this port
§Examples
use ev3dev_lang_rust::{Ev3Result, LegoPort};
use ev3dev_lang_rust::sensors::{ColorSensor, SensorPort};
use std::thread;
use std::time::Duration;
fn init_color_sensor(port: SensorPort) -> Ev3Result<ColorSensor> {
let lego_port = LegoPort::get(port)?;
lego_port.set_mode("ev3-uart")?;
lego_port.set_device("lego-ev3-color")?;
thread::sleep(Duration::from_millis(100));
ColorSensor::get(port)
}
let color_sensor = init_color_sensor(SensorPort::In1)?;Sourcepub fn find() -> Ev3Result<Self>
pub fn find() -> Ev3Result<Self>
Try to find a Self. Only returns a device if their is exactly one connected, Error::NotFound otherwise.
Sourcepub fn get_address(&self) -> Ev3Result<String>
pub fn get_address(&self) -> Ev3Result<String>
Returns the name of the port that the device is connected to.
Sourcepub fn get_driver_name(&self) -> Ev3Result<String>
pub fn get_driver_name(&self) -> Ev3Result<String>
Returns the name of the driver that provides this device.
Sourcepub fn set_mode(&self, mode: &str) -> Ev3Result<()>
pub fn set_mode(&self, mode: &str) -> Ev3Result<()>
Sets the currently selected mode. Generally speaking when the mode changes any sensor or motor devices associated with the port will be removed new ones loaded, however this this will depend on the individual driver implementing this class.
Sourcepub fn get_modes(&self) -> Ev3Result<Vec<String>>
pub fn get_modes(&self) -> Ev3Result<Vec<String>>
Returns a list of the available modes of the port.
Sourcepub fn set_device(&self, mode: &str) -> Ev3Result<()>
pub fn set_device(&self, mode: &str) -> Ev3Result<()>
For modes that support it, writing the name of a driver will cause a new device to be registered for that driver and attached to this port. For example, since NXT/Analog sensors cannot be auto-detected, you must use this attribute to load the correct driver. Returns -EOPNOTSUPP if setting a device is not supported.
Sourcepub fn get_status(&self) -> Ev3Result<String>
pub fn get_status(&self) -> Ev3Result<String>
In most cases, reading status will return the same value as mode. In
cases where there is an auto mode additional values may be returned,
such as no-device or error. See individual port driver documentation
for the full list of possible values.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for LegoPort
impl !RefUnwindSafe for LegoPort
impl Send for LegoPort
impl !Sync for LegoPort
impl Unpin for LegoPort
impl UnsafeUnpin for LegoPort
impl UnwindSafe for LegoPort
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more