app.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. if (!flipper_http_ping())
  26. {
  27. FURI_LOG_E(TAG, "Failed to ping the device");
  28. return -1;
  29. }
  30. // Try to wait for pong response.
  31. uint8_t counter = 10;
  32. while (fhttp.state == INACTIVE && --counter > 0)
  33. {
  34. FURI_LOG_D(TAG, "Waiting for PONG");
  35. furi_delay_ms(100);
  36. }
  37. if (counter == 0)
  38. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  39. flipper_http_deinit();
  40. }
  41. else
  42. {
  43. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  44. }
  45. // Run the view dispatcher
  46. view_dispatcher_run(app_instance->view_dispatcher);
  47. // Free the resources used by the Hello World application
  48. flip_social_app_free(app_instance);
  49. // Return 0 to indicate success
  50. return 0;
  51. }