Loading...
Searching...
No Matches
store_poll.h
Go to the documentation of this file.
1
7#pragma once
8#include <pebble.h>
9#include <time.h>
10
15
26static inline time_t store_poll_next(int poll_min, time_t now)
27{
28 time_t interval = (time_t)poll_min * SECONDS_PER_MINUTE;
29 return ((now / interval) + 1) * interval;
30}
31
43static inline bool store_poll_due(int poll_min, time_t *next, time_t now)
44{
45 if (poll_min <= 0)
46 {
47 return false;
48 }
49
50 time_t interval = (time_t)poll_min * SECONDS_PER_MINUTE;
51 if (*next > now + interval)
52 {
53 *next = store_poll_next(poll_min, now);
54 }
55
56 if (now < *next)
57 {
58 return false;
59 }
60
61 *next = store_poll_next(poll_min, now);
62 return true;
63}
64
77static inline bool store_poll_reconnect_due(int age_s, int poll_min)
78{
79 if (poll_min <= 0)
80 {
81 return false;
82 }
83 // a clock set back makes a saved reading's age negative too, so it reads as never arrived and the
84 // reconnect asks again. the first answer resets the age, and a reconnect means the phone is there
85 // to give one, so it costs about one fetch. counting that age as fresh instead would skip every
86 // reconnect fetch until the clock caught up, which can be hours
87 return age_s < 0 || age_s >= poll_min * SECONDS_PER_MINUTE;
88}
89
91typedef struct
92{
93 time_t next;
95 bool live;
96} StorePoll;
97
111bool store_poll_set(StorePoll *poll, int poll_min, bool live, time_t now);
112
120bool store_poll_turn(StorePoll *poll, time_t now);
121
bool store_poll_set(StorePoll *poll, int poll_min, bool live, time_t now)
Take a store's interval and whether it is live, as its init and its reconfigure both do.
Definition store_poll.c:12
bool store_poll_turn(StorePoll *poll, time_t now)
A store's turn on the face's cadence: whether a poll should go out now.
Definition store_poll.c:26
static bool store_poll_reconnect_due(int age_s, int poll_min)
Whether a reading is worth asking for again now that the phone is back.
Definition store_poll.h:77
static bool store_poll_due(int poll_min, time_t *next, time_t now)
Whether next has come round, moving it on to the following deadline when it has.
Definition store_poll.h:43
static time_t store_poll_next(int poll_min, time_t now)
The next wall-clock second a poll of this interval falls due.
Definition store_poll.h:26
One store's polling: its interval, whether it polls at all, and when it is next due.
Definition store_poll.h:92
time_t next
Wall-clock second the next recurring poll is due.
Definition store_poll.h:93
int poll_min
Minutes between polls. 0 or less means no recurring poll.
Definition store_poll.h:94
bool live
True on a live face. A store seeded with fixtures never polls.
Definition store_poll.h:95
#define SECONDS_PER_MINUTE
Seconds in a minute, so the epoch maths reads as what it is.
Definition timeband.c:12