Просмотр исходного кода

fix freeze when board not connected/not flashed

jblanked 8 месяцев назад
Родитель
Сommit
1c79361844
1 измененных файлов с 15 добавлено и 10 удалено
  1. 15 10
      app.c

+ 15 - 10
app.c

@@ -32,6 +32,8 @@ int32_t flip_world_main(void *p)
         return -1;
     }
 
+    save_char("app_version", VERSION);
+
     if (!flipper_http_send_command(fhttp, HTTP_CMD_PING))
     {
         FURI_LOG_E(TAG, "Failed to ping the device");
@@ -39,6 +41,8 @@ int32_t flip_world_main(void *p)
         return -1;
     }
 
+    furi_delay_ms(100);
+
     // Try to wait for pong response.
     uint32_t counter = 10;
     while (fhttp->state == INACTIVE && --counter > 0)
@@ -47,18 +51,19 @@ int32_t flip_world_main(void *p)
         furi_delay_ms(100);
     }
 
-    if (counter == 0)
+    // last response should be PONG
+    if (!fhttp->last_response || strcmp(fhttp->last_response, "[PONG]") != 0)
+    {
         easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
-
-    // save app version
-    // char app_version[16];
-    // snprintf(app_version, sizeof(app_version), "%f", (double)VERSION);
-    save_char("app_version", VERSION);
-
-    // for now use the catalog API until I implement caching on the server
-    if (update_is_ready(fhttp, true))
+        FURI_LOG_E(TAG, "Failed to receive PONG");
+    }
+    else
     {
-        easy_flipper_dialog("Update Status", "Complete.\nRestart your Flipper Zero.");
+        // for now use the catalog API until I implement caching on the server
+        if (update_is_ready(fhttp, true))
+        {
+            easy_flipper_dialog("Update Status", "Complete.\nRestart your Flipper Zero.");
+        }
     }
 
     flipper_http_free(fhttp);