]> git.scottworley.com Git - tattlekey/blob - client/tattlekey.c
30f92a4d4e3cb804a86af133a4c058a3908acfd7
[tattlekey] / client / tattlekey.c
1 #include "pico/cyw43_arch.h"
2 #include "pico/stdlib.h"
3
4 #include "blink.h"
5 #include "button.h"
6 #include "config.h"
7 #include "net.h"
8
9 static u16_t seq = 0;
10
11 static void button_pressed() {
12 /* TODO: This is interrupt context. We need to get out of interrupt context
13 * quickly; we should not be doing significant work here, & definitely
14 * shouldn't be sleeping here. We signal errors with blinking the LED, which
15 * involves sleeping, so this all has to move. */
16 send_report(seq++, 0);
17 signal(4, 200);
18 }
19
20 static void wait_forever() {
21 /* pico-examples/gpio/hello_gpio_irq/hello_gpio_irq.c implements wait-forever
22 * as "while (1);", but
23 * https://www.raspberrypi.com/documentation/pico-sdk/high_level.html#gaf469c6d691230e9d1008
24 * says sleeping uses less power, so we sleep. */
25 while (1) {
26 /* https://www.raspberrypi.com/documentation/pico-sdk/hardware.html#rpip7ce2cdc1662dce59296b
27 * says the maximum sleep is 2^32 - 1 microseconds (~71.58 minutes), so we
28 * sleep in chunks. */
29 sleep_ms(1 << 31); /* 35.79 minutes */
30 }
31 }
32
33 int main() {
34 stdio_init_all();
35 if (cyw43_arch_init_with_country(CYW43_COUNTRY_USA))
36 signal_error_by_blinking();
37 signal(1, 200);
38 cyw43_arch_enable_sta_mode();
39 signal(2, 200);
40 if (cyw43_arch_wifi_connect_timeout_ms(wifi_ssid, wifi_pass,
41 CYW43_AUTH_WPA2_AES_PSK, 10000))
42 signal_error_by_blinking();
43 signal(3, 200);
44 begin_listening_for_button_press(button_pressed);
45
46 wait_forever();
47 }