app.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <flip_wifi.h>
  2. #include <alloc/flip_wifi_alloc.h>
  3. // Entry point for the FlipWiFi application
  4. int32_t flip_wifi_main(void* p) {
  5. // Suppress unused parameter warning
  6. UNUSED(p);
  7. // Initialize the FlipWiFi application
  8. app_instance = flip_wifi_app_alloc();
  9. if(!app_instance) {
  10. FURI_LOG_E(TAG, "Failed to allocate FlipWiFiApp");
  11. return -1;
  12. }
  13. if(!flipper_http_ping()) {
  14. FURI_LOG_E(TAG, "Failed to ping the device");
  15. return -1;
  16. }
  17. // Thanks to Derek Jamison for the following code snippet:
  18. if (app_instance->uart_text_input_buffer_add_ssid != NULL &&
  19. app_instance->uart_text_input_buffer_add_password != NULL)
  20. {
  21. // Try to wait for pong response.
  22. uint8_t counter = 10;
  23. while (fhttp.state == INACTIVE && --counter > 0)
  24. {
  25. FURI_LOG_D(TAG, "Waiting for PONG");
  26. furi_delay_ms(100);
  27. }
  28. if (counter == 0)
  29. {
  30. DialogsApp *dialogs = furi_record_open(RECORD_DIALOGS);
  31. DialogMessage *message = dialog_message_alloc();
  32. dialog_message_set_header(
  33. message, "[FlipperHTTP Error]", 64, 0, AlignCenter, AlignTop);
  34. dialog_message_set_text(
  35. message,
  36. "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the 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. }
  46. // Run the view dispatcher
  47. view_dispatcher_run(app_instance->view_dispatcher);
  48. // Free the resources used by the FlipWiFi application
  49. flip_wifi_app_free(app_instance);
  50. // Return 0 to indicate success
  51. return 0;
  52. }