timed-signal 0.2.0

Helper crate for generating time-dependent signals.
Documentation
  • Coverage
  • 100%
    26 out of 26 items documented1 out of 26 items with examples
  • Size
  • Source code size: 24.32 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.04 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • sourcebox/timed-signal-rs
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sourcebox

timed-signal

no_std Rust helper crate for generating time-dependent signals offering the following features:

  • Static on, off and toggle.
  • Scheduled state changes.
  • Pulse of specific duration with single and retrigger.
  • Synchronous blink of multiple signals.

Usage

  • Create an instance of TimedSignal.
  • Set the signal state either statically or to be changed dynamically dependent on a tick value.
  • Call the update() function with a tick current value as argument. It will return the state of the signal according to the tick. The tick value can be of any unit, e.g. milliseconds or microseconds. There's no requirement for a continuous value, but it must be increasing monotonically.

Example

use timed_signal::TimedSignal;

// Create some instances of to drive LEDs.
let mut led1 = TimedSignal::new();
let mut led2 = TimedSignal::new();
let mut led3 = TimedSignal::new();

// Blink LED1 with a period of 4. LED will then be on for 2 ticks and off for another 2.
led1.blink(4);

// Set LED2 on until a specific tick is reached.
led2.on_until(10);

// Toggle LED3 for a number of ticks.
led3.toggle_for(20);

// Just a dummy loop to iterate over the tick.
for tick in 0..100 {
    let state1 = led1.update(tick);
    let state2 = led2.update(tick);
    let state3 = led3.update(tick);
    println!("{}: {:?} {:?} {:?}", tick, state1, state2, state3);
}

Tests

Run cargo test for the unit tests.

License

Published under the MIT license. Any contribution to this project must be provided under the same license conditions.

Author: Oliver Rockstedt info@sourcebox.de