app.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // check if board is connected (Derek Jamison)
  17. FlipperHTTP *fhttp = flipper_http_alloc();
  18. if (!fhttp)
  19. {
  20. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  21. return -1;
  22. }
  23. if (!flipper_http_send_command(fhttp, HTTP_CMD_PING))
  24. {
  25. FURI_LOG_E(TAG, "Failed to ping the device");
  26. flipper_http_free(fhttp);
  27. return -1;
  28. }
  29. // Try to wait for pong response.
  30. uint32_t counter = 10;
  31. while (fhttp->state == INACTIVE && --counter > 0)
  32. {
  33. FURI_LOG_D(TAG, "Waiting for PONG");
  34. furi_delay_ms(100); // this causes a BusFault
  35. }
  36. if (counter == 0)
  37. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  38. save_char("app_version", VERSION);
  39. // for now use the catalog API until I implement caching on the server
  40. if (update_is_ready(fhttp, true))
  41. {
  42. easy_flipper_dialog("Update Status", "Complete.\nRestart your Flipper Zero.");
  43. }
  44. flipper_http_free(fhttp);
  45. // Run the view dispatcher
  46. view_dispatcher_run(app->view_dispatcher);
  47. // Free the resources used by the FlipWiFi application
  48. flip_wifi_app_free(app);
  49. // Return 0 to indicate success
  50. return 0;
  51. }