1 #include "pico/cyw43_arch.h"
2 #include "pico/stdlib.h"
3 #include "pico/util/queue.h"
10 enum event_type
{ BUTTONPRESS
};
22 uint32_t time_s() { return time_us_64() / 1000000ul; }
24 static void button_pressed() {
25 /* This runs in interrupt context; don't linger. */
26 static uint64_t last_button_press_time
= 0;
27 uint32_t now
= time_s();
28 uint32_t time_since_last_press
= now
- last_button_press_time
;
29 if (time_since_last_press
>= config_minimum_seconds_between_button_presses
) {
30 last_button_press_time
= now
;
33 e
.buttonpress
.timestamp
= now
;
34 /* We don't check for failure (full queue) here because there's not much to
35 * be done about it. */
36 queue_try_add(&queue
, &e
);
42 if (cyw43_arch_init_with_country(CYW43_COUNTRY_USA
))
43 signal_error_by_blinking();
44 cyw43_arch_enable_sta_mode();
46 if (cyw43_arch_wifi_connect_timeout_ms(config_wifi_ssid
, config_wifi_pass
,
47 CYW43_AUTH_WPA2_AES_PSK
, 90000))
48 signal_error_by_blinking();
51 queue_init(&queue
, sizeof(event_t
), 99);
53 begin_listening_for_button_press(button_pressed
);
58 queue_remove_blocking(&queue
, &e
);
62 for (int i
= 0; i
< config_resend_count
; i
++) {
63 uint32_t now
= time_s();
64 uint32_t ago
= now
- e
.buttonpress
.timestamp
;
65 send_report(seq
, ago
);
66 signal(i
== 0 ? 2 : 1, 100);
67 sleep_ms(config_resend_interval_ms
);
71 signal_error_by_blinking();