]> git.street.me.uk Git - andy/viking.git/commitdiff
Add ability to turn off Garmin GPS after transfer.
authorRob Norris <rw_norris@hotmail.com>
Sat, 17 Apr 2010 18:51:08 +0000 (19:51 +0100)
committerGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Wed, 19 May 2010 21:36:25 +0000 (23:36 +0200)
gpsbabel can turn off Garmin devices.
This is more useful for serial devices than USB ones, since serial ones use there own power.

src/acquire.c
src/acquire.h
src/babel.c
src/datasource_bfilter.c
src/datasource_gc.c
src/datasource_google.c
src/datasource_gps.c

index 5e62bef3c634d133723bd5d2c87cdf43496c84d1..90ee3fff6c6f58be6b037ca79b0c95e2f48b3fd2 100644 (file)
@@ -214,6 +214,7 @@ static void acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikD
   GtkWidget *dialog = NULL;
   GtkWidget *status;
   gchar *cmd, *extra;
+  gchar *cmd_off, *extra_off;
   acq_dialog_widgets_t *w;
   gpointer user_data;
 
@@ -296,6 +297,11 @@ static void acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikD
   } else
     source_interface->get_cmd_string_func ( pass_along_data, &cmd, &extra );
 
+  /* Get data for Off command */
+  if ( source_interface->off_func ) {
+    source_interface->off_func ( pass_along_data, &cmd_off, &extra_off );
+  }
+
   /* cleanup for option dialogs */
   if ( source_interface->add_setup_widgets_func ) {
     gtk_widget_destroy(dialog);
@@ -343,6 +349,10 @@ static void acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikD
   if ( w->ok )
     w->ok = FALSE; /* tell thread to stop. TODO: add mutex */
   else {
+    if ( cmd_off ) {
+      /* Turn off */
+      a_babel_convert_from (NULL, cmd_off, NULL, extra_off, NULL);
+    }
     g_free ( w ); /* thread has finished; free w */
   }
   gtk_widget_destroy ( dialog );
index 86ed42a3f1799a799052236b6f144a47745352dc..ae173643aa5bcb05db379e82a773a926e97ff77c 100644 (file)
@@ -89,6 +89,7 @@ typedef void  (*VikDataSourceAddProgressWidgetsFunc) ( GtkWidget *dialog, gpoint
 /* Frees any widgets created for the setup or progress dialogs, any allocated state, etc. */
 typedef void (*VikDataSourceCleanupFunc) ( gpointer user_data );
 
+typedef void (*VikDataSourceOffFunc) ( gpointer user_data, gchar **babelargs_or_shellcmd, gchar **inputfile_or_inputtype );;
 
 struct _VikDataSourceInterface {
   const gchar *window_title;
@@ -111,7 +112,7 @@ struct _VikDataSourceInterface {
   VikDataSourceProgressFunc progress_func;
   VikDataSourceAddProgressWidgetsFunc add_progress_widgets_func;
   VikDataSourceCleanupFunc cleanup_func;
-
+  VikDataSourceOffFunc off_func;
 
   /*** UI Building        ***/
   VikLayerParam *                   params;
index fd1f286c27aeb120f8222081dee400378571a6f6..abd322274982bdb9de646cfaf3d8b73975eff490 100644 (file)
@@ -158,6 +158,10 @@ gboolean babel_general_convert_from( VikTrwLayer *vt, BabelStatusFunc cb, gchar
     g_error_free(error);
     ret = FALSE;
   } else {
+    /* No data required */
+    if ( vt == NULL )
+      return TRUE;
+
     gchar line[512];
     FILE *diag;
     diag = fdopen(babel_stdout, "r");
index 49e3ad3883355588c11f2edf3fab5e5bacd13b7f..453eb1821f52330ca5205559b3d04f4c5e817fc8 100644 (file)
@@ -60,6 +60,7 @@ VikDataSourceInterface vik_datasource_bfilter_simplify_interface = {
   NULL, NULL, NULL,
   (VikDataSourceGetCmdStringFunc)      datasource_bfilter_simplify_get_cmd_string,
   NULL, NULL, NULL,
+  (VikDataSourceOffFunc) NULL,
 
   bfilter_simplify_params,
   sizeof(bfilter_simplify_params)/sizeof(bfilter_simplify_params[0]),
@@ -93,6 +94,7 @@ VikDataSourceInterface vik_datasource_bfilter_dup_interface = {
   NULL, NULL, NULL,
   (VikDataSourceGetCmdStringFunc)      datasource_bfilter_dup_get_cmd_string,
   NULL, NULL, NULL,
+  (VikDataSourceOffFunc) NULL,
 
   NULL, 0, NULL, NULL, 0
 };
@@ -123,6 +125,7 @@ VikDataSourceInterface vik_datasource_bfilter_polygon_interface = {
   NULL, NULL, NULL,
   (VikDataSourceGetCmdStringFunc)      datasource_bfilter_polygon_get_cmd_string,
   NULL, NULL, NULL,
+  (VikDataSourceOffFunc) NULL,
 
   NULL,
   0,
@@ -156,6 +159,7 @@ VikDataSourceInterface vik_datasource_bfilter_exclude_polygon_interface = {
   NULL, NULL, NULL,
   (VikDataSourceGetCmdStringFunc)      datasource_bfilter_exclude_polygon_get_cmd_string,
   NULL, NULL, NULL,
+  (VikDataSourceOffFunc) NULL,
 
   NULL,
   0,
index 5b297e6a8e9dd79369c17eafa4374bb533855498..5351ae71b2010552ad1a1e6fb79fa76450bbd865 100644 (file)
@@ -71,7 +71,8 @@ VikDataSourceInterface vik_datasource_gc_interface = {
   (VikDataSourceGetCmdStringFunc)      datasource_gc_get_cmd_string,
   (VikDataSourceProgressFunc)          NULL,
   (VikDataSourceAddProgressWidgetsFunc)        NULL,
-  (VikDataSourceCleanupFunc)           datasource_gc_cleanup
+  (VikDataSourceCleanupFunc)           datasource_gc_cleanup,
+  (VikDataSourceOffFunc)                NULL,
 };
 
 static VikLayerParam prefs[] = {
index 08c6e9427912eeba68d6028c8114aaaa6afae12f..7cafd3300a30132e8052f72af4d5b2d6080583f7 100644 (file)
@@ -59,6 +59,7 @@ VikDataSourceInterface vik_datasource_google_interface = {
   (VikDataSourceProgressFunc)          NULL,
   (VikDataSourceAddProgressWidgetsFunc)        NULL,
   (VikDataSourceCleanupFunc)           datasource_google_cleanup,
+  (VikDataSourceOffFunc)                NULL,
 };
 
 static gpointer datasource_google_init ( )
index 6c341b1ef2724974fc2ded48833ce3e8b1661cc7..e7de72e27fbf8fb6dadc75777b95ca9899aed009 100644 (file)
@@ -43,6 +43,7 @@ static void datasource_gps_cleanup ( gpointer user_data );
 static void datasource_gps_progress ( BabelProgressCode c, gpointer data, acq_dialog_widgets_t *w );
 static void datasource_gps_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data );
 static void datasource_gps_add_progress_widgets ( GtkWidget *dialog, gpointer user_data );
+static void datasource_gps_off ( gpointer add_widgets_data_not_used, gchar **babelargs, gchar **input_file );
 
 VikDataSourceInterface vik_datasource_gps_interface = {
   N_("Acquire from GPS"),
@@ -57,7 +58,8 @@ VikDataSourceInterface vik_datasource_gps_interface = {
   (VikDataSourceGetCmdStringFunc)      datasource_gps_get_cmd_string,
   (VikDataSourceProgressFunc)          datasource_gps_progress,
   (VikDataSourceAddProgressWidgetsFunc)        datasource_gps_add_progress_widgets,
-  (VikDataSourceCleanupFunc)           datasource_gps_cleanup
+  (VikDataSourceCleanupFunc)           datasource_gps_cleanup,
+  (VikDataSourceOffFunc)                datasource_gps_off
 };
 
 /*********************************************************
@@ -73,6 +75,8 @@ typedef struct {
   GtkComboBox *proto_b;
   GtkWidget *ser_l;
   GtkComboBox *ser_b;
+  GtkWidget *off_request_l;
+  GtkCheckButton *off_request_b;
 
   /* progress dialog */
   GtkWidget *gps_label;
@@ -118,6 +122,7 @@ static void datasource_gps_get_cmd_string ( gpointer user_data, gchar **babelarg
   } else {
     device = "magellan";
   }
+
   *babelargs = g_strdup_printf("-D 9 -t -w -i %s", device);
   /* device points to static content => no free */
   device = NULL;
@@ -133,6 +138,51 @@ static void datasource_gps_get_cmd_string ( gpointer user_data, gchar **babelarg
   g_debug(_("using cmdline '%s' and file '%s'\n"), *babelargs, *input_file);
 }
 
+
+static void datasource_gps_off ( gpointer user_data, gchar **babelargs, gchar **input_file )
+{
+  char *proto = NULL;
+  char *ser = NULL;
+  char *device = NULL;
+#ifndef USE_NEW_COMBO_BOX
+  GtkTreeIter iter;
+#endif
+  gps_user_data_t *w = (gps_user_data_t *)user_data;
+
+  if (gps_acquire_in_progress) {
+    *babelargs = *input_file = NULL;
+  }
+
+  /* See if we should turn off the device */
+  if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w->off_request_b))) {
+    return;
+  }
+  
+#ifdef USE_NEW_COMBO_BOX
+  proto = gtk_combo_box_get_active_text(GTK_COMBO_BOX(w->proto_b));
+#else
+  proto = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(w->proto_b),&iter);
+#endif
+  if (!strcmp(proto, "Garmin")) {
+    device = "garmin,power_off";
+  } else {
+    return;
+  }
+
+  *babelargs = g_strdup_printf("-i %s", device);
+  /* device points to static content => no free */
+  device = NULL;
+  
+  /* Old stuff */
+#ifdef USE_NEW_COMBO_BOX
+  ser = gtk_combo_box_get_active_text(GTK_COMBO_BOX(w->ser_b));
+#else
+  ser = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(w->ser_b),&iter);
+#endif
+  *input_file = g_strdup(ser);
+}
+
+
 static void datasource_gps_cleanup ( gpointer user_data )
 {
   g_free ( user_data );
@@ -280,11 +330,16 @@ void datasource_gps_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpo
   gtk_combo_box_set_active (w->ser_b, 0);
   g_object_ref(w->ser_b);
 
-  box = GTK_TABLE(gtk_table_new(2, 2, FALSE));
+  w->off_request_l = gtk_label_new (_("Turn Off After Transfer\n(Garmin Only)"));
+  w->off_request_b = GTK_CHECK_BUTTON ( gtk_check_button_new () );
+
+  box = GTK_TABLE(gtk_table_new(2, 3, FALSE));
   gtk_table_attach_defaults(box, GTK_WIDGET(w->proto_l), 0, 1, 0, 1);
   gtk_table_attach_defaults(box, GTK_WIDGET(w->proto_b), 1, 2, 0, 1);
   gtk_table_attach_defaults(box, GTK_WIDGET(w->ser_l), 0, 1, 1, 2);
   gtk_table_attach_defaults(box, GTK_WIDGET(w->ser_b), 1, 2, 1, 2);
+  gtk_table_attach_defaults(box, GTK_WIDGET(w->off_request_l), 0, 1, 2, 3);
+  gtk_table_attach_defaults(box, GTK_WIDGET(w->off_request_b), 1, 3, 2, 3);
   gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), GTK_WIDGET(box), FALSE, FALSE, 5 );
 
   gtk_widget_show_all ( dialog );