Преглед изворни кода

Add additional error handling

jblanked пре 1 година
родитељ
комит
61a18a2e08

+ 6 - 0
alloc/flip_weather_alloc.c

@@ -107,6 +107,12 @@ FlipWeatherApp *flip_weather_app_alloc()
         }
     }
 
+    // Popup
+    if (!easy_flipper_set_popup(&app->popup_error, FlipWeatherViewPopupError, "[ERROR]", 0, 0, "Wifi Dev Board disconnected.\nPlease connect to the board.\nIf your board is connected,\nmake sure you have flashed\nyour WiFi Devboard with the\nlatest FlipperHTTP flash.", 0, 7, flip_weather_popup_callback, callback_to_submenu, &app->view_dispatcher, app))
+    {
+        return NULL;
+    }
+
     // Switch to the main view
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipWeatherViewSubmenu);
 

+ 22 - 4
callback/flip_weather_callback.c

@@ -4,6 +4,17 @@ bool weather_request_success = false;
 bool sent_weather_request = false;
 bool got_weather_data = false;
 
+void flip_weather_popup_callback(void *context)
+{
+    FlipWeatherApp *app = (FlipWeatherApp *)context;
+    if (!app)
+    {
+        FURI_LOG_E(TAG, "FlipWeatherApp is NULL");
+        return;
+    }
+    view_dispatcher_switch_to_view(app->view_dispatcher, FlipWeatherViewSubmenu);
+}
+
 void flip_weather_request_error(Canvas *canvas)
 {
     if (fhttp.last_response != NULL)
@@ -22,6 +33,13 @@ void flip_weather_request_error(Canvas *canvas)
             canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
             canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
         }
+        else if (strstr(fhttp.last_response, "[ERROR] GET request failed or returned empty data.") != NULL)
+        {
+            canvas_clear(canvas);
+            canvas_draw_str(canvas, 0, 10, "[ERROR] WiFi error.");
+            canvas_draw_str(canvas, 0, 50, "Update your WiFi settings.");
+            canvas_draw_str(canvas, 0, 60, "Press BACK to return.");
+        }
         else
         {
             canvas_clear(canvas);
@@ -102,7 +120,7 @@ void flip_weather_view_draw_callback_weather(Canvas *canvas, void *model)
     // handle geo location until it's processed and then handle weather
 
     // start the process
-    if (!send_geo_location_request())
+    if (!send_geo_location_request() || fhttp.state == ISSUE)
     {
         flip_weather_request_error(canvas);
     }
@@ -185,7 +203,7 @@ void flip_weather_view_draw_callback_gps(Canvas *canvas, void *model)
         return;
     }
 
-    if (!send_geo_location_request())
+    if (!send_geo_location_request() || fhttp.state == ISSUE)
     {
         flip_weather_request_error(canvas);
     }
@@ -206,14 +224,14 @@ void callback_submenu_choices(void *context, uint32_t index)
     case FlipWeatherSubmenuIndexWeather:
         if (!flip_weather_handle_ip_address())
         {
-            return;
+            view_dispatcher_switch_to_view(app->view_dispatcher, FlipWeatherViewPopupError);
         }
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipWeatherViewWeather);
         break;
     case FlipWeatherSubmenuIndexGPS:
         if (!flip_weather_handle_ip_address())
         {
-            return;
+            view_dispatcher_switch_to_view(app->view_dispatcher, FlipWeatherViewPopupError);
         }
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipWeatherViewGPS);
         break;

+ 1 - 0
callback/flip_weather_callback.h

@@ -9,6 +9,7 @@ extern bool weather_request_success;
 extern bool sent_weather_request;
 extern bool got_weather_data;
 
+void flip_weather_popup_callback(void *context);
 void flip_weather_request_error(Canvas *canvas);
 void flip_weather_handle_gps_draw(Canvas *canvas, bool show_gps_data);
 void flip_weather_view_draw_callback_weather(Canvas *canvas, void *model);

+ 7 - 0
flip_weather.c

@@ -68,6 +68,13 @@ void flip_weather_app_free(FlipWeatherApp *app)
         uart_text_input_free(app->uart_text_input_password);
     }
 
+    // Free Popup(s)
+    if (app->popup_error)
+    {
+        view_dispatcher_remove_view(app->view_dispatcher, FlipWeatherViewPopupError);
+        popup_free(app->popup_error);
+    }
+
     // Free the text input buffer
     if (app->uart_text_input_buffer_ssid)
         free(app->uart_text_input_buffer_ssid);

+ 3 - 0
flip_weather.h

@@ -27,6 +27,8 @@ typedef enum
     FlipWeatherViewSettings,          // The wifi settings screen
     FlipWeatherViewTextInputSSID,     // The text input screen for SSID
     FlipWeatherViewTextInputPassword, // The text input screen for password
+    //
+    FlipWeatherViewPopupError, // The error popup screen
 } FlipWeatherView;
 
 // Each screen will have its own view
@@ -37,6 +39,7 @@ typedef struct
     View *view_gps;                           // The GPS view
     Submenu *submenu;                         // The main submenu
     Widget *widget;                           // The widget (about)
+    Popup *popup_error;                       // The error popup
     VariableItemList *variable_item_list;     // The variable item list (settngs)
     VariableItem *variable_item_ssid;         // The variable item
     VariableItem *variable_item_password;     // The variable item

+ 12 - 0
parse/flip_weather_parse.c

@@ -42,6 +42,12 @@ bool flip_weather_parse_ip_address()
 // handle the async-to-sync process to get and set the IP address
 bool flip_weather_handle_ip_address()
 {
+    if (fhttp.state == INACTIVE)
+    {
+        FURI_LOG_E(TAG, "Board is INACTIVE");
+        flipper_http_ping(); // ping the device
+        return false;
+    }
     if (!got_ip_address)
     {
         got_ip_address = true;
@@ -82,6 +88,12 @@ bool flip_weather_handle_ip_address()
 
 bool send_geo_location_request()
 {
+    if (fhttp.state == INACTIVE)
+    {
+        FURI_LOG_E(TAG, "Board is INACTIVE");
+        flipper_http_ping(); // ping the device
+        return false;
+    }
     if (!sent_get_request && fhttp.state == IDLE)
     {
         sent_get_request = true;