app.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. uint8_t counter = 10;
  23. // initialize the http
  24. if (flipper_http_init(flipper_http_rx_callback, app_instance))
  25. {
  26. fhttp.state = INACTIVE; // set inactive for the ping
  27. if (!flipper_http_ping())
  28. {
  29. FURI_LOG_E(TAG, "Failed to ping the device");
  30. return -1;
  31. }
  32. // Try to wait for pong response.
  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. {
  40. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  41. }
  42. else
  43. {
  44. save_char("is_connected", "true");
  45. }
  46. flipper_http_deinit();
  47. }
  48. else
  49. {
  50. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  51. }
  52. // if counter is not 0, check notifications
  53. if (counter != 0)
  54. {
  55. char is_connected[5];
  56. char is_logged_in[5];
  57. char is_notifications[5];
  58. load_char("is_connected", is_connected, 5);
  59. load_char("is_logged_in", is_logged_in, 5);
  60. load_char("user_notifications", is_notifications, 5);
  61. if (strcmp(is_connected, "true") == 0 &&
  62. strcmp(is_notifications, "on") == 0 &&
  63. strcmp(is_logged_in, "true") == 0)
  64. {
  65. flip_social_home_notification();
  66. }
  67. }
  68. // Run the view dispatcher
  69. view_dispatcher_run(app_instance->view_dispatcher);
  70. // Free the resources used by the Hello World application
  71. flip_social_app_free(app_instance);
  72. // Return 0 to indicate success
  73. return 0;
  74. }