app.c 1.8 KB

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