app.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. return -1; // Indicate failure
  19. }
  20. if (!flipper_http_ping())
  21. {
  22. FURI_LOG_E(TAG, "Failed to ping the device");
  23. return -1;
  24. }
  25. // Thanks to Derek Jamison for the following edits
  26. if (app_instance->wifi_ssid_logged_out != NULL &&
  27. app_instance->wifi_password_logged_out != NULL)
  28. {
  29. // Try to wait for pong response.
  30. uint8_t counter = 10;
  31. while (fhttp.state == INACTIVE && --counter > 0)
  32. {
  33. FURI_LOG_D(TAG, "Waiting for PONG");
  34. furi_delay_ms(100);
  35. }
  36. if (counter == 0)
  37. {
  38. DialogsApp *dialogs = furi_record_open(RECORD_DIALOGS);
  39. DialogMessage *message = dialog_message_alloc();
  40. dialog_message_set_header(
  41. message, "[FlipperHTTP Error]", 64, 0, AlignCenter, AlignTop);
  42. dialog_message_set_text(
  43. message,
  44. "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.",
  45. 0,
  46. 63,
  47. AlignLeft,
  48. AlignBottom);
  49. dialog_message_show(dialogs, message);
  50. dialog_message_free(message);
  51. furi_record_close(RECORD_DIALOGS);
  52. }
  53. }
  54. // Run the view dispatcher
  55. view_dispatcher_run(app_instance->view_dispatcher);
  56. // Free the resources used by the Hello World application
  57. flip_social_app_free(app_instance);
  58. // Return 0 to indicate success
  59. return 0;
  60. }