app.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <flip_weather.h>
  2. #include <alloc/flip_weather_alloc.h>
  3. // Entry point for the FlipWeather application
  4. int32_t flip_weather_app(void *p)
  5. {
  6. // Suppress unused parameter warning
  7. UNUSED(p);
  8. // Initialize the FlipWeather application
  9. app_instance = flip_weather_app_alloc();
  10. if (!app_instance)
  11. {
  12. FURI_LOG_E(TAG, "Failed to allocate FlipWeatherApp");
  13. return -1;
  14. }
  15. if (!flipper_http_ping())
  16. {
  17. FURI_LOG_E(TAG, "Failed to ping the device");
  18. return -1;
  19. }
  20. // Thanks to Derek Jamison for the following edits
  21. if (app_instance->uart_text_input_buffer_ssid != NULL &&
  22. app_instance->uart_text_input_buffer_password != NULL)
  23. {
  24. // Try to wait for pong response.
  25. uint8_t counter = 10;
  26. while (fhttp.state == INACTIVE && --counter > 0)
  27. {
  28. FURI_LOG_D(TAG, "Waiting for PONG");
  29. furi_delay_ms(100);
  30. }
  31. if (counter == 0)
  32. {
  33. DialogsApp *dialogs = furi_record_open(RECORD_DIALOGS);
  34. DialogMessage *message = dialog_message_alloc();
  35. dialog_message_set_header(
  36. message, "[FlipperHTTP Error]", 64, 0, AlignCenter, AlignTop);
  37. dialog_message_set_text(
  38. message,
  39. "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.",
  40. 0,
  41. 63,
  42. AlignLeft,
  43. AlignBottom);
  44. dialog_message_show(dialogs, message);
  45. dialog_message_free(message);
  46. furi_record_close(RECORD_DIALOGS);
  47. }
  48. }
  49. // Run the view dispatcher
  50. view_dispatcher_run(app_instance->view_dispatcher);
  51. // Free the resources used by the FlipWeather application
  52. flip_weather_app_free(app_instance);
  53. // Return 0 to indicate success
  54. return 0;
  55. }