app.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // Suppress unused parameter warning
  6. UNUSED(p);
  7. // Initialize the FlipWeather application
  8. app_instance = flip_weather_app_alloc();
  9. if(!app_instance) {
  10. FURI_LOG_E(TAG, "Failed to allocate FlipWeatherApp");
  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 edits
  18. if(app_instance->uart_text_input_buffer_ssid != NULL &&
  19. app_instance->uart_text_input_buffer_password != NULL) {
  20. // Try to wait for pong response.
  21. uint8_t counter = 10;
  22. while(fhttp.state == INACTIVE && --counter > 0) {
  23. FURI_LOG_D(TAG, "Waiting for PONG");
  24. furi_delay_ms(100);
  25. }
  26. if(counter == 0) {
  27. DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
  28. DialogMessage* message = dialog_message_alloc();
  29. dialog_message_set_header(
  30. message, "[FlipperHTTP Error]", 64, 0, AlignCenter, AlignTop);
  31. dialog_message_set_text(
  32. message,
  33. "Ensure your WiFi Developer\nBoard or Pico W is connected\nand the latest FlipperHTTP\nfirmware is installed.",
  34. 0,
  35. 63,
  36. AlignLeft,
  37. AlignBottom);
  38. dialog_message_show(dialogs, message);
  39. dialog_message_free(message);
  40. furi_record_close(RECORD_DIALOGS);
  41. }
  42. }
  43. // Run the view dispatcher
  44. view_dispatcher_run(app_instance->view_dispatcher);
  45. // Free the resources used by the FlipWeather application
  46. flip_weather_app_free(app_instance);
  47. // Return 0 to indicate success
  48. return 0;
  49. }