Led

Struct Led 

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

Represents a LED controlled by a digital pin. There are two kinds of pins that can be used:

  • OUTPUT: for digital on/off led
  • PWM: for more control on the LED brightness

Implementations§

Source§

impl Led

Source

pub fn new(board: &dyn Hardware, pin: u8, default: bool) -> Result<Self, Error>

Creates an instance of a LED attached to a given board.

§Errors
  • UnknownPin: this function will bail an error if the pin does not exist for this board.
  • IncompatibleMode: this function will bail an error if the pin does not support OUTPUT or PWM mode.
Source

pub fn turn_on(&mut self) -> Result<&Self, Error>

Turns the LED on.

Source

pub fn turn_off(&mut self) -> Result<&Self, Error>

Turns the LED off.

Source

pub fn toggle(&mut self) -> Result<&Self, Error>

Toggles the current state, if on then turn off, if off then turn on.

Blinks the LED on/off in phases of milliseconds duration. This is an animation and can be stopped by calling Led::stop().

Source

pub fn pulse(&mut self, ms: u64) -> &Self

Pulses the LED on/off (using fading) in phases of ms (milliseconds) duration. This is an animation and can be stopped by calling Led::stop().

Source

pub fn get_pin(&self) -> u8

Returns the pin (id) used by the device.

Source

pub fn get_pin_info(&self) -> Result<Pin, Error>

Returns the Pin information.

Source

pub fn get_brightness(&self) -> u8

Returns the LED current brightness in percentage (0-100%).

Source

pub fn set_brightness(self, brightness: u8) -> Result<Self, Error>

Set the LED brightness (integer between 0-100) in percent of the max brightness. If a number higher than 100 is used, the brightness is set to 100%. If the requested brightness is 100%, the LED will reset to simple on/off (OUTPUT) mode.

§Errors
  • IncompatiblePin: this function will bail an error if the LED pin does not support PWM.
Source

pub fn is_on(&self) -> bool

Indicates if the LED is current ON (regardless its brightness).

Source

pub fn is_off(&self) -> bool

Indicates if the LED is current OFF.

Trait Implementations§

Source§

impl Clone for Led

Source§

fn clone(&self) -> Led

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 Led

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for Led

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Output for Led

Source§

fn get_state(&self) -> State

Returns the actuator current state.

Source§

fn set_state(&mut self, state: State) -> Result<State, Error>

Internal only: you should rather use Self::turn_on(), Self::turn_off(), Self::set_brightness() functions.

Source§

fn get_default(&self) -> State

Returns the actuator default (or neutral) state.
Source§

fn animate<S: Into<State>>( &mut self, state: S, duration: u64, transition: Easing, )

Animates the output of the device. In other word: the state of the device will be animated from current step to targeted step through an interpolation of in-between states. The function will last for the required duration and the interpolation will follow an easing transition function. Read more
Source§

fn is_busy(&self) -> bool

Indicates the busy status, ie if the device is running an animation.
Source§

fn stop(&mut self)

Stops the current animation, if any.
Source§

fn reset(&mut self) -> Result<State, Error>

Resets the actuator to default (or neutral) state.
Source§

fn scale_state( &mut self, previous: State, target: State, progress: f32, ) -> State

Internal only.
Source§

impl Device for Led

Auto Trait Implementations§

§

impl Freeze for Led

§

impl !RefUnwindSafe for Led

§

impl Send for Led

§

impl Sync for Led

§

impl Unpin for Led

§

impl !UnwindSafe for Led

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.