app.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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);
  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. save_char("app_version", "0.2.1");
  45. // Run the view dispatcher
  46. view_dispatcher_run(app->view_dispatcher);
  47. // Free the resources used by the FlipWorld application
  48. flip_world_app_free(app);
  49. // Return 0 to indicate success
  50. return 0;
  51. }