]>
Commit | Line | Data |
---|---|---|
e2173399 | 1 | #include "pico/cyw43_arch.h" |
5ec2b60a | 2 | #include "pico/stdlib.h" |
1427141a | 3 | #include "pico/util/queue.h" |
5ec2b60a | 4 | |
dae35db7 | 5 | #include "blink.h" |
d1521eda | 6 | #include "button.h" |
fbc57595 | 7 | #include "config.h" |
1e0a316e | 8 | #include "net.h" |
d234f6b3 | 9 | |
1427141a | 10 | queue_t queue; |
d1521eda | 11 | |
de14b62c SW |
12 | uint32_t time_s() { return time_us_64() / 1000000ul; } |
13 | ||
d1521eda | 14 | static void button_pressed() { |
1427141a | 15 | /* This runs in interrupt context; don't linger. */ |
2f7a1e89 | 16 | static uint64_t last_button_press_time = 0; |
de14b62c SW |
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) { | |
2f7a1e89 | 20 | last_button_press_time = now; |
2f7a1e89 SW |
21 | /* We don't check for failure (full queue) here because there's not much to |
22 | * be done about it. */ | |
c8c900a6 | 23 | queue_try_add(&queue, &now); |
2f7a1e89 | 24 | } |
d1521eda SW |
25 | } |
26 | ||
75649fe3 SW |
27 | int main() { |
28 | stdio_init_all(); | |
d234f6b3 | 29 | if (cyw43_arch_init_with_country(CYW43_COUNTRY_USA)) |
75649fe3 | 30 | signal_error_by_blinking(); |
d234f6b3 | 31 | cyw43_arch_enable_sta_mode(); |
38d971ac | 32 | signal(3, 100); |
fbc57595 | 33 | if (cyw43_arch_wifi_connect_timeout_ms(wifi_ssid, wifi_pass, |
9efef936 | 34 | CYW43_AUTH_WPA2_AES_PSK, 90000)) |
d234f6b3 | 35 | signal_error_by_blinking(); |
38d971ac | 36 | signal(2, 300); |
1427141a | 37 | |
c8c900a6 | 38 | queue_init(&queue, sizeof(uint32_t), 99); |
1427141a | 39 | |
d1521eda | 40 | begin_listening_for_button_press(button_pressed); |
1e0a316e | 41 | |
1427141a SW |
42 | u16_t seq = 0; |
43 | while (1) { | |
c8c900a6 SW |
44 | uint32_t t; |
45 | queue_remove_blocking(&queue, &t); | |
ff379463 SW |
46 | seq++; |
47 | for (int i = 0; i < resend_count; i++) { | |
c8c900a6 SW |
48 | uint32_t now = time_s(); |
49 | uint32_t ago = now - t; | |
50 | send_report(seq, ago); | |
ff379463 SW |
51 | signal(i == 0 ? 2 : 1, 100); |
52 | sleep_ms(resend_interval_ms); | |
53 | } | |
1427141a | 54 | } |
75649fe3 | 55 | } |