app.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // app.c
  2. #include <flip_social.h> // Include the FlipSocialApp structure
  3. #include <alloc/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. 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. flip_social_home_notification();
  60. }
  61. }
  62. flipper_http_free(fhttp);
  63. // Run the view dispatcher
  64. view_dispatcher_run(app_instance->view_dispatcher);
  65. // Free the resources used by the Hello World application
  66. flip_social_app_free(app_instance);
  67. // Return 0 to indicate success
  68. return 0;
  69. }