app.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <flip_library.h>
  2. #include <alloc/flip_library_alloc.h>
  3. // Entry point for the FlipLibrary application
  4. int32_t flip_library_app(void *p)
  5. {
  6. // Suppress unused parameter warning
  7. UNUSED(p);
  8. // Initialize the FlipLibrary application
  9. app_instance = flip_library_app_alloc();
  10. if (!app_instance)
  11. {
  12. FURI_LOG_E(TAG, "Failed to allocate FlipLibraryApp");
  13. return -1;
  14. }
  15. if (!flipper_http_ping())
  16. {
  17. FURI_LOG_E(TAG, "Failed to ping the device");
  18. return -1;
  19. }
  20. if (app_instance->uart_text_input_buffer_ssid != NULL &&
  21. app_instance->uart_text_input_buffer_password != NULL)
  22. {
  23. // Try to wait for pong response.
  24. uint8_t counter = 10;
  25. while (fhttp.state == INACTIVE && --counter > 0)
  26. {
  27. FURI_LOG_D(TAG, "Waiting for PONG");
  28. furi_delay_ms(100);
  29. }
  30. if (counter == 0)
  31. {
  32. DialogsApp *dialogs = furi_record_open(RECORD_DIALOGS);
  33. DialogMessage *message = dialog_message_alloc();
  34. dialog_message_set_header(
  35. message, "[FlipperHTTP Error]", 64, 0, AlignCenter, AlignTop);
  36. dialog_message_set_text(
  37. message,
  38. "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.",
  39. 0,
  40. 63,
  41. AlignLeft,
  42. AlignBottom);
  43. dialog_message_show(dialogs, message);
  44. dialog_message_free(message);
  45. furi_record_close(RECORD_DIALOGS);
  46. }
  47. }
  48. // Run the view dispatcher
  49. view_dispatcher_run(app_instance->view_dispatcher);
  50. // Free the resources used by the FlipLibrary application
  51. flip_library_app_free(app_instance);
  52. // Return 0 to indicate success
  53. return 0;
  54. }