app.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // app.c
  2. #include <flip_social.h> // Include the FlipSocialApp structure
  3. #include <alloc/flip_social_alloc.h> // Include the allocation functions
  4. /**
  5. * @brief Entry point for the Hello World application.
  6. * @details Initializes the app, runs the view dispatcher, and cleans up upon exit.
  7. * @param p Input parameter - unused
  8. * @return 0 to indicate success, -1 on failure
  9. */
  10. int32_t main_flip_social(void *p)
  11. {
  12. UNUSED(p);
  13. // Initialize the Hello World application
  14. app_instance = flip_social_app_alloc();
  15. if (!app_instance)
  16. {
  17. // Allocation failed
  18. FURI_LOG_E(TAG, "Failed to allocate FlipSocialApp");
  19. return -1; // Indicate failure
  20. }
  21. // check if board is connected (Derek Jamison)
  22. // initialize the http
  23. if (flipper_http_init(flipper_http_rx_callback, app_instance))
  24. {
  25. fhttp.state = INACTIVE; // set inactive for the ping
  26. if (!flipper_http_ping())
  27. {
  28. FURI_LOG_E(TAG, "Failed to ping the device");
  29. return -1;
  30. }
  31. // Try to wait for pong response.
  32. uint8_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. if (counter == 0)
  39. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  40. flipper_http_deinit();
  41. }
  42. else
  43. {
  44. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  45. }
  46. // Run the view dispatcher
  47. view_dispatcher_run(app_instance->view_dispatcher);
  48. // Free the resources used by the Hello World application
  49. flip_social_app_free(app_instance);
  50. // Return 0 to indicate success
  51. return 0;
  52. }