app.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <flip_social.h>
  2. #include <alloc/alloc.h>
  3. #include <flip_storage/flip_social_storage.h>
  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 = alloc_flip_social_app();
  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. if (!alloc_flipper_http())
  23. {
  24. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  25. return -1;
  26. }
  27. if (!flipper_http_send_command(app_instance->fhttp, HTTP_CMD_PING))
  28. {
  29. FURI_LOG_E(TAG, "Failed to ping the device");
  30. free_flipper_http();
  31. return -1;
  32. }
  33. // Try to wait for pong response.
  34. uint32_t counter = 10;
  35. while (app_instance->fhttp->state == INACTIVE && --counter > 0)
  36. {
  37. FURI_LOG_D(TAG, "Waiting for PONG");
  38. furi_delay_ms(100);
  39. }
  40. // save app version
  41. save_char("app_version", VERSION);
  42. if (counter == 0)
  43. {
  44. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  45. }
  46. else
  47. {
  48. char is_connected[5];
  49. char is_logged_in[5];
  50. char is_notifications[5];
  51. load_char("is_connected", is_connected, 5);
  52. load_char("is_logged_in", is_logged_in, 5);
  53. load_char("user_notifications", is_notifications, 5);
  54. if (strcmp(is_connected, "true") == 0 &&
  55. strcmp(is_notifications, "on") == 0 &&
  56. strcmp(is_logged_in, "true") == 0)
  57. {
  58. callback_home_notification(app_instance->fhttp);
  59. }
  60. // if (update_is_ready(app_instance->fhttp, true))
  61. // {
  62. // easy_flipper_dialog("Update Status", "Complete.\nRestart your Flipper Zero.");
  63. // }
  64. }
  65. free_flipper_http();
  66. // Run the view dispatcher
  67. view_dispatcher_run(app_instance->view_dispatcher);
  68. // Free the resources used by the Hello World application
  69. free_flip_social_app(app_instance);
  70. // Return 0 to indicate success
  71. return 0;
  72. }