app.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. FlipperHTTP *fhttp = flipper_http_alloc();
  16. if (!fhttp)
  17. {
  18. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  19. return -1;
  20. }
  21. if (!flipper_http_send_command(fhttp, HTTP_CMD_PING))
  22. {
  23. FURI_LOG_E(TAG, "Failed to ping the device");
  24. flipper_http_free(fhttp);
  25. return -1;
  26. }
  27. // Try to wait for pong response.
  28. uint32_t counter = 10;
  29. while (fhttp->state == INACTIVE && --counter > 0)
  30. {
  31. FURI_LOG_D(TAG, "Waiting for PONG");
  32. furi_delay_ms(100); // this causes a BusFault
  33. }
  34. flipper_http_free(fhttp);
  35. if (counter == 0)
  36. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  37. // Run the view dispatcher
  38. view_dispatcher_run(app->view_dispatcher);
  39. // Free the resources used by the FlipWiFi application
  40. flip_wifi_app_free(app);
  41. // Return 0 to indicate success
  42. return 0;
  43. }