Improved the detection when a fix is really usable
[gps-tracker] / gps-tracker.c
index 0e39111..392ff79 100644 (file)
@@ -22,7 +22,7 @@ typedef struct {
     //GtkWidget *wp_label;
     GtkButton *wp_set_btn;
     GString *wp_marker_str;
-    gboolean tracking_is_on;
+    gboolean tracking_is_on, has_fix;
     FILE *outf_p;
     guint points_recorded_in_current_segment;
     LocationGPSDeviceStatus last_device_status;
@@ -163,9 +163,21 @@ static void on_gps_device_changed (LocationGPSDevice *device, gpointer data)
        if (!device)
                return;
 
-  if (device->fix) {
+  /* if there is no fix, or we are recording (fp != NULL), but the fix is so
+   * bad that it is a 2D fix only, with no time set then do not
+   * record any longer */
+  if ((device->status == LOCATION_GPS_DEVICE_STATUS_NO_FIX) ||
+      (device->fix && fp &&
+       (! device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) &&
+       (device->fix->mode == LOCATION_GPS_DEVICE_MODE_2D))) {
+    app_data->has_fix = FALSE;
+    hildon_banner_show_information(GTK_WIDGET(app_data->window), NULL, "WARNING: Lost fix");
+    app_data->last_device_status = LOCATION_GPS_DEVICE_STATUS_NO_FIX;
+  }
+  else if (device->fix) {
     //g_print("mode=%d stat=%d\n", device->fix->mode, device->status);
     if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
+      app_data->has_fix = TRUE; /* fix found again */
       //g_print ("lat = %f, long = %f\n", device->fix->latitude, device->fix->longitude);
       CHANGE_LABEL(app_data->lat_val_label, "% 9.6f", device->fix->latitude);
       CHANGE_LABEL(app_data->lon_val_label, "% 9.6f", device->fix->longitude);
@@ -259,8 +271,6 @@ static void on_gps_device_changed (LocationGPSDevice *device, gpointer data)
       }
     }
   }
-  else
-    g_print("device->fix=%p\n", device->fix);
        
        //g_print ("Satellites in view: %d\n", device->satellites_in_view);
        //g_print ("Satellites in use: %d\n", device->satellites_in_use);
@@ -275,7 +285,11 @@ static void on_gps_device_changed (LocationGPSDevice *device, gpointer data)
        //              g_print ("Mobile Coutry Code WCDMA: %d\n", device->cell_info->wcdma_cell_info.mcc);
        //}
 
-  if(device->status == LOCATION_GPS_DEVICE_STATUS_NO_FIX) {
+  if(app_data->has_fix) {
+    hildon_gtk_window_set_progress_indicator(GTK_WINDOW(app_data->window), 0);
+    gtk_widget_set_sensitive(GTK_WIDGET(app_data->start_stop_button), TRUE);
+  }
+  else {
     hildon_gtk_window_set_progress_indicator(GTK_WINDOW(app_data->window), 1);
     CHANGE_LABEL(app_data->lat_val_label, " ?", NULL);
     CHANGE_LABEL(app_data->lon_val_label, " ?", NULL);
@@ -283,10 +297,6 @@ static void on_gps_device_changed (LocationGPSDevice *device, gpointer data)
     CHANGE_LABEL(app_data->speed_val_label, " ?", NULL);
     CHANGE_LABEL(app_data->track_val_label, " ?", NULL);
   }
-  else {
-    hildon_gtk_window_set_progress_indicator(GTK_WINDOW(app_data->window), 0);
-    gtk_widget_set_sensitive(GTK_WIDGET(app_data->start_stop_button), TRUE);
-  }
 }
 
 static void