]> git.scottworley.com Git - tattlekey/blobdiff - client/tattlekey.c
client: Extract pending-send object as send_t
[tattlekey] / client / tattlekey.c
index cd1324145e220b097578b0b67e613ca973778bd8..78d1dcfd8925c576b362d6fa0d20e09f7686de54 100644 (file)
@@ -7,6 +7,12 @@
 #include "config.h"
 #include "net.h"
 
+typedef struct {
+  uint32_t timestamp;
+  u16_t seq;
+  u8_t send_count;
+} send_t;
+
 enum event_type { BUTTONPRESS, SEND };
 typedef struct {
   enum event_type type;
@@ -14,11 +20,7 @@ typedef struct {
     struct {
       uint32_t timestamp;
     } buttonpress;
-    struct {
-      uint32_t timestamp;
-      u16_t seq;
-      u8_t send_count;
-    } send;
+    send_t send;
   };
 } event_t;
 
@@ -51,21 +53,7 @@ static void button_pressed() {
   }
 }
 
-int main() {
-  stdio_init_all();
-  if (cyw43_arch_init_with_country(CYW43_COUNTRY_USA))
-    signal_error_by_blinking();
-  cyw43_arch_enable_sta_mode();
-  signal(3, 100);
-  if (cyw43_arch_wifi_connect_timeout_ms(config_wifi_ssid, config_wifi_pass,
-                                         CYW43_AUTH_WPA2_AES_PSK, 90000))
-    signal_error_by_blinking();
-  signal(2, 300);
-
-  queue_init(&queue, sizeof(event_t), 99);
-
-  begin_listening_for_button_press(button_pressed);
-
+void service_queue() {
   u16_t seq = 0;
   while (1) {
     event_t e;
@@ -95,3 +83,21 @@ int main() {
     }
   }
 }
+
+int main() {
+  stdio_init_all();
+  if (cyw43_arch_init_with_country(CYW43_COUNTRY_USA))
+    signal_error_by_blinking();
+  cyw43_arch_enable_sta_mode();
+  signal(3, 100);
+  if (cyw43_arch_wifi_connect_timeout_ms(config_wifi_ssid, config_wifi_pass,
+                                         CYW43_AUTH_WPA2_AES_PSK, 90000))
+    signal_error_by_blinking();
+  signal(2, 300);
+
+  queue_init(&queue, sizeof(event_t), 99);
+
+  begin_listening_for_button_press(button_pressed);
+
+  service_queue();
+}