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
97typedef struct
98{
99 time_t next;
101 bool live;
102 bool pinned;
103} StorePoll;
104
124bool store_poll_start(StorePoll *poll, int poll_min, bool live, time_t now);
125
141bool store_poll_set(StorePoll *poll, int poll_min, bool live, time_t now);
142
150bool store_poll_turn(StorePoll *poll, time_t now);
151
163bool store_poll_reconnect(const StorePoll *poll, int age_s);
164
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 reconfigure does.
Definition store_poll.c:20
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:34
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
bool store_poll_reconnect(const StorePoll *poll, int age_s)
A store's catch-up when the phone comes back: whether to ask for its reading again.
Definition store_poll.c:39
bool store_poll_start(StorePoll *poll, int poll_min, bool live, time_t now)
Take a store's interval and whether it is live, as its init does.
Definition store_poll.c:14
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:98
time_t next
Wall-clock second the next recurring poll is due.
Definition store_poll.h:99
int poll_min
Minutes between polls. 0 or less means no recurring poll.
Definition store_poll.h:100
bool pinned
True when init started the store not live, so no reconfigure turns it live.
Definition store_poll.h:102
bool live
True on a live face. A store seeded with fixtures never polls.
Definition store_poll.h:101
#define SECONDS_PER_MINUTE
Seconds in a minute, so the epoch maths reads as what it is.
Definition timeband.c:12