Struct SawToothProfile

Source
pub struct SawToothProfile {
    counter: f32,
    pub level_normalized: f32,
    phase1_counter_limit: f32,
    phase2_counter_limit: f32,
    phase3_counter_limit: f32,
    phase4_counter_limit: f32,
}
Expand description

Contains the profile configuration and the implementation for the saw tooth profile.

Fields§

§counter: f32

This variable counts the number of iterations executed and is reset to zero when reaching the end of the profile.

§level_normalized: f32

Variable with values from zero to one. This is the output of the saw tooth profile component.

§phase1_counter_limit: f32

This variable is set to the same value as the length of the first phase.

§phase2_counter_limit: f32

This variable is set to the cumulated length of the first and second phase.

§phase3_counter_limit: f32

This variable is set to the cumulated length of the first three phases.

§phase4_counter_limit: f32

This variable is set to the cumulated length of all phases.

Implementations§

Source§

impl SawToothProfile

Source

pub fn new(config: &SawToothProfileConfig) -> SawToothProfile

Creates a new SawToothProfile instance based on the provided configuration.

This constructor initializes the sawtooth wave generator, setting up its internal counter and pre-calculating the limits for each phase based on the lengths defined in the SawToothProfileConfig. The level_normalized output is initially set to 0.0.

§Arguments
  • config - A reference to a SawToothProfileConfig struct, which specifies the desired lengths of the four phases (ramp up, constant high, ramp down, constant low) in terms of iterations or time units.
§Returns

A new SawToothProfile struct, ready to generate values.

Source

pub fn execute_with(&mut self, increment: f32)

Advances the internal state of the sawtooth profile and calculates its current normalized output level.

This method increments an internal counter. When the counter reaches the end of a full cycle (defined by the sum of all phase lengths), it resets to the beginning. Based on the current value of the counter, the function then determines which phase of the sawtooth profile is active and updates level_normalized accordingly. The output level_normalized ranges from 0.0 to 1.0.

§Arguments
  • increment - The step value by which the internal counter should be advanced in this execution. This value determines the “speed” at which the profile progresses.

Trait Implementations§

Source§

impl Display for SawToothProfile

Source§

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

Formats the SawToothProfile struct into a multi-line, human-readable string.

This implementation is primarily for debugging and logging purposes, providing a detailed view of the filter’s current state, including its internal counter, normalized output level, and the limits for each phase.

§Arguments
  • f - A mutable reference to the formatter, as required by the fmt::Display trait.
§Returns

A fmt::Result indicating whether the formatting operation was successful.

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T