app.c 1.7 KB

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