Skip to main content

pamoja_power/
lib.rs

1#![cfg_attr(not(test), no_std)]
2
3//! Power-aware scheduling for the pamoja SDK.
4//!
5//! A node on a battery or a solar panel lives or dies by how much it sleeps. This
6//! crate holds the scheduling math that keeps such a node alive, with no runtime
7//! and no hardware assumptions, so the same decisions can be made on a
8//! microcontroller and verified on a server:
9//!
10//! - [`DutyCycle`] - trade wakefulness for battery life with a repeating
11//!   wake/sleep schedule, and read back the duty fraction as a power proxy.
12//! - [`PowerPlan`] - an energy-aware governor that stretches the sampling interval
13//!   as the battery drains, picking a [`PowerMode`] from the state of charge and
14//!   easing off when the panel is charging.
15//!
16//! The state of charge fed to a [`PowerPlan`] is noisy in the field, so smoothing
17//! it first (for example with a `Smoother` from `pamoja-kit`) keeps the governor
18//! from flapping between modes at a threshold.
19//!
20//! The crate is `no_std` and allocation-free.
21//!
22//! # Examples
23//!
24//! ```
25//! use core::time::Duration;
26//! use pamoja_power::{PowerMode, PowerPlan};
27//!
28//! let plan = PowerPlan::new(
29//!     Duration::from_secs(60), // sample each minute when healthy
30//!     Duration::from_secs(600), // back off to ten minutes to conserve
31//!     Duration::from_secs(3600), // once an hour when critically low
32//! );
33//!
34//! assert_eq!(plan.mode(0.8), PowerMode::Active);
35//! assert_eq!(plan.interval(0.1), Duration::from_secs(3600));
36//! ```
37
38mod duty;
39mod plan;
40
41pub use duty::DutyCycle;
42pub use plan::{PowerMode, PowerPlan};