app.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <alloc/alloc.h>
  2. #include <flip_storage/storage.h>
  3. #include <update/update.h>
  4. // Entry point for the FlipWorld application
  5. int32_t flip_world_main(void *p)
  6. {
  7. // check memory
  8. if (!is_enough_heap(sizeof(FlipWorldApp) + sizeof(FlipperHTTP), true))
  9. {
  10. easy_flipper_dialog("Memory Error", "Not enough heap memory.\nPlease restart your Flipper Zero.");
  11. return 0; // return success so the user can see the error
  12. }
  13. // Suppress unused parameter warning
  14. UNUSED(p);
  15. // Initialize the FlipWorld application
  16. FlipWorldApp *app = flip_world_app_alloc();
  17. if (!app)
  18. return -1;
  19. // initialize the VGM
  20. furi_hal_gpio_init_simple(&gpio_ext_pc1, GpioModeOutputPushPull);
  21. furi_hal_gpio_write(&gpio_ext_pc1, false); // pull pin 15 low
  22. // check if board is connected (Derek Jamison)
  23. FlipperHTTP *fhttp = flipper_http_alloc();
  24. if (!fhttp)
  25. {
  26. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  27. return -1;
  28. }
  29. save_char("app_version", VERSION);
  30. if (!flipper_http_send_command(fhttp, HTTP_CMD_PING))
  31. {
  32. FURI_LOG_E(TAG, "Failed to ping the device");
  33. flipper_http_free(fhttp);
  34. return -1;
  35. }
  36. furi_delay_ms(100);
  37. // Try to wait for pong response.
  38. uint32_t counter = 10;
  39. while (fhttp->state == INACTIVE && --counter > 0)
  40. {
  41. FURI_LOG_D(TAG, "Waiting for PONG");
  42. furi_delay_ms(100);
  43. }
  44. // last response should be PONG
  45. if (!fhttp->last_response || strcmp(fhttp->last_response, "[PONG]") != 0)
  46. {
  47. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  48. FURI_LOG_E(TAG, "Failed to receive PONG");
  49. }
  50. else
  51. {
  52. // for now use the catalog API until I implement caching on the server
  53. if (update_is_ready(fhttp, true))
  54. {
  55. easy_flipper_dialog("Update Status", "Complete.\nRestart your Flipper Zero.");
  56. }
  57. }
  58. flipper_http_free(fhttp);
  59. // Run the view dispatcher
  60. view_dispatcher_run(app->view_dispatcher);
  61. // Free the resources used by the FlipWorld application
  62. flip_world_app_free(app);
  63. // Return 0 to indicate success
  64. return 0;
  65. }