X-Git-Url: http://git.scottworley.com/tattlekey/blobdiff_plain/00ca9fa67636580409193bf7a9baf394113b4af8..0527f2292fd8cb1585d63cee916f918cc0a65098:/client/press.h?ds=sidebyside diff --git a/client/press.h b/client/press.h index b13f9a8..6cd4c5b 100644 --- a/client/press.h +++ b/client/press.h @@ -3,6 +3,7 @@ #include "pico/cyw43_arch.h" #include "pico/util/pheap.h" +#include "pico/util/queue.h" typedef struct { uint32_t timestamp; @@ -10,13 +11,33 @@ typedef struct { u8_t send_count; } press_t; -bool next_send_less_than(void *user_data, pheap_node_id_t a, pheap_node_id_t b); +typedef struct { + /* Queues of various sizes that hold presses. There is one queue for each + * send_count. */ + queue_t *presses; + + /* Tracks when each queue will be next ready-to-send. Empty queues are not in + * the heap. */ + pheap_t *sleeps_heap; + + /* The companion-array for the heap. */ + queue_t **sleeps; -void create_press(press_t *presses, pheap_t *sleeps_heap, uint32_t timestamp, - u16_t seq); +} press_pile_t; + +press_pile_t *create_press_pile(); + +/* Adds this press to the pile. + * Copies the contents of `press`. */ +void add_press(press_pile_t *pp, press_t *press); /* When do we next need to send something (in seconds since boot)? * Returns -1 if there's nothing pending. */ -int32_t next_scheduled_send(press_t *presses, pheap_t *sleeps_heap); +int32_t next_scheduled_send(press_pile_t *pp); + +/* Find a press ready for resend at or before `now`. + * Move it out of the press-pile `pp` and into into `press`. + * Or return false if there is no press due for re-send. */ +bool get_press_due_for_resend(press_pile_t *pp, uint32_t now, press_t *press); #endif