2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 #define EEPROM_LEN 1024
22 static struct aoview_file *eeprom_file;
23 static char eeprom_line[EEPROM_LEN + 1];
24 static int eeprom_pos;
25 static GtkMessageDialog *eeprom_save_done;
26 static GtkWidget *eeprom_save_close;
27 static gboolean eeprom_save_shown;
30 aoview_eeprom_disconnect(struct aoview_serial *serial)
32 aoview_file_finish(eeprom_file);
36 aoview_eeprom_done(struct aoview_serial *serial)
38 gtk_window_set_title(GTK_WINDOW(eeprom_save_done),
40 gtk_message_dialog_set_markup(eeprom_save_done,
41 "<b>EEPROM data saved as</b>");
42 if (!eeprom_save_shown)
43 gtk_widget_show(GTK_WIDGET(eeprom_save_done));
44 eeprom_save_close = gtk_window_get_default_widget(GTK_WINDOW(eeprom_save_done));
45 if (eeprom_save_close)
46 gtk_widget_set_sensitive(eeprom_save_close, TRUE);
47 aoview_eeprom_disconnect(serial);
51 aoview_eeprom_parse(struct aoview_serial *serial,
62 if (!strcmp(line, "end")) {
63 aoview_eeprom_done(serial);
66 if (sscanf(line, "serial-number %u", &serial_number) == 1) {
67 aoview_file_set_serial(eeprom_file, serial_number);
68 } else if (sscanf(line, "%c %x %x %x", &cmd, &tick, &a, &b) == 4) {
69 aoview_file_printf(eeprom_file, "%s\n", line);
70 if (cmd == 'S' && a == 8) {
71 aoview_eeprom_done(serial);
75 if (!eeprom_save_shown)
77 name = aoview_file_name(eeprom_file);
79 utf8_name = g_filename_to_utf8(name, -1, NULL, NULL, NULL);
81 utf8_name = (char *) name;
82 gtk_widget_set_sensitive(eeprom_save_close, FALSE);
83 gtk_window_set_title(GTK_WINDOW(eeprom_save_done),
84 "Saving EEPROM data");
85 gtk_message_dialog_set_markup(eeprom_save_done,
86 "<b>Saving EEPROM data as</b>");
87 gtk_message_dialog_format_secondary_text(eeprom_save_done, "%s",
89 if (utf8_name != name)
91 gtk_container_check_resize(GTK_CONTAINER(eeprom_save_done));
92 gtk_widget_show(GTK_WIDGET(eeprom_save_done));
93 eeprom_save_shown = TRUE;
94 eeprom_save_close = gtk_window_get_default_widget(GTK_WINDOW(eeprom_save_done));
95 if (eeprom_save_close)
96 gtk_widget_set_sensitive(eeprom_save_close, FALSE);
104 aoview_eeprom_callback(gpointer user_data,
105 struct aoview_serial *serial,
110 if (revents & (G_IO_HUP|G_IO_ERR)) {
111 aoview_eeprom_disconnect(serial);
114 if (revents & G_IO_IN) {
116 c = aoview_serial_getc(serial);
122 eeprom_line[eeprom_pos] = '\0';
124 if (!aoview_eeprom_parse(serial, eeprom_line))
127 } else if (eeprom_pos < EEPROM_LEN)
128 eeprom_line[eeprom_pos++] = c;
134 aoview_eeprom_save(const char *device)
136 struct aoview_serial *serial;
138 gtk_widget_hide(GTK_WIDGET(eeprom_save_done));
139 eeprom_save_shown = FALSE;
140 serial = aoview_serial_open(device);
143 aoview_serial_set_callback(serial, aoview_eeprom_callback);
144 aoview_serial_printf(serial, "v\nl\n");
149 aoview_eeprom_init(GladeXML *xml)
151 eeprom_file = aoview_file_new("eeprom");
154 eeprom_save_done = GTK_MESSAGE_DIALOG(glade_xml_get_widget(xml, "ao_save_done"));
155 assert(eeprom_save_done);