Skip to main content

LegoPort

Struct LegoPort 

Source
pub struct LegoPort { /* private fields */ }
Expand description

Lego ports

Implementations§

Source§

impl LegoPort

Source

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)?;
Source

pub fn find() -> Ev3Result<Self>

Try to find a Self. Only returns a device if their is exactly one connected, Error::NotFound otherwise.

Source

pub fn list() -> Ev3Result<Vec<Self>>

Extract list of connected ‘Self’

Source

pub fn get_address(&self) -> Ev3Result<String>

Returns the name of the port that the device is connected to.

Source

pub fn get_driver_name(&self) -> Ev3Result<String>

Returns the name of the driver that provides this device.

Source

pub fn get_mode(&self) -> Ev3Result<String>

Returns the currently selected mode.

Source

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.

Source

pub fn get_modes(&self) -> Ev3Result<Vec<String>>

Returns a list of the available modes of the port.

Source

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.

Source

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§

Source§

impl Clone for LegoPort

Source§

fn clone(&self) -> LegoPort

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LegoPort

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.