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. /**
  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. FlipperHTTP *fhttp = flipper_http_alloc();
  23. if (!fhttp)
  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(fhttp, HTTP_CMD_PING))
  29. {
  30. FURI_LOG_E(TAG, "Failed to ping the device");
  31. flipper_http_free(fhttp);
  32. return -1;
  33. }
  34. // Try to wait for pong response.
  35. uint32_t counter = 10;
  36. while (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();
  60. }
  61. // if (update_is_ready(fhttp, true))
  62. // {
  63. // easy_flipper_dialog("Update Status", "Complete.\nRestart your Flipper Zero.");
  64. // }
  65. }
  66. flipper_http_free(fhttp);
  67. // Run the view dispatcher
  68. view_dispatcher_run(app_instance->view_dispatcher);
  69. // Free the resources used by the Hello World application
  70. flip_social_app_free(app_instance);
  71. // Return 0 to indicate success
  72. return 0;
  73. }