]> git.scottworley.com Git - tattlekey/blame - client/press.h
client: Make the queue size bounds configurable
[tattlekey] / client / press.h
CommitLineData
2dcbb2a0
SW
1#ifndef SENDS_H
2#define SENDS_H
3
4#include "pico/cyw43_arch.h"
5#include "pico/util/pheap.h"
0527f229 6#include "pico/util/queue.h"
2dcbb2a0
SW
7
8typedef struct {
9 uint32_t timestamp;
10 u16_t seq;
11 u8_t send_count;
17461dec 12} press_t;
2dcbb2a0 13
e3ff9e0d 14typedef struct {
0527f229
SW
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. */
e3ff9e0d 21 pheap_t *sleeps_heap;
0527f229
SW
22
23 /* The companion-array for the heap. */
24 queue_t **sleeps;
25
e3ff9e0d
SW
26} press_pile_t;
27
28press_pile_t *create_press_pile();
2dcbb2a0 29
f68e05b2
SW
30/* Adds this press to the pile.
31 * Copies the contents of `press`. */
32void add_press(press_pile_t *pp, press_t *press);
67001c93 33
b512ec26
SW
34/* When do we next need to send something (in seconds since boot)?
35 * Returns -1 if there's nothing pending. */
e3ff9e0d 36int32_t next_scheduled_send(press_pile_t *pp);
b512ec26 37
9ae691e9
SW
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. */
41bool get_press_due_for_resend(press_pile_t *pp, uint32_t now, press_t *press);
42
2dcbb2a0 43#endif