Struct Track

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

Represents an animation track within a Segment for a given Output device.

The Track struct manages the state and keyframes for an actuator device through a sequence. It represents the evolution of the device internal state over the sequence (animation) period at specific Keyframe and the transition between those.

§Example

If a Keyframe is set with a target value of 100, a start time of 0 ms, and an end time of 1000 ms, the Actuator’s value will gradually move towards value 100 (whatever it means to it: let it be the brightness of a LED, or the position of a Servo), over 1000 milliseconds, following the defined easing function.

use hermes_five::animations::{Easing, Keyframe, Track};
use hermes_five::hardware::Board;
use hermes_five::devices::Servo;
use hermes_five::io::RemoteIo;

#[hermes_five::runtime]
async fn main() {
    // Defines a board (using serial port on COM4).
    let board = Board::new(RemoteIo::new("COM4")).open();
    // Defines a servo attached to the board on PIN 9 (default servo position is 90°).
    let servo = Servo::new(&board, 9, 90).unwrap();
    // Creates a track for the servo.
    let track = Track::new(servo)
        // Turns the servo to 180° in 1000ms
        .with_keyframe(Keyframe::new(180, 0, 1000).set_transition(Easing::SineInOut))
        // Turns the servo to 0° in 1000ms
        .with_keyframe(Keyframe::new(0, 2000, 3000).set_transition(Easing::SineInOut));
}

Implementations§

Source§

impl Track

Source

pub fn new<T: Output + 'static>(device: T) -> Self

Creates a new Track associated with the given actuator.

Source

pub fn get_duration(&self) -> u64

Compute and return the total duration (in ms) of the track. The duration is by definition the end time of the last keyframe.

Source

pub fn get_device(&self) -> &dyn Output

Returns the device associated with the Track.

Source

pub fn get_keyframes(&self) -> &Vec<Keyframe>

Returns the keyframes of this Track.

Source

pub fn with_keyframe(self, keyframe: Keyframe) -> Self

Add a new keyframe to this Track.

No validation is done on keyframe validity: at any moment, only one keyframe (the best suitable one according to Track::get_best_keyframe() strategy) will be played. So some keyframes may be missed if overlapping for instance.

Trait Implementations§

Source§

impl Clone for Track

Source§

fn clone(&self) -> Track

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 Track

Source§

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

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

impl Display for Track

Source§

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

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

impl From<Track> for Animation

Source§

fn from(track: Track) -> Self

Converts to this type from the input type.
Source§

impl From<Track> for Segment

Source§

fn from(track: Track) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Track

§

impl !RefUnwindSafe for Track

§

impl Send for Track

§

impl Sync for Track

§

impl Unpin for Track

§

impl !UnwindSafe for Track

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.