pub struct DutyCycle { /* private fields */ }Expand description
A repeating wake/sleep schedule.
Duty cycling is the simplest way to make a battery or solar node last: stay awake just long enough to do the work, then sleep through the rest of the period. The duty fraction - the share of each period spent awake - is a good first proxy for average power draw, so roughly halving it halves the energy the cycle costs.
§Examples
use core::time::Duration;
use pamoja_power::DutyCycle;
// Wake for one second every minute.
let cycle = DutyCycle::new(Duration::from_secs(1), Duration::from_secs(59));
assert_eq!(cycle.period(), Duration::from_secs(60));
assert!((cycle.fraction() - 1.0 / 60.0).abs() < 1e-6);Implementations§
Source§impl DutyCycle
impl DutyCycle
Sourcepub fn from_fraction(period: Duration, fraction: f32) -> Self
pub fn from_fraction(period: Duration, fraction: f32) -> Self
Creates a duty cycle from a period and the fraction of it to stay awake.
§Arguments
period- the full wake-plus-sleep period.fraction- the share of the period to stay awake, clamped to[0.0, 1.0]. A fraction that is not a number keeps the node asleep for the whole period, since a budget worked out from a failed reading is no budget.
§Returns
A duty cycle whose awake time is fraction of period.
Sourcepub fn period(&self) -> Duration
pub fn period(&self) -> Duration
Returns the full period, awake plus asleep, held at Duration::MAX rather
than overflowing.
Trait Implementations§
impl Copy for DutyCycle
impl Eq for DutyCycle
impl StructuralPartialEq for DutyCycle
Auto Trait Implementations§
impl Freeze for DutyCycle
impl RefUnwindSafe for DutyCycle
impl Send for DutyCycle
impl Sync for DutyCycle
impl Unpin for DutyCycle
impl UnsafeUnpin for DutyCycle
impl UnwindSafe for DutyCycle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more