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
impl Track
Sourcepub fn new<T: Output + 'static>(device: T) -> Self
pub fn new<T: Output + 'static>(device: T) -> Self
Creates a new Track
associated with the given actuator.
Sourcepub fn get_duration(&self) -> u64
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.
Sourcepub fn get_device(&self) -> &dyn Output
pub fn get_device(&self) -> &dyn Output
Returns the device associated with the Track
.
Sourcepub fn get_keyframes(&self) -> &Vec<Keyframe>
pub fn get_keyframes(&self) -> &Vec<Keyframe>
Returns the keyframes of this Track
.
Sourcepub fn with_keyframe(self, keyframe: Keyframe) -> Self
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.