pub struct PowerPlan { /* private fields */ }Expand description
Maps a battery state of charge onto a PowerMode and a work interval.
As the battery drains, a node should do less: sample and transmit less often so
it survives the night or a cloudy week. A PowerPlan encodes that policy as
three intervals and two thresholds. Feed it a state of charge in [0.0, 1.0]
and it returns the mode to run in and how long to wait before the next cycle.
When the panel is charging it eases off by one mode, since incoming energy buys
back some headroom.
§Examples
use core::time::Duration;
use pamoja_power::{PowerMode, PowerPlan};
let plan = PowerPlan::new(
Duration::from_secs(60),
Duration::from_secs(600),
Duration::from_secs(3600),
);
// Low battery means the saver cadence...
assert_eq!(plan.mode(0.3), PowerMode::Saver);
// ...unless the panel is charging, which buys back the active cadence.
assert_eq!(plan.mode_while_charging(0.3, true), PowerMode::Active);Implementations§
Source§impl PowerPlan
impl PowerPlan
Sourcepub fn new(active: Duration, saver: Duration, critical: Duration) -> Self
pub fn new(active: Duration, saver: Duration, critical: Duration) -> Self
Creates a plan from its three work intervals, with default thresholds.
The defaults enter PowerMode::Saver below 50% charge and
PowerMode::Critical below 20%.
§Arguments
active- the interval at a healthy charge.saver- the longer interval used to conserve, normally larger thanactive.critical- the longest interval, used when charge is critically low.
§Returns
The power plan.
Sourcepub fn thresholds(self, saver_below: f32, critical_below: f32) -> Self
pub fn thresholds(self, saver_below: f32, critical_below: f32) -> Self
Sets the state-of-charge thresholds for entering each lower mode.
§Arguments
saver_below- enterPowerMode::Saverwhen charge is below this.critical_below- enterPowerMode::Criticalwhen charge is below this, normally lower thansaver_below.
§Returns
The updated plan, for chaining.
Sourcepub fn saver_below(&self) -> f32
pub fn saver_below(&self) -> f32
Returns the charge below which the plan enters PowerMode::Saver.
§Returns
The saver threshold as a state of charge in [0.0, 1.0].
Sourcepub fn critical_below(&self) -> f32
pub fn critical_below(&self) -> f32
Returns the charge below which the plan enters PowerMode::Critical.
§Returns
The critical threshold as a state of charge in [0.0, 1.0].
Sourcepub fn mode_while_charging(&self, soc: f32, charging: bool) -> PowerMode
pub fn mode_while_charging(&self, soc: f32, charging: bool) -> PowerMode
Returns the mode for the given charge, easing off by one step when charging.
§Arguments
soc- the battery state of charge in[0.0, 1.0].charging- whether the panel is currently delivering charge.
§Returns
The PowerMode, promoted one step toward PowerMode::Active while
charging is true.