Skip to main content

Module timer

Module timer 

Source
Expand description

Timer API for nros

This module provides timer support matching rclrs patterns while maintaining no_std compatibility for embedded systems.

§Overview

Timers allow scheduling periodic or one-shot callbacks. In embedded environments without background threads, timers must be processed manually via process_timers().

§Timer Modes

  • Repeating: Fires at regular intervals until canceled
  • OneShot: Fires once after a delay, then becomes inert
  • Inert: Never fires, useful as a placeholder

§Example (with std)

use nros::prelude::*;
use nros::timer::Duration;

let mut node = ConnectedNode::connect(config, locator)?;

// Create a repeating timer
let timer = node.create_timer_repeating(
    Duration::from_millis(100),
    || println!("Timer fired!"),
)?;

// Process timers periodically
loop {
    node.process_timers(10); // 10ms elapsed
    std::thread::sleep(std::time::Duration::from_millis(10));
}

§Example (RTIC)

// In RTIC, use a periodic task to process timers
#[task(priority = 2, shared = [node])]
async fn timer_process(mut cx: timer_process::Context) {
    loop {
        cx.shared.node.lock(|node| {
            node.process_timers(TIMER_PROCESS_INTERVAL_MS as u64);
        });
        Systick::delay(TIMER_PROCESS_INTERVAL_MS.millis()).await;
    }
}

Structs§

TimerDuration
Duration type for timer periods
TimerHandle
A handle to a timer stored in a node
TimerState
Internal timer state

Enums§

TimerMode
Timer mode (repeating, one-shot, or inert)

Type Aliases§

TimerCallbackFn
Timer callback as a bare function pointer (no_std, no heap required).