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: f32This variable counts the number of iterations executed and is reset to zero when reaching the end of the profile.
level_normalized: f32Variable with values from zero to one. This is the output of the saw tooth profile component.
phase1_counter_limit: f32This variable is set to the same value as the length of the first phase.
phase2_counter_limit: f32This variable is set to the cumulated length of the first and second phase.
phase3_counter_limit: f32This variable is set to the cumulated length of the first three phases.
phase4_counter_limit: f32This variable is set to the cumulated length of all phases.
Implementations§
Source§impl SawToothProfile
impl SawToothProfile
Sourcepub fn new(config: &SawToothProfileConfig) -> SawToothProfile
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 aSawToothProfileConfigstruct, 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.
Sourcepub fn execute_with(&mut self, increment: f32)
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
impl Display for SawToothProfile
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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 thefmt::Displaytrait.
§Returns
A fmt::Result indicating whether the formatting operation was successful.