app.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <flip_downloader.h>
  2. #include <alloc/flip_store_alloc.h>
  3. // Entry point for the Hello World application
  4. int32_t main_flip_downloader(void *p)
  5. {
  6. // Suppress unused parameter warning
  7. UNUSED(p);
  8. // Initialize the Hello World application
  9. FlipStoreApp *app = flip_store_app_alloc();
  10. if (!app)
  11. {
  12. FURI_LOG_E(TAG, "Failed to allocate FlipStoreApp");
  13. return -1;
  14. }
  15. // check if board is connected (Derek Jamison)
  16. FlipperHTTP *fhttp = flipper_http_alloc();
  17. if (!fhttp)
  18. {
  19. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  20. return -1;
  21. }
  22. if (!flipper_http_send_command(fhttp, HTTP_CMD_PING))
  23. {
  24. FURI_LOG_E(TAG, "Failed to ping the device");
  25. flipper_http_free(fhttp);
  26. return -1;
  27. }
  28. // Try to wait for pong response.
  29. uint32_t counter = 10;
  30. while (fhttp->state == INACTIVE && --counter > 0)
  31. {
  32. FURI_LOG_D(TAG, "Waiting for PONG");
  33. furi_delay_ms(100);
  34. }
  35. flipper_http_free(fhttp);
  36. if (counter == 0)
  37. {
  38. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  39. }
  40. // Run the view dispatcher
  41. view_dispatcher_run(app->view_dispatcher);
  42. // Free the resources used by the Hello World application
  43. flip_store_app_free(app);
  44. // Return 0 to indicate success
  45. return 0;
  46. }