app.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. FURI_LOG_E(TAG, "Counter: %d", counter);
  29. if(counter == 0) {
  30. DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
  31. DialogMessage* message = dialog_message_alloc();
  32. dialog_message_set_header(
  33. message, "WIFI NOT RESPONDING", 64, 0, AlignCenter, AlignTop);
  34. dialog_message_set_text(
  35. message,
  36. "Ensure ESP32 is connected\nand latest FlipperHTTP\nfirmware is installed.",
  37. 0,
  38. 63,
  39. AlignLeft,
  40. AlignBottom);
  41. dialog_message_show(dialogs, message);
  42. dialog_message_free(message);
  43. furi_record_close(RECORD_DIALOGS);
  44. }
  45. // Switch to application wifi settings
  46. if(!flipper_http_save_wifi(
  47. app_instance->uart_text_input_buffer_ssid,
  48. app_instance->uart_text_input_buffer_password)) {
  49. FURI_LOG_E(TAG, "Failed to save wifi settings");
  50. }
  51. }
  52. // Run the view dispatcher
  53. view_dispatcher_run(app_instance->view_dispatcher);
  54. // Free the resources used by the FlipLibrary application
  55. flip_library_app_free(app_instance);
  56. // Return 0 to indicate success
  57. return 0;
  58. }