app.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <flip_wifi.h>
  2. #include <alloc/flip_wifi_alloc.h>
  3. #include <update/update.h>
  4. #include <flip_storage/flip_wifi_storage.h>
  5. // Entry point for the FlipWiFi application
  6. int32_t flip_wifi_main(void *p)
  7. {
  8. UNUSED(p);
  9. // Initialize the FlipWiFi application
  10. FlipWiFiApp *app = flip_wifi_app_alloc();
  11. if (!app)
  12. {
  13. FURI_LOG_E(TAG, "Failed to allocate FlipWiFiApp");
  14. return -1;
  15. }
  16. save_char("app_version", VERSION);
  17. // check if board is connected (Derek Jamison)
  18. FlipperHTTP *fhttp = flipper_http_alloc();
  19. if (!fhttp)
  20. {
  21. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  22. return -1;
  23. }
  24. if (!flipper_http_send_command(fhttp, HTTP_CMD_PING))
  25. {
  26. FURI_LOG_E(TAG, "Failed to ping the device");
  27. flipper_http_free(fhttp);
  28. return -1;
  29. }
  30. furi_delay_ms(100);
  31. // Try to wait for pong response.
  32. uint32_t counter = 10;
  33. while (fhttp->state == INACTIVE && --counter > 0)
  34. {
  35. FURI_LOG_D(TAG, "Waiting for PONG");
  36. furi_delay_ms(100);
  37. }
  38. // last response should be PONG
  39. if (!fhttp->last_response || strcmp(fhttp->last_response, "[PONG]") != 0)
  40. {
  41. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  42. FURI_LOG_E(TAG, "Failed to receive PONG");
  43. }
  44. else
  45. {
  46. // for now use the catalog API until I implement caching on the server
  47. if (update_is_ready(fhttp, true))
  48. {
  49. easy_flipper_dialog("Update Status", "Complete.\nRestart your Flipper Zero.");
  50. }
  51. }
  52. flipper_http_free(fhttp);
  53. // Run the view dispatcher
  54. view_dispatcher_run(app->view_dispatcher);
  55. // Free the resources used by the FlipWiFi application
  56. flip_wifi_app_free(app);
  57. // Return 0 to indicate success
  58. return 0;
  59. }