app.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include <flip_social.h>
  2. #include <alloc/alloc.h>
  3. #include <flip_storage/flip_social_storage.h>
  4. #include <update/update.h>
  5. /**
  6. * @brief Entry point for the Hello World application.
  7. * @details Initializes the app, runs the view dispatcher, and cleans up upon exit.
  8. * @param p Input parameter - unused
  9. * @return 0 to indicate success, -1 on failure
  10. */
  11. int32_t main_flip_social(void *p)
  12. {
  13. UNUSED(p);
  14. // Initialize the Hello World application
  15. app_instance = alloc_flip_social_app();
  16. if (!app_instance)
  17. {
  18. // Allocation failed
  19. FURI_LOG_E(TAG, "Failed to allocate FlipSocialApp");
  20. return -1; // Indicate failure
  21. }
  22. // check if board is connected (Derek Jamison)
  23. if (!alloc_flipper_http())
  24. {
  25. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  26. return -1;
  27. }
  28. if (!flipper_http_send_command(app_instance->fhttp, HTTP_CMD_PING))
  29. {
  30. FURI_LOG_E(TAG, "Failed to ping the device");
  31. free_flipper_http();
  32. return -1;
  33. }
  34. // Try to wait for pong response.
  35. uint32_t counter = 10;
  36. while (app_instance->fhttp->state == INACTIVE && --counter > 0)
  37. {
  38. FURI_LOG_D(TAG, "Waiting for PONG");
  39. furi_delay_ms(100);
  40. }
  41. // save app version
  42. save_char("app_version", VERSION);
  43. if (counter == 0)
  44. {
  45. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  46. }
  47. else
  48. {
  49. char is_connected[5];
  50. char is_logged_in[5];
  51. char is_notifications[5];
  52. load_char("is_connected", is_connected, 5);
  53. load_char("is_logged_in", is_logged_in, 5);
  54. load_char("user_notifications", is_notifications, 5);
  55. if (strcmp(is_connected, "true") == 0 &&
  56. strcmp(is_notifications, "on") == 0 &&
  57. strcmp(is_logged_in, "true") == 0)
  58. {
  59. callback_home_notification(app_instance->fhttp);
  60. }
  61. if (update_is_ready(app_instance->fhttp, true))
  62. {
  63. easy_flipper_dialog("Update Status", "Complete.\nRestart your Flipper Zero.");
  64. }
  65. }
  66. free_flipper_http();
  67. // Run the view dispatcher
  68. view_dispatcher_run(app_instance->view_dispatcher);
  69. // Free the resources used by the Hello World application
  70. free_flip_social_app(app_instance);
  71. // Return 0 to indicate success
  72. return 0;
  73. }