app.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. if (!flipper_http_send_command(fhttp, HTTP_CMD_PING))
  30. {
  31. FURI_LOG_E(TAG, "Failed to ping the device");
  32. flipper_http_free(fhttp);
  33. return -1;
  34. }
  35. // Try to wait for pong response.
  36. uint32_t counter = 10;
  37. while (fhttp->state == INACTIVE && --counter > 0)
  38. {
  39. FURI_LOG_D(TAG, "Waiting for PONG");
  40. furi_delay_ms(100);
  41. }
  42. if (counter == 0)
  43. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  44. // save app version
  45. // char app_version[16];
  46. // snprintf(app_version, sizeof(app_version), "%f", (double)VERSION);
  47. save_char("app_version", VERSION);
  48. // for now use the catalog API until I implement caching on the server
  49. if (update_is_ready(fhttp, true))
  50. {
  51. easy_flipper_dialog("Update Status", "Complete.\nRestart your Flipper Zero.");
  52. }
  53. flipper_http_free(fhttp);
  54. // Run the view dispatcher
  55. view_dispatcher_run(app->view_dispatcher);
  56. // Free the resources used by the FlipWorld application
  57. flip_world_app_free(app);
  58. // Return 0 to indicate success
  59. return 0;
  60. }