app.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. {
  6. UNUSED(p);
  7. // Initialize the FlipWiFi application
  8. FlipWiFiApp *app = flip_wifi_app_alloc();
  9. if (!app)
  10. {
  11. FURI_LOG_E(TAG, "Failed to allocate FlipWiFiApp");
  12. return -1;
  13. }
  14. // check if board is connected (Derek Jamison)
  15. // initialize the http
  16. if (flipper_http_init(flipper_http_rx_callback, app))
  17. {
  18. if (!flipper_http_ping())
  19. {
  20. FURI_LOG_E(TAG, "Failed to ping the device");
  21. return -1;
  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. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  32. flipper_http_deinit();
  33. }
  34. else
  35. {
  36. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  37. }
  38. // Run the view dispatcher
  39. view_dispatcher_run(app->view_dispatcher);
  40. // Free the resources used by the FlipWiFi application
  41. flip_wifi_app_free(app);
  42. // Return 0 to indicate success
  43. return 0;
  44. }