]> git.scottworley.com Git - tattlekey/blame - client/press.h
client: Explain the exponential re-send delay
[tattlekey] / client / press.h
CommitLineData
a4a617fd
SW
1/* tattlekey: A one-key UDP keyboard
2 * Copyright (C) 2023 Scott Worley <scottworley@scottworley.com>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
2dcbb2a0
SW
18#ifndef SENDS_H
19#define SENDS_H
20
21#include "pico/cyw43_arch.h"
22#include "pico/util/pheap.h"
0527f229 23#include "pico/util/queue.h"
2dcbb2a0
SW
24
25typedef struct {
26 uint32_t timestamp;
27 u16_t seq;
28 u8_t send_count;
17461dec 29} press_t;
2dcbb2a0 30
e3ff9e0d 31typedef struct {
0527f229
SW
32 /* Queues of various sizes that hold presses. There is one queue for each
33 * send_count. */
34 queue_t *presses;
35
36 /* Tracks when each queue will be next ready-to-send. Empty queues are not in
37 * the heap. */
e3ff9e0d 38 pheap_t *sleeps_heap;
0527f229
SW
39
40 /* The companion-array for the heap. */
41 queue_t **sleeps;
42
e3ff9e0d
SW
43} press_pile_t;
44
45press_pile_t *create_press_pile();
2dcbb2a0 46
f68e05b2
SW
47/* Adds this press to the pile.
48 * Copies the contents of `press`. */
49void add_press(press_pile_t *pp, press_t *press);
67001c93 50
b512ec26
SW
51/* When do we next need to send something (in seconds since boot)?
52 * Returns -1 if there's nothing pending. */
e3ff9e0d 53int32_t next_scheduled_send(press_pile_t *pp);
b512ec26 54
9ae691e9
SW
55/* Find a press ready for resend at or before `now`.
56 * Move it out of the press-pile `pp` and into into `press`.
57 * Or return false if there is no press due for re-send. */
58bool get_press_due_for_resend(press_pile_t *pp, uint32_t now, press_t *press);
59
2dcbb2a0 60#endif