From 2b756ea0f81ebe3ef92ba3d40b67b9ad0d2e19e6 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Sat, 17 Apr 2010 19:51:08 +0100 Subject: [PATCH] Add ability to turn off Garmin GPS after transfer. 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 | 10 +++++++ src/acquire.h | 3 +- src/babel.c | 4 +++ src/datasource_bfilter.c | 4 +++ src/datasource_gc.c | 3 +- src/datasource_google.c | 1 + src/datasource_gps.c | 59 ++++++++++++++++++++++++++++++++++++++-- 7 files changed, 80 insertions(+), 4 deletions(-) diff --git a/src/acquire.c b/src/acquire.c index 5e62bef3..90ee3fff 100644 --- a/src/acquire.c +++ b/src/acquire.c @@ -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 ); diff --git a/src/acquire.h b/src/acquire.h index 86ed42a3..ae173643 100644 --- a/src/acquire.h +++ b/src/acquire.h @@ -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; diff --git a/src/babel.c b/src/babel.c index fd1f286c..abd32227 100644 --- a/src/babel.c +++ b/src/babel.c @@ -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"); diff --git a/src/datasource_bfilter.c b/src/datasource_bfilter.c index 49e3ad38..453eb182 100644 --- a/src/datasource_bfilter.c +++ b/src/datasource_bfilter.c @@ -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, diff --git a/src/datasource_gc.c b/src/datasource_gc.c index 5b297e6a..5351ae71 100644 --- a/src/datasource_gc.c +++ b/src/datasource_gc.c @@ -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[] = { diff --git a/src/datasource_google.c b/src/datasource_google.c index 08c6e942..7cafd330 100644 --- a/src/datasource_google.c +++ b/src/datasource_google.c @@ -59,6 +59,7 @@ VikDataSourceInterface vik_datasource_google_interface = { (VikDataSourceProgressFunc) NULL, (VikDataSourceAddProgressWidgetsFunc) NULL, (VikDataSourceCleanupFunc) datasource_google_cleanup, + (VikDataSourceOffFunc) NULL, }; static gpointer datasource_google_init ( ) diff --git a/src/datasource_gps.c b/src/datasource_gps.c index 6c341b1e..e7de72e2 100644 --- a/src/datasource_gps.c +++ b/src/datasource_gps.c @@ -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 ); -- 2.39.5