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