From e29961fdb2a48874c895829880eadbf13e094c0c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 10 Oct 2009 11:43:31 -0700 Subject: [PATCH] Add channel menu to ao-view. Sets radio channel when TD is connected, saves selected channel in gconf database. Signed-off-by: Keith Packard --- ao-tools/ao-view/Makefile.am | 1 + ao-tools/ao-view/aoview.glade | 101 ++++++++++++++++++++++++++++++ ao-tools/ao-view/aoview.h | 11 ++++ ao-tools/ao-view/aoview_channel.c | 90 ++++++++++++++++++++++++++ ao-tools/ao-view/aoview_main.c | 2 + ao-tools/ao-view/aoview_monitor.c | 12 ++++ 6 files changed, 217 insertions(+) create mode 100644 ao-tools/ao-view/aoview_channel.c diff --git a/ao-tools/ao-view/Makefile.am b/ao-tools/ao-view/Makefile.am index 7b274a40..7a288417 100644 --- a/ao-tools/ao-view/Makefile.am +++ b/ao-tools/ao-view/Makefile.am @@ -25,6 +25,7 @@ ao_view_SOURCES = \ aoview_replay.c \ aoview_label.c \ aoview_flite.c \ + aoview_channel.c \ aoview.h BUILT_SOURCES = aoview_glade.h diff --git a/ao-tools/ao-view/aoview.glade b/ao-tools/ao-view/aoview.glade index 9a746110..c302ad0d 100644 --- a/ao-tools/ao-view/aoview.glade +++ b/ao-tools/ao-view/aoview.glade @@ -257,6 +257,107 @@ + + + True + _Channel + True + + + True + + + True + Channel 0 (434.550MHz) + True + True + + + + + True + Channel 1 (434.650MHz) + True + True + channel_0 + + + + + True + Channel 2 (434.750MHz) + True + True + channel_0 + + + + + True + Channel 3 (434.850MHz) + True + True + channel_0 + + + + + True + Channel 4 (434.950MHz) + True + True + channel_0 + + + + + True + Channel 5 (435.050MHz) + True + True + channel_0 + + + + + True + Channel 6 (435.150MHz) + True + True + channel_0 + + + + + True + Channel 7 (435.250MHz) + True + True + channel_0 + + + + + True + Channel 8 (435.350MHz) + True + True + channel_0 + + + + + True + Channel 9 (435.450MHz) + True + True + channel_0 + + + + + + True diff --git a/ao-tools/ao-view/aoview.h b/ao-tools/ao-view/aoview.h index 6a4753ac..c582159c 100644 --- a/ao-tools/ao-view/aoview.h +++ b/ao-tools/ao-view/aoview.h @@ -168,6 +168,9 @@ aoview_monitor_connect(char *tty); gboolean aoview_monitor_parse(const char *line); +void +aoview_monitor_set_channel(int channel); + void aoview_monitor_reset(void); @@ -320,4 +323,12 @@ aoview_flite_stop(void); extern char *aoview_tty; +/* aoview_channel.c */ + +int +aoview_channel_current(void); + +void +aoview_channel_init(GladeXML *xml); + #endif /* _AOVIEW_H_ */ diff --git a/ao-tools/ao-view/aoview_channel.c b/ao-tools/ao-view/aoview_channel.c new file mode 100644 index 00000000..959173ca --- /dev/null +++ b/ao-tools/ao-view/aoview_channel.c @@ -0,0 +1,90 @@ +/* + * Copyright © 2009 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include "aoview.h" + + +#define NUM_CHANNEL 10 + +static GtkRadioMenuItem *channel_item[NUM_CHANNEL]; + +int +aoview_channel_current(void) +{ + int c; + + for (c = 0; c < NUM_CHANNEL; c++) + if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(channel_item[c]))) + return c; + return -1; +} + +static void +aoview_channel_notify(int channel) +{ + if (0 <= channel && channel < NUM_CHANNEL) + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(channel_item[channel]), TRUE); +} + +#define ALTOS_CHANNEL_PATH "/apps/aoview/channel" + +static void +aoview_channel_change(GtkWidget *widget, gpointer data) +{ + gboolean enabled = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); + int c = (int) data; + GConfClient *gconf_client; + GError *error; + + if (enabled) { + aoview_monitor_set_channel(c); + gconf_client = gconf_client_get_default(); + gconf_client_set_int(gconf_client, ALTOS_CHANNEL_PATH, c, &error); + } +} + +void +aoview_channel_init(GladeXML *xml) +{ + int c; + GConfClient *gconf_client; + + for (c = 0; c < NUM_CHANNEL; c++) { + char name[32]; + + sprintf(name, "channel_%d", c); + channel_item[c] = GTK_RADIO_MENU_ITEM(glade_xml_get_widget(xml, name)); + assert(channel_item[c]); + g_signal_connect(G_OBJECT(channel_item[c]), "toggled", + G_CALLBACK(aoview_channel_change), + (gpointer) c); + } + gconf_client = gconf_client_get_default(); + c = 0; + if (gconf_client) + { + GError *error; + + error = NULL; + c = gconf_client_get_int(gconf_client, + ALTOS_CHANNEL_PATH, + &error); + if (error) + c = 0; + } + aoview_channel_notify(c); +} diff --git a/ao-tools/ao-view/aoview_main.c b/ao-tools/ao-view/aoview_main.c index 64c1c027..714bee9a 100644 --- a/ao-tools/ao-view/aoview_main.c +++ b/ao-tools/ao-view/aoview_main.c @@ -86,6 +86,8 @@ int main(int argc, char **argv) aoview_voice_init(xml); + aoview_channel_init(xml); + aoview_dev_dialog_init(xml); aoview_state_init(xml); diff --git a/ao-tools/ao-view/aoview_monitor.c b/ao-tools/ao-view/aoview_monitor.c index 8564014b..48e20320 100644 --- a/ao-tools/ao-view/aoview_monitor.c +++ b/ao-tools/ao-view/aoview_monitor.c @@ -82,6 +82,7 @@ aoview_monitor_parse(const char *input_line) char line_buf[8192], *line; struct aodata data; int tracking_pos; + int channel; /* avoid smashing our input parameter */ strncpy (line_buf, input_line, sizeof (line_buf)-1); @@ -214,15 +215,26 @@ aoview_monitor_callback(gpointer user_data, } } +void +aoview_monitor_set_channel(int channel) +{ + if (monitor_serial) + aoview_serial_printf(monitor_serial, "c r %d\n", channel); +} + gboolean aoview_monitor_connect(char *tty) { + int channel; aoview_monitor_disconnect(); monitor_serial = aoview_serial_open(tty); if (!monitor_serial) return FALSE; aoview_table_clear(); aoview_state_reset(); + channel = aoview_channel_current(); + if (channel >= 0) + aoview_monitor_set_channel(channel); aoview_serial_set_callback(monitor_serial, aoview_monitor_callback); return TRUE; -- 2.30.2