+ while (1) {
+ uint32_t now = time_s();
+ int32_t act_time = next_scheduled_send(pp);
+ if (act_time == -1)
+ return;
+ if (act_time > now) {
+ set_resend_alarm(alarm, now, act_time);
+ return;
+ }
+ press_t press;
+ if (!get_press_due_for_resend(pp, now, &press))
+ signal_error_by_blinking();
+ uint32_t ago = now - press.timestamp;
+ send_report_packet(press.seq, ago);
+ press.send_count++;
+ if (press.send_count < config_resend_count) {
+ add_press(pp, &press);
+ }
+ }
+}
+
+void service_queue() {
+ int alarm = hardware_alarm_claim_unused(true);
+ if (alarm == -1)
+ signal_error_by_blinking();
+ hardware_alarm_set_callback(alarm, time_to_send);