app.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <web_crawler.h>
  2. #include <alloc/web_crawler_alloc.h>
  3. /**
  4. * @brief Entry point for the WebCrawler application.
  5. * @param p Input parameter - unused
  6. * @return 0 to indicate success, -1 on failure
  7. */
  8. int32_t web_crawler_app(void *p)
  9. {
  10. UNUSED(p);
  11. WebCrawlerApp *app = web_crawler_app_alloc();
  12. if (!app)
  13. {
  14. FURI_LOG_E(TAG, "Failed to allocate WebCrawlerApp");
  15. return -1;
  16. }
  17. // check if board is connected (Derek Jamison)
  18. FlipperHTTP *fhttp = flipper_http_alloc();
  19. if (!fhttp)
  20. {
  21. easy_flipper_dialog("FlipperHTTP Error", "The UART is likely busy.\nEnsure you have the correct\nflash for your board then\nrestart your Flipper Zero.");
  22. return -1;
  23. }
  24. if (!flipper_http_ping(fhttp))
  25. {
  26. FURI_LOG_E(TAG, "Failed to ping the device");
  27. flipper_http_free(fhttp);
  28. return -1;
  29. }
  30. // Try to wait for pong response.
  31. uint32_t counter = 10;
  32. while (fhttp->state == INACTIVE && --counter > 0)
  33. {
  34. FURI_LOG_D(TAG, "Waiting for PONG");
  35. furi_delay_ms(100); // this causes a BusFault
  36. }
  37. flipper_http_free(fhttp);
  38. if (counter == 0)
  39. {
  40. easy_flipper_dialog("FlipperHTTP Error", "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.");
  41. }
  42. // Run the application
  43. view_dispatcher_run(app->view_dispatcher);
  44. // Free resources after the application loop ends
  45. web_crawler_app_free(app);
  46. return 0;
  47. }