]>
git.scottworley.com Git - tattlekey/blob - client/press.c
7a7f99678ad6b64d48f6767620bce97fc9065bbc
4 static uint32_t next_send(press_t
*s
) {
5 return s
->timestamp
+ (1 << s
->send_count
) - 1;
8 static bool next_send_less_than(void *user_data
, pheap_node_id_t a
,
10 press_t
*presses
= (press_t
*)user_data
;
11 return next_send(&presses
[a
]) < next_send(&presses
[b
]);
14 press_pile_t
*create_press_pile() {
15 press_pile_t
*pp
= (press_pile_t
*)malloc(sizeof(press_pile_t
));
17 signal_error_by_blinking();
18 pp
->presses
= calloc(PICO_PHEAP_MAX_ENTRIES
, sizeof(press_t
));
19 if (pp
->presses
== NULL
)
20 signal_error_by_blinking();
22 ph_create(PICO_PHEAP_MAX_ENTRIES
, next_send_less_than
, pp
->presses
);
23 if (pp
->sleeps_heap
== NULL
)
24 signal_error_by_blinking();
28 void create_press(press_pile_t
*pp
, uint32_t timestamp
, u16_t seq
) {
29 pheap_node_id_t i
= ph_new_node(pp
->sleeps_heap
);
31 /* TODO: Don't drop new presses just because sleeps_heap is full of old
35 pp
->presses
[i
].timestamp
= timestamp
;
36 pp
->presses
[i
].seq
= seq
;
37 pp
->presses
[i
].send_count
= 0;
38 ph_insert_node(pp
->sleeps_heap
, i
);
41 int32_t next_scheduled_send(press_pile_t
*pp
) {
42 pheap_node_id_t i
= ph_peek_head(pp
->sleeps_heap
);
45 return next_send(&pp
->presses
[i
]);