pub struct AlarmManager {
rtc: Rtc,
scheduled_alarms: BTreeMap<AlarmType, ScheduledAlarm>,
}Expand description
Multiplexes multiple logical alarms onto a single hardware RTC alarm.
The hardware RTC supports only one wake alarm at a time. AlarmManager
maintains a map of logical alarms keyed by AlarmType and always
programs the hardware with the earliest upcoming wake time. After each
wake, AlarmManager::check_fired_alarms determines which logical alarms fired and
reschedules the hardware for any remaining ones.
Fields§
§rtc: Rtc§scheduled_alarms: BTreeMap<AlarmType, ScheduledAlarm>Implementations§
Source§impl AlarmManager
impl AlarmManager
pub fn new(rtc: Rtc) -> Self
Sourcepub fn schedule_alarm(
&mut self,
alarm_type: AlarmType,
duration: Duration,
) -> Result<(), Error>
pub fn schedule_alarm( &mut self, alarm_type: AlarmType, duration: Duration, ) -> Result<(), Error>
Schedule a logical alarm to fire duration from now.
If an alarm of the same type is already scheduled it is replaced. The hardware RTC is updated to reflect the new earliest wake time.
Sourcepub fn cancel_alarm(&mut self, alarm_type: AlarmType) -> Result<(), Error>
pub fn cancel_alarm(&mut self, alarm_type: AlarmType) -> Result<(), Error>
Cancel a previously scheduled logical alarm.
If no alarm of that type is scheduled this is a no-op. The hardware RTC is updated to reflect the new earliest remaining wake time.
Sourcepub fn is_alarm_scheduled(&self, alarm_type: AlarmType) -> bool
pub fn is_alarm_scheduled(&self, alarm_type: AlarmType) -> bool
Returns true if an alarm of alarm_type is scheduled for a future time.
Sourcepub fn has_alarm(&self, alarm_type: AlarmType) -> bool
pub fn has_alarm(&self, alarm_type: AlarmType) -> bool
Returns true if an alarm of alarm_type exists in the schedule.
Sourcepub fn ensure_scheduled(
&mut self,
alarm_type: AlarmType,
duration: Duration,
past_due_action: PastDueAction,
) -> Result<EnsureAlarmOutcome, Error>
pub fn ensure_scheduled( &mut self, alarm_type: AlarmType, duration: Duration, past_due_action: PastDueAction, ) -> Result<EnsureAlarmOutcome, Error>
Ensures an alarm of alarm_type is active and scheduled for the future.
- If no alarm exists, one is scheduled for
now + duration. - If an alarm exists and is in the future, nothing changes.
- If an alarm exists but is past-due, the stale entry is always
cancelled.
past_due_actionthen controls whether a fresh alarm is scheduled:PastDueAction::Rescheduleschedules a new one and returnsEnsureAlarmOutcome::Scheduled;PastDueAction::Cancelstops there and returnsEnsureAlarmOutcome::PastDueso the caller can decide what action to take.
Sourcepub fn time_until_alarm(&self, alarm_type: AlarmType) -> Option<i64>
pub fn time_until_alarm(&self, alarm_type: AlarmType) -> Option<i64>
Returns the number of seconds until alarm_type fires, or None if
it is not scheduled.
Sourcepub fn check_fired_alarms(
&mut self,
before: DateTime<Utc>,
after: DateTime<Utc>,
) -> Result<Vec<AlarmType>, Error>
pub fn check_fired_alarms( &mut self, before: DateTime<Utc>, after: DateTime<Utc>, ) -> Result<Vec<AlarmType>, Error>
Determines which logical alarms fired during the last sleep cycle.
before is the timestamp just before the device went to sleep and
after is the timestamp just after it woke. A hardware alarm is
considered fired when it is disabled or when the sleep duration is
within 3 seconds of the expected wake time (accounting for RTC
granularity). Any fired logical alarms are removed from the schedule
and the hardware is reprogrammed for the next earliest alarm.
fn update_hardware_alarm(&self) -> Result<(), Error>
Auto Trait Implementations§
impl Freeze for AlarmManager
impl RefUnwindSafe for AlarmManager
impl Send for AlarmManager
impl Sync for AlarmManager
impl Unpin for AlarmManager
impl UnsafeUnpin for AlarmManager
impl UnwindSafe for AlarmManager
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more