]> git.scottworley.com Git - tattlekey/blobdiff - client/press.h
client: Hold presses in queues, one queue per send_count
[tattlekey] / client / press.h
index 898bb1a85a4334c3cbb1e83046813100da251aac..6cd4c5b7faa5cfacf0d5cfa1f65c62d0019efe8a 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "pico/cyw43_arch.h"
 #include "pico/util/pheap.h"
+#include "pico/util/queue.h"
 
 typedef struct {
   uint32_t timestamp;
@@ -11,8 +12,17 @@ typedef struct {
 } press_t;
 
 typedef struct {
-  press_t *presses;
+  /* 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;
+
 } press_pile_t;
 
 press_pile_t *create_press_pile();
@@ -25,4 +35,9 @@ void add_press(press_pile_t *pp, press_t *press);
  * Returns -1 if there's nothing pending. */
 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