schedule¶
When to fetch data, when to stay awake and how long to sleep.
Attributes¶
Functions¶
|
Seconds to keep the web API up before sleeping. |
|
Decide whether this wake fetches new data. |
|
Return the sleep time to wake just after the next full minute. |
|
Check whether local |
|
(fetch interval in s, minute clock on?) for the current conditions. |
|
Minutes from local |
|
Deep sleep time until the next wake, always just after a full minute. |
|
Decide whether a data update needs a full (flashing) refresh. |
|
Return when the next fetch will happen. |
Module Contents¶
- schedule.FETCH_SLACK_S = 30¶
- schedule.awake_window_s(woke_from_deep_sleep, window_s)¶
Seconds to keep the web API up before sleeping.
Only after a reset (power on, reset button, deploy): that is when a person may want to reach the board. Timer wakes go straight back to sleep to save battery.
- schedule.fetch_due(woke_from_deep_sleep, state, now_s, interval_s)¶
Decide whether this wake fetches new data.
A fetch means connecting to the WLAN and redrawing the whole screen; otherwise only the header is updated.
- schedule.ms_to_next_minute(ms_into_minute, margin_ms=500, min_ms=1000)¶
Return the sleep time to wake just after the next full minute.
That way a displayed time changes right when the minute does.
- schedule.MINUTES_PER_DAY = 1440¶
- schedule.is_night(minute, start, end)¶
Check whether local
minute(since midnight) lies in [start, end).The range may span midnight, as from 23:00 to 06:00 does.
- schedule.update_mode(minute, battery_percent, battery_modes, night, night_interval_s)¶
(fetch interval in s, minute clock on?) for the current conditions.
battery_modesare (from percent, fetch interval s, minute clock) rows, highest threshold first; the first row the battery reaches applies. Duringnight((start, end) in local minutes; None disables it) the clock is off and fetches are at most everynight_interval_s. With an unset clock (minuteNone) there is no night.
- schedule.minutes_until(minute, target)¶
Minutes from local
minuteto the nexttarget(1..1440).
- schedule.sleep_ms(ms_into_minute, clock, since_fetch_s, interval_s, until_change_s=None)¶
Deep sleep time until the next wake, always just after a full minute.
With the minute clock on, that is the next minute. Otherwise it is the next fetch (
interval_safter the last one,since_fetch_sago), oruntil_change_sif the mode changes earlier (e.g. the night ends).
- schedule.full_refresh_due(had_full_since_reset, full_at, now_s, interval_s)¶
Decide whether a data update needs a full (flashing) refresh.
It does first after any reset other than a deep-sleep wake (the saved image may not match the panel, after an interrupted update for instance), otherwise every
interval_sagainst ghosting.