app.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. // Try to wait for pong response.
  23. uint8_t counter = 10;
  24. while(fhttp.state == INACTIVE && --counter > 0) {
  25. FURI_LOG_D(TAG, "Waiting for PONG");
  26. furi_delay_ms(100);
  27. }
  28. if(counter == 0) {
  29. DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
  30. DialogMessage* message = dialog_message_alloc();
  31. dialog_message_set_header(
  32. message, "WIFI NOT RESPONDING", 64, 0, AlignCenter, AlignTop);
  33. dialog_message_set_text(
  34. message,
  35. "Ensure ESP32 is connected\nand latest FlipperHTTP\nfirmware is installed.",
  36. 0,
  37. 63,
  38. AlignLeft,
  39. AlignBottom);
  40. dialog_message_show(dialogs, message);
  41. dialog_message_free(message);
  42. furi_record_close(RECORD_DIALOGS);
  43. }
  44. }
  45. // Run the view dispatcher
  46. view_dispatcher_run(app_instance->view_dispatcher);
  47. // Free the resources used by the FlipLibrary application
  48. flip_library_app_free(app_instance);
  49. // Return 0 to indicate success
  50. return 0;
  51. }