]> git.scottworley.com Git - tattlekey/blob - client/press.h
client: Change wire format!: Expand `ago` field: 16 bits → 32 bits
[tattlekey] / client / press.h
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
18 #ifndef SENDS_H
19 #define SENDS_H
20
21 #include "pico/cyw43_arch.h"
22 #include "pico/util/pheap.h"
23 #include "pico/util/queue.h"
24
25 typedef struct {
26 uint32_t timestamp;
27 u16_t seq;
28 u8_t send_count;
29 } press_t;
30
31 typedef struct {
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. */
38 pheap_t *sleeps_heap;
39
40 /* The companion-array for the heap. */
41 queue_t **sleeps;
42
43 } press_pile_t;
44
45 press_pile_t *create_press_pile();
46
47 /* Adds this press to the pile.
48 * Copies the contents of `press`. */
49 void add_press(press_pile_t *pp, press_t *press);
50
51 /* When do we next need to send something (in seconds since boot)?
52 * Returns -1 if there's nothing pending. */
53 int32_t next_scheduled_send(press_pile_t *pp);
54
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. */
58 bool get_press_due_for_resend(press_pile_t *pp, uint32_t now, press_t *press);
59
60 #endif