]> git.scottworley.com Git - tattlekey/blame - client/tattlekey.c
client: Send each report multiple times
[tattlekey] / client / tattlekey.c
CommitLineData
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 10queue_t queue;
d1521eda
SW
11
12static void button_pressed() {
1427141a 13 /* This runs in interrupt context; don't linger. */
2f7a1e89
SW
14 static uint64_t last_button_press_time = 0;
15 uint64_t now = time_us_64();
16 uint64_t time_since_last_press = now - last_button_press_time;
17 if (time_since_last_press > minimum_microseconds_between_button_presses) {
18 last_button_press_time = now;
19 char zero = '\0';
20 /* We don't check for failure (full queue) here because there's not much to
21 * be done about it. */
22 queue_try_add(&queue, &zero);
23 }
d1521eda
SW
24}
25
75649fe3
SW
26int main() {
27 stdio_init_all();
d234f6b3 28 if (cyw43_arch_init_with_country(CYW43_COUNTRY_USA))
75649fe3 29 signal_error_by_blinking();
d234f6b3 30 cyw43_arch_enable_sta_mode();
38d971ac 31 signal(3, 100);
fbc57595 32 if (cyw43_arch_wifi_connect_timeout_ms(wifi_ssid, wifi_pass,
9efef936 33 CYW43_AUTH_WPA2_AES_PSK, 90000))
d234f6b3 34 signal_error_by_blinking();
38d971ac 35 signal(2, 300);
1427141a
SW
36
37 queue_init(&queue, 1, 99);
38
d1521eda 39 begin_listening_for_button_press(button_pressed);
1e0a316e 40
1427141a
SW
41 u16_t seq = 0;
42 while (1) {
43 char _;
44 queue_remove_blocking(&queue, &_);
ff379463
SW
45 seq++;
46 for (int i = 0; i < resend_count; i++) {
47 send_report(seq, i);
48 signal(i == 0 ? 2 : 1, 100);
49 sleep_ms(resend_interval_ms);
50 }
1427141a 51 }
75649fe3 52}