+ while (1) {
+ uint32_t now = time_s();
+ int32_t act_time = next_scheduled_send(presses, sleeps_heap);
+ if (act_time == -1)
+ return;
+ if (act_time > now) {
+ set_resend_alarm(alarm, now, act_time);
+ return;
+ }
+ pheap_node_id_t i = ph_remove_head(sleeps_heap, false);
+ press_t *press = &presses[i];
+ uint32_t ago = now - press->timestamp;
+ send_report_packet(press->seq, ago);
+ press->send_count++;
+ if (press->send_count < config_resend_count)
+ ph_insert_node(sleeps_heap, i);
+ else
+ ph_free_node(sleeps_heap, i);
+ }
+}