]> git.scottworley.com Git - tattlekey/blob - client/press.h
6cd4c5b7faa5cfacf0d5cfa1f65c62d0019efe8a
[tattlekey] / client / press.h
1 #ifndef SENDS_H
2 #define SENDS_H
3
4 #include "pico/cyw43_arch.h"
5 #include "pico/util/pheap.h"
6 #include "pico/util/queue.h"
7
8 typedef struct {
9 uint32_t timestamp;
10 u16_t seq;
11 u8_t send_count;
12 } press_t;
13
14 typedef struct {
15 /* Queues of various sizes that hold presses. There is one queue for each
16 * send_count. */
17 queue_t *presses;
18
19 /* Tracks when each queue will be next ready-to-send. Empty queues are not in
20 * the heap. */
21 pheap_t *sleeps_heap;
22
23 /* The companion-array for the heap. */
24 queue_t **sleeps;
25
26 } press_pile_t;
27
28 press_pile_t *create_press_pile();
29
30 /* Adds this press to the pile.
31 * Copies the contents of `press`. */
32 void add_press(press_pile_t *pp, press_t *press);
33
34 /* When do we next need to send something (in seconds since boot)?
35 * Returns -1 if there's nothing pending. */
36 int32_t next_scheduled_send(press_pile_t *pp);
37
38 /* Find a press ready for resend at or before `now`.
39 * Move it out of the press-pile `pp` and into into `press`.
40 * Or return false if there is no press due for re-send. */
41 bool get_press_due_for_resend(press_pile_t *pp, uint32_t now, press_t *press);
42
43 #endif