1 #include "pico/cyw43_arch.h"
2 #include "pico/stdlib.h"
3 #include "pico/util/queue.h"
12 uint32_t time_s() { return time_us_64() / 1000000ul; }
14 static void button_pressed() {
15 /* This runs in interrupt context; don't linger. */
16 static uint64_t last_button_press_time
= 0;
17 uint32_t now
= time_s();
18 uint32_t time_since_last_press
= now
- last_button_press_time
;
19 if (time_since_last_press
>= minimum_seconds_between_button_presses
) {
20 last_button_press_time
= now
;
21 /* We don't check for failure (full queue) here because there's not much to
22 * be done about it. */
23 queue_try_add(&queue
, &now
);
29 if (cyw43_arch_init_with_country(CYW43_COUNTRY_USA
))
30 signal_error_by_blinking();
31 cyw43_arch_enable_sta_mode();
33 if (cyw43_arch_wifi_connect_timeout_ms(wifi_ssid
, wifi_pass
,
34 CYW43_AUTH_WPA2_AES_PSK
, 90000))
35 signal_error_by_blinking();
38 queue_init(&queue
, sizeof(uint32_t), 99);
40 begin_listening_for_button_press(button_pressed
);
45 queue_remove_blocking(&queue
, &t
);
47 for (int i
= 0; i
< resend_count
; i
++) {
48 uint32_t now
= time_s();
49 uint32_t ago
= now
- t
;
50 send_report(seq
, ago
);
51 signal(i
== 0 ? 2 : 1, 100);
52 sleep_ms(resend_interval_ms
);