app.c 2.2 KB

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