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§
- Timer
Duration - Duration type for timer periods
- Timer
Handle - A handle to a timer stored in a node
- Timer
State - Internal timer state
Enums§
- Timer
Mode - Timer mode (repeating, one-shot, or inert)
Type Aliases§
- Timer
Callback Fn - Timer callback as a bare function pointer (
no_std, no heap required).