app.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. // Suppress unused parameter warning
  7. UNUSED(p);
  8. // Initialize the FlipWorld application
  9. FlipWorldApp *app = flip_world_app_alloc();
  10. if (!app)
  11. {
  12. FURI_LOG_E(TAG, "Failed to allocate FlipWorldApp");
  13. return -1;
  14. }
  15. // initialize the VGM
  16. furi_hal_gpio_init_simple(&gpio_ext_pc1, GpioModeOutputPushPull);
  17. furi_hal_gpio_write(&gpio_ext_pc1, false); // pull pin 15 low
  18. // check if board is connected (Derek Jamison)
  19. FlipperHTTP *fhttp = flipper_http_alloc();
  20. if (!fhttp)
  21. {
  22. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  23. return -1;
  24. }
  25. if (!flipper_http_ping(fhttp))
  26. {
  27. FURI_LOG_E(TAG, "Failed to ping the device");
  28. flipper_http_free(fhttp);
  29. return -1;
  30. }
  31. // Try to wait for pong response.
  32. uint32_t counter = 10;
  33. while (fhttp->state == INACTIVE && --counter > 0)
  34. {
  35. FURI_LOG_D(TAG, "Waiting for PONG");
  36. furi_delay_ms(100); // this causes a BusFault
  37. }
  38. flipper_http_free(fhttp);
  39. if (counter == 0)
  40. {
  41. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  42. }
  43. // save app version
  44. char app_version[16];
  45. snprintf(app_version, sizeof(app_version), "%f", (double)VERSION);
  46. save_char("app_version", app_version);
  47. // Run the view dispatcher
  48. view_dispatcher_run(app->view_dispatcher);
  49. // Free the resources used by the FlipWorld application
  50. flip_world_app_free(app);
  51. // Return 0 to indicate success
  52. return 0;
  53. }