commit 8027ce29b7e08095530e2ee1fb98facda7778b49 Author: Olaf Rempel Date: Sun Jun 22 17:53:20 2008 +0200 working version diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..19c448e --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.o +*.d +blmc-config +*.bin +*.hex diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8d90a0f --- /dev/null +++ b/Makefile @@ -0,0 +1,30 @@ +TARGET = blmc-config + +CFLAGS = -Wall -O2 -MD -MP -MF $(*F).d +LDFLAGS = $(shell pkg-config --libs gtk+-2.0) +CFLAGS += $(shell pkg-config --cflags gtk+-2.0) + +# ------ + +SRC := $(wildcard *.c) + +all: $(TARGET) + +$(TARGET): $(SRC:.c=.o) + @echo " Linking file: $@" + @$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) > /dev/null + +%.o: %.c + @echo " Building file: $<" + @$(CC) -c $(CFLAGS) $< -o $@ + +clean: + rm -rf $(TARGET) *.o *.d + +driver: + sudo rmmod lp ppdev + sudo modprobe i2c-parport type=3 + sudo modprobe i2c-dev + sudo chmod 666 /dev/i2c-0 + +-include $(shell find -name *.d 2> /dev/null) diff --git a/blmc-config.c b/blmc-config.c new file mode 100644 index 0000000..c82d6fb --- /dev/null +++ b/blmc-config.c @@ -0,0 +1,37 @@ +/*************************************************************************** + * Copyright (C) 06/2008 by Olaf Rempel * + * razzor@kopf-tisch.de * + * * + * 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 +#include + +#include "gtk2-gui.h" +#include "i2c.h" + +int main(int argc, char *argv[]) +{ + gtk_init (&argc, &argv); + + GtkWidget *window = gui_create_window(); + + i2c_enumerate_interfaces(); + + gtk_widget_show_all(window); + gtk_main(); + + return 0; +} diff --git a/gtk2-gui.c b/gtk2-gui.c new file mode 100644 index 0000000..5fa2c20 --- /dev/null +++ b/gtk2-gui.c @@ -0,0 +1,1057 @@ +/*************************************************************************** + * Copyright (C) 06/2008 by Olaf Rempel * + * razzor@kopf-tisch.de * + * * + * 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 + +#include +#include "gtk2-gui.h" +#include "i2c.h" + +static GtkWidget *combobox101; +static GtkWidget *spinbutton101; +static GtkWidget *textview101; + +static GtkWidget *filechooserbutton201; +static GtkWidget *filechooserbutton202; +static GtkWidget *progressbar201; + +static GtkWidget *spinbutton301; +static GtkWidget *spinbutton302; +static GtkWidget *spinbutton303; +static GtkWidget *spinbutton304; +static GtkWidget *spinbutton305; +static GtkWidget *spinbutton306; +static GtkWidget *spinbutton307; +static GtkWidget *spinbutton308; +static GtkWidget *spinbutton309; +static GtkWidget *spinbutton310; + +static GtkWidget *entry401; +static GtkWidget *entry402; +static GtkWidget *entry403; +static GtkWidget *entry404; +static GtkWidget *entry405; +static GtkWidget *vscale401; +static GtkWidget *togglebutton401; + +static int i2c_fd = -1; +static struct blmc_parameter blmc_parameters; +static int parameter_update_in_progress = 0; + +static void add_message(const char *msg) +{ + if (msg == NULL) + msg = "EMPTY MESSAGE\n"; + + GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview101)); + gtk_text_buffer_insert_at_cursor(buffer, msg, strlen(msg)); + GtkTextMark *mark = gtk_text_buffer_get_insert(buffer); + gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(textview101), mark); +} + +static void update_parameter_boxes(void) +{ + parameter_update_in_progress = 1; + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton301), blmc_parameters.spinup_ticks); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton302), blmc_parameters.spinup_tick); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton303), blmc_parameters.spinup_step); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton304), blmc_parameters.spinup_wait); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton305), blmc_parameters.spinup_pwm); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton306), blmc_parameters.pwm_min); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton307), blmc_parameters.pwm_max); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton308), blmc_parameters.current_limit); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton309), blmc_parameters.current_max); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton310), blmc_parameters.voltage_min); + parameter_update_in_progress = 0; +} + +static void update_status_boxes(struct blmc_status *status) +{ + char buf[16]; + + snprintf(buf, sizeof(buf), "%d", status->pwm); + gtk_entry_set_text(GTK_ENTRY(entry401), buf); + + snprintf(buf, sizeof(buf), "%d", status->pwm_real); + gtk_entry_set_text(GTK_ENTRY(entry402), buf); + + snprintf(buf, sizeof(buf), "%d", status->rpm); + gtk_entry_set_text(GTK_ENTRY(entry403), buf); + + snprintf(buf, sizeof(buf), "%d", status->current); + gtk_entry_set_text(GTK_ENTRY(entry404), buf); + + snprintf(buf, sizeof(buf), "%d", status->voltage); + gtk_entry_set_text(GTK_ENTRY(entry405), buf); +} + +static void on_spinbutton101_value_changed(GtkSpinButton *spinbutton, gpointer user_data) +{ + int address = gtk_spin_button_get_value_as_int(spinbutton); + if (i2c_fd != -1) + i2c_set_address(i2c_fd, address); +} + +/* CONNECT Button */ +static void on_button101_clicked(GtkButton *button, gpointer user_data) +{ + if (!i2c_isconnected()) { + /* not connected, so this is a CONNECT */ + char *path = gtk_combo_box_get_active_text(GTK_COMBO_BOX(combobox101)); + int address = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton101)); + + i2c_fd = i2c_open(path); + if (i2c_fd != -1) + i2c_set_address(i2c_fd, address); + + } else { + i2c_close(i2c_fd); + i2c_fd = -1; + } + + if (i2c_isconnected()) { + gtk_button_set_label(button, "Disconnect"); + + } else { + gtk_button_set_label(GTK_BUTTON(button), "Connect"); + } +} + +static gint bootloader_cb(gpointer data) +{ + char info_buf[16]; + unsigned char sig_buf[4]; + + i2c_cmd_getinfo(i2c_fd, info_buf, sizeof(info_buf)); + i2c_cmd_getsignature(i2c_fd, sig_buf, sizeof(sig_buf)); + + char msg_buf[64]; + snprintf(msg_buf, sizeof(msg_buf), "%-16s (sig: 0x%02x%02x%02x)\n", + info_buf, sig_buf[0], sig_buf[1], sig_buf[2]); + + add_message(msg_buf); + return 0; +} + +/* Bootloader Button */ +static void on_button102_clicked(GtkButton *button, gpointer user_data) +{ + i2c_cmd_bootloader(i2c_fd); + g_timeout_add(150, bootloader_cb, NULL); +} + +static gint application_cb(gpointer data) +{ + char info_buf[16]; + + i2c_cmd_getinfo(i2c_fd, info_buf, sizeof(info_buf)); + i2c_cmd_getparameters(i2c_fd, &blmc_parameters); + + char msg_buf[64]; + snprintf(msg_buf, sizeof(msg_buf), "%-16s\n", info_buf); + add_message(msg_buf); + + update_parameter_boxes(); + return 0; +} + +/* Application Button */ +static void on_button103_clicked(GtkButton *button, gpointer user_data) +{ + i2c_cmd_application(i2c_fd); + g_timeout_add(150, application_cb, NULL); +} + +/* FLASH-READ Button */ +static void on_button201_clicked(GtkButton *button, gpointer user_data) +{ + add_message("sorry, not implemented yet\n"); +} + +static void progress_cb(double progress) +{ + if (progress < 0.0) + progress = 0.0; + else if (progress > 1.0) + progress = 1.0; + + char buf[16]; + snprintf(buf, sizeof(buf), "%3.0f%%", progress * 100); + + gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progressbar201), buf); + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar201), progress); + gdk_window_process_updates(gtk_widget_get_parent_window(progressbar201), 1); +} + +/* FLASH-WRITE Button */ +static void on_button202_clicked(GtkButton *button, gpointer user_data) +{ + char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filechooserbutton201)); + int size = i2c_write_flash(i2c_fd, filename, progress_cb); + + char msg_buf[64]; + snprintf(msg_buf, sizeof(msg_buf), "FLASH: %d bytes written and verified\n", size); + add_message(msg_buf); +} + +/* FLASH-VERIFY Button */ +static void on_button203_clicked(GtkButton *button, gpointer user_data) +{ + add_message("sorry, not implemented yet\n"); +} + +/* FLASH-CLEAR Button */ +static void on_button204_clicked(GtkButton *button, gpointer user_data) +{ + add_message("sorry, not implemented yet\n"); +} + +/* EEPROM-READ Button */ +static void on_button205_clicked(GtkButton *button, gpointer user_data) +{ + add_message("sorry, not implemented yet\n"); +} + +/* EEPROM-WRITE Button */ +static void on_button206_clicked(GtkButton *button, gpointer user_data) +{ + add_message("sorry, not implemented yet\n"); +} + +/* EEPROM-VERIFY Button */ +static void on_button207_clicked(GtkButton *button, gpointer user_data) +{ + add_message("sorry, not implemented yet\n"); +} + +/* EEPROM-CLEAR Button */ +static void on_button208_clicked(GtkButton *button, gpointer user_data) +{ + add_message("sorry, not implemented yet\n"); +} + +static void on_parameter_value_changed(GtkSpinButton *spinbutton, gpointer user_data) +{ + if (parameter_update_in_progress) + return; + + blmc_parameters.spinup_ticks = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton301)); + blmc_parameters.spinup_tick = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton302)); + blmc_parameters.spinup_step = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton303)); + blmc_parameters.spinup_wait = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton304)); + blmc_parameters.spinup_pwm = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton305)); + blmc_parameters.pwm_min = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton306)); + blmc_parameters.pwm_max = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton307)); + blmc_parameters.current_limit = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton308)); + blmc_parameters.current_max = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton309)); + blmc_parameters.voltage_min = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinbutton310)); + + i2c_cmd_setparameters(i2c_fd, &blmc_parameters, 0); + add_message("parameter updated\n"); +} + +/* Revert parameters to default */ +static void on_button301_clicked(GtkButton *button, gpointer user_data) +{ + add_message("sorry, not implemented yet\n"); +} + +/* save parameters */ +static void on_button302_clicked(GtkButton *button, gpointer user_data) +{ + i2c_cmd_setparameters(i2c_fd, &blmc_parameters, 1); + add_message("parameter saved\n"); +} + +static gint pwm_update_cb(gpointer data) +{ + int active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglebutton401)); + int pwm = gtk_range_get_value(GTK_RANGE(vscale401)); + + if (!active) + pwm = 0; + + i2c_cmd_setpwm(i2c_fd, pwm); + + struct blmc_status status; + i2c_cmd_getstatus(i2c_fd, &status); + update_status_boxes(&status); + return active; +} + +/* Motor Togglebutton */ +static void on_togglebutton401_toggled(GtkToggleButton *togglebutton, gpointer user_data) +{ + g_timeout_add(50, pwm_update_cb, NULL); +} + +static unsigned int i2c_interface_count; + +void gui_add_i2c_interface(const char *path) +{ + gtk_combo_box_append_text(GTK_COMBO_BOX(combobox101), path); + gtk_combo_box_set_active(GTK_COMBO_BOX(combobox101), 0); + i2c_interface_count++; +} + +void gui_flush_i2c_interfaces(void) { + while (i2c_interface_count-- > 0) + gtk_combo_box_remove_text(GTK_COMBO_BOX(combobox101), 0); +} + +GtkWidget * gui_create_window (void) +{ + GtkWidget *window; + GtkWidget *table1; + GtkWidget *frame400; + GtkWidget *table401; + GtkWidget *label401; + GtkWidget *label402; + GtkWidget *label403; + GtkWidget *label407; + GtkWidget *label408; +// GtkWidget *vscale401; +// GtkWidget *togglebutton401; +// GtkWidget *entry401; +// GtkWidget *entry402; +// GtkWidget *entry403; +// GtkWidget *entry405; +// GtkWidget *entry406; + GtkWidget *vseparator402; + GtkWidget *vseparator401; + GtkWidget *label400; + GtkWidget *frame200; + GtkWidget *table201; + GtkWidget *button202; + GtkWidget *button204; + GtkWidget *button203; + GtkWidget *button201; + GtkWidget *label201; +// GtkWidget *filechooserbutton201; + GtkWidget *label202; +// GtkWidget *filechooserbutton202; + GtkWidget *button207; + GtkWidget *button208; + GtkWidget *button205; + GtkWidget *button206; + GtkWidget *vseparator201; +// GtkWidget *progressbar201; + GtkWidget *label200; + GtkWidget *frame300; + GtkWidget *table301; + GtkWidget *label301; + GtkWidget *label302; + GtkWidget *label303; + GtkWidget *label304; + GtkWidget *label305; + GtkWidget *label306; + GtkWidget *label307; + GtkWidget *label308; + GtkWidget *label309; + GtkWidget *label310; + GtkWidget *hseparator301; + GtkObject *spinbutton302_adj; +// GtkWidget *spinbutton302; + GtkObject *spinbutton307_adj; +// GtkWidget *spinbutton307; + GtkObject *spinbutton303_adj; +// GtkWidget *spinbutton303; + GtkObject *spinbutton308_adj; +// GtkWidget *spinbutton308; + GtkObject *spinbutton304_adj; +// GtkWidget *spinbutton304; + GtkObject *spinbutton309_adj; +// GtkWidget *spinbutton309; + GtkObject *spinbutton305_adj; +// GtkWidget *spinbutton305; + GtkObject *spinbutton310_adj; +// GtkWidget *spinbutton310; + GtkWidget *hbuttonbox301; + GtkWidget *button301; + GtkWidget *button302; + GtkObject *spinbutton301_adj; +// GtkWidget *spinbutton301; + GtkObject *spinbutton306_adj; +// GtkWidget *spinbutton306; + GtkWidget *vseparator301; + GtkWidget *label300; + GtkWidget *frame100; + GtkWidget *table101; + GtkWidget *label101; +// GtkWidget *combobox101; + GtkWidget *label102; + GtkObject *spinbutton101_adj; +// GtkWidget *spinbutton101; + GtkWidget *scrolledwindow101; +// GtkWidget *textview101; + GtkWidget *hbuttonbox101; + GtkWidget *button101; + GtkWidget *button102; + GtkWidget *button103; + GtkWidget *hseparator101; + GtkWidget *hseparator102; + GtkWidget *label100; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_container_set_border_width (GTK_CONTAINER (window), 10); + gtk_window_set_title (GTK_WINDOW (window), "blmc-config v0.20"); + gtk_window_set_resizable (GTK_WINDOW (window), FALSE); + + table1 = gtk_table_new (2, 2, FALSE); + gtk_widget_show (table1); + gtk_container_add (GTK_CONTAINER (window), table1); + gtk_table_set_row_spacings (GTK_TABLE (table1), 5); + gtk_table_set_col_spacings (GTK_TABLE (table1), 5); + + frame400 = gtk_frame_new (NULL); + gtk_widget_show (frame400); + gtk_table_attach (GTK_TABLE (table1), frame400, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_FILL), 0, 0); + gtk_frame_set_shadow_type (GTK_FRAME (frame400), GTK_SHADOW_IN); + + table401 = gtk_table_new (5, 6, FALSE); + gtk_widget_show (table401); + gtk_container_add (GTK_CONTAINER (frame400), table401); + gtk_container_set_border_width (GTK_CONTAINER (table401), 5); + gtk_table_set_row_spacings (GTK_TABLE (table401), 2); + gtk_table_set_col_spacings (GTK_TABLE (table401), 2); + + label401 = gtk_label_new ("PWM:"); + gtk_widget_show (label401); + gtk_table_attach (GTK_TABLE (table401), label401, 0, 1, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label401), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label401), 5, 0); + + label402 = gtk_label_new ("PWM (real):"); + gtk_widget_show (label402); + gtk_table_attach (GTK_TABLE (table401), label402, 0, 1, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label402), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label402), 5, 0); + + label403 = gtk_label_new ("RPM:"); + gtk_widget_show (label403); + gtk_table_attach (GTK_TABLE (table401), label403, 0, 1, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label403), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label403), 5, 0); + + label407 = gtk_label_new ("Current:"); + gtk_widget_show (label407); + gtk_table_attach (GTK_TABLE (table401), label407, 0, 1, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label407), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label407), 5, 0); + + label408 = gtk_label_new ("Voltage:"); + gtk_widget_show (label408); + gtk_table_attach (GTK_TABLE (table401), label408, 0, 1, 4, 5, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label408), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label408), 5, 0); + + vscale401 = gtk_vscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 255, 0, 0, 0))); + gtk_widget_show (vscale401); + gtk_table_attach (GTK_TABLE (table401), vscale401, 3, 4, 0, 5, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (GTK_FILL), 0, 0); + gtk_scale_set_value_pos (GTK_SCALE (vscale401), GTK_POS_BOTTOM); + gtk_scale_set_digits (GTK_SCALE (vscale401), 0); + gtk_range_set_inverted (GTK_RANGE (vscale401), TRUE); + + togglebutton401 = gtk_toggle_button_new_with_mnemonic ("Motor"); + gtk_widget_show (togglebutton401); + gtk_table_attach (GTK_TABLE (table401), togglebutton401, 5, 6, 0, 5, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + entry401 = gtk_entry_new (); + gtk_widget_show (entry401); + gtk_table_attach (GTK_TABLE (table401), entry401, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_editable_set_editable (GTK_EDITABLE (entry401), FALSE); + gtk_entry_set_text (GTK_ENTRY (entry401), "0"); + gtk_entry_set_invisible_char (GTK_ENTRY (entry401), 9679); + gtk_entry_set_width_chars (GTK_ENTRY (entry401), 8); + + entry402 = gtk_entry_new (); + gtk_widget_show (entry402); + gtk_table_attach (GTK_TABLE (table401), entry402, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_editable_set_editable (GTK_EDITABLE (entry402), FALSE); + gtk_entry_set_text (GTK_ENTRY (entry402), "0"); + gtk_entry_set_invisible_char (GTK_ENTRY (entry402), 9679); + gtk_entry_set_width_chars (GTK_ENTRY (entry402), 8); + + entry403 = gtk_entry_new (); + gtk_widget_show (entry403); + gtk_table_attach (GTK_TABLE (table401), entry403, 1, 2, 2, 3, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_editable_set_editable (GTK_EDITABLE (entry403), FALSE); + gtk_entry_set_text (GTK_ENTRY (entry403), "0"); + gtk_entry_set_invisible_char (GTK_ENTRY (entry403), 9679); + gtk_entry_set_width_chars (GTK_ENTRY (entry403), 8); + + entry404 = gtk_entry_new (); + gtk_widget_show (entry404); + gtk_table_attach (GTK_TABLE (table401), entry404, 1, 2, 3, 4, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_editable_set_editable (GTK_EDITABLE (entry404), FALSE); + gtk_entry_set_text (GTK_ENTRY (entry404), "0"); + gtk_entry_set_invisible_char (GTK_ENTRY (entry404), 9679); + gtk_entry_set_width_chars (GTK_ENTRY (entry404), 8); + + entry405 = gtk_entry_new (); + gtk_widget_show (entry405); + gtk_table_attach (GTK_TABLE (table401), entry405, 1, 2, 4, 5, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_editable_set_editable (GTK_EDITABLE (entry405), FALSE); + gtk_entry_set_text (GTK_ENTRY (entry405), "0"); + gtk_entry_set_invisible_char (GTK_ENTRY (entry405), 9679); + gtk_entry_set_width_chars (GTK_ENTRY (entry405), 8); + + vseparator402 = gtk_vseparator_new (); + gtk_widget_show (vseparator402); + gtk_table_attach (GTK_TABLE (table401), vseparator402, 4, 5, 0, 5, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (GTK_FILL), 0, 0); + + vseparator401 = gtk_vseparator_new (); + gtk_widget_show (vseparator401); + gtk_table_attach (GTK_TABLE (table401), vseparator401, 2, 3, 0, 5, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (GTK_FILL), 0, 0); + + label400 = gtk_label_new ("Motorttest:"); + gtk_widget_show (label400); + gtk_frame_set_label_widget (GTK_FRAME (frame400), label400); + gtk_label_set_use_markup (GTK_LABEL (label400), TRUE); + gtk_misc_set_padding (GTK_MISC (label400), 5, 0); + + frame200 = gtk_frame_new (NULL); + gtk_widget_show (frame200); + gtk_table_attach (GTK_TABLE (table1), frame200, 0, 1, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_FILL), 0, 0); + gtk_frame_set_shadow_type (GTK_FRAME (frame200), GTK_SHADOW_IN); + + table201 = gtk_table_new (5, 5, FALSE); + gtk_widget_show (table201); + gtk_container_add (GTK_CONTAINER (frame200), table201); + gtk_container_set_border_width (GTK_CONTAINER (table201), 5); + gtk_table_set_row_spacings (GTK_TABLE (table201), 2); + gtk_table_set_col_spacings (GTK_TABLE (table201), 2); + + button202 = gtk_button_new_with_mnemonic ("WRITE"); + gtk_widget_show (button202); + gtk_table_attach (GTK_TABLE (table201), button202, 0, 1, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_container_set_border_width (GTK_CONTAINER (button202), 5); + GTK_WIDGET_SET_FLAGS (button202, GTK_CAN_DEFAULT); + + button204 = gtk_button_new_with_mnemonic ("CLEAR"); + gtk_widget_show (button204); + gtk_table_attach (GTK_TABLE (table201), button204, 1, 2, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_container_set_border_width (GTK_CONTAINER (button204), 5); + + button203 = gtk_button_new_with_mnemonic ("VERIFY"); + gtk_widget_show (button203); + gtk_table_attach (GTK_TABLE (table201), button203, 1, 2, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_container_set_border_width (GTK_CONTAINER (button203), 5); + + button201 = gtk_button_new_with_mnemonic ("READ"); + gtk_widget_show (button201); + gtk_table_attach (GTK_TABLE (table201), button201, 0, 1, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_container_set_border_width (GTK_CONTAINER (button201), 5); + GTK_WIDGET_SET_FLAGS (button201, GTK_CAN_DEFAULT); + + label201 = gtk_label_new ("FLASH:"); + gtk_widget_show (label201); + gtk_table_attach (GTK_TABLE (table201), label201, 0, 2, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + filechooserbutton201 = gtk_file_chooser_button_new ("Select A File", GTK_FILE_CHOOSER_ACTION_OPEN); + gtk_widget_show (filechooserbutton201); + gtk_table_attach (GTK_TABLE (table201), filechooserbutton201, 0, 2, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 5, 0); + g_object_set (filechooserbutton201, + "width-chars", 15, + NULL); + + label202 = gtk_label_new ("EEPROM:"); + gtk_widget_show (label202); + gtk_table_attach (GTK_TABLE (table201), label202, 3, 5, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + filechooserbutton202 = gtk_file_chooser_button_new ("Select A File", GTK_FILE_CHOOSER_ACTION_OPEN); + gtk_widget_show (filechooserbutton202); + gtk_table_attach (GTK_TABLE (table201), filechooserbutton202, 3, 5, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 5, 0); + g_object_set (filechooserbutton202, + "width-chars", 16, + NULL); + + button207 = gtk_button_new_with_mnemonic ("VERIFY"); + gtk_widget_show (button207); + gtk_table_attach (GTK_TABLE (table201), button207, 4, 5, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_container_set_border_width (GTK_CONTAINER (button207), 5); + + button208 = gtk_button_new_with_mnemonic ("CLEAR"); + gtk_widget_show (button208); + gtk_table_attach (GTK_TABLE (table201), button208, 4, 5, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_container_set_border_width (GTK_CONTAINER (button208), 5); + + button205 = gtk_button_new_with_mnemonic ("READ"); + gtk_widget_show (button205); + gtk_table_attach (GTK_TABLE (table201), button205, 3, 4, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_container_set_border_width (GTK_CONTAINER (button205), 5); + GTK_WIDGET_SET_FLAGS (button205, GTK_CAN_DEFAULT); + + button206 = gtk_button_new_with_mnemonic ("WRITE"); + gtk_widget_show (button206); + gtk_table_attach (GTK_TABLE (table201), button206, 3, 4, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_container_set_border_width (GTK_CONTAINER (button206), 5); + GTK_WIDGET_SET_FLAGS (button206, GTK_CAN_DEFAULT); + + vseparator201 = gtk_vseparator_new (); + gtk_widget_show (vseparator201); + gtk_table_attach (GTK_TABLE (table201), vseparator201, 2, 3, 0, 4, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (GTK_FILL), 5, 0); + + progressbar201 = gtk_progress_bar_new (); + gtk_widget_show (progressbar201); + gtk_table_attach (GTK_TABLE (table201), progressbar201, 0, 5, 4, 5, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progressbar201), "0%"); + + label200 = gtk_label_new ("Bootloader:"); + gtk_widget_show (label200); + gtk_frame_set_label_widget (GTK_FRAME (frame200), label200); + gtk_label_set_use_markup (GTK_LABEL (label200), TRUE); + gtk_misc_set_padding (GTK_MISC (label200), 5, 0); + + frame300 = gtk_frame_new (NULL); + gtk_widget_show (frame300); + gtk_table_attach (GTK_TABLE (table1), frame300, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_FILL), 0, 0); + gtk_frame_set_shadow_type (GTK_FRAME (frame300), GTK_SHADOW_IN); + + table301 = gtk_table_new (7, 5, FALSE); + gtk_widget_show (table301); + gtk_container_add (GTK_CONTAINER (frame300), table301); + gtk_container_set_border_width (GTK_CONTAINER (table301), 5); + gtk_table_set_row_spacings (GTK_TABLE (table301), 2); + gtk_table_set_col_spacings (GTK_TABLE (table301), 2); + + label301 = gtk_label_new ("SPINUP Ticks:"); + gtk_widget_show (label301); + gtk_table_attach (GTK_TABLE (table301), label301, 0, 1, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label301), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label301), 5, 0); + + label302 = gtk_label_new ("SPINUP Tick:"); + gtk_widget_show (label302); + gtk_table_attach (GTK_TABLE (table301), label302, 0, 1, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label302), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label302), 5, 0); + + label303 = gtk_label_new ("SPINUP Step:"); + gtk_widget_show (label303); + gtk_table_attach (GTK_TABLE (table301), label303, 0, 1, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label303), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label303), 5, 0); + + label304 = gtk_label_new ("SPINUP Wait:"); + gtk_widget_show (label304); + gtk_table_attach (GTK_TABLE (table301), label304, 0, 1, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label304), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label304), 5, 0); + + label305 = gtk_label_new ("SPINUP PWM:"); + gtk_widget_show (label305); + gtk_table_attach (GTK_TABLE (table301), label305, 0, 1, 4, 5, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label305), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label305), 5, 0); + + label306 = gtk_label_new ("min. PWM:"); + gtk_widget_show (label306); + gtk_table_attach (GTK_TABLE (table301), label306, 3, 4, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label306), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label306), 5, 0); + + label307 = gtk_label_new ("max. PWM:"); + gtk_widget_show (label307); + gtk_table_attach (GTK_TABLE (table301), label307, 3, 4, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label307), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label307), 5, 0); + + label308 = gtk_label_new ("Current Limit:"); + gtk_widget_show (label308); + gtk_table_attach (GTK_TABLE (table301), label308, 3, 4, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label308), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label308), 5, 0); + + label309 = gtk_label_new ("Current max.:"); + gtk_widget_show (label309); + gtk_table_attach (GTK_TABLE (table301), label309, 3, 4, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label309), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label309), 5, 0); + + label310 = gtk_label_new ("Voltage min.:"); + gtk_widget_show (label310); + gtk_table_attach (GTK_TABLE (table301), label310, 3, 4, 4, 5, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label310), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label310), 5, 0); + + hseparator301 = gtk_hseparator_new (); + gtk_widget_show (hseparator301); + gtk_table_attach (GTK_TABLE (table301), hseparator301, 0, 5, 5, 6, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0); + + spinbutton302_adj = gtk_adjustment_new (0, 0, 63, 1, 10, 10); + spinbutton302 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton302_adj), 1, 0); + gtk_widget_show (spinbutton302); + gtk_table_attach (GTK_TABLE (table301), spinbutton302, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + spinbutton307_adj = gtk_adjustment_new (0, 0, 255, 1, 10, 10); + spinbutton307 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton307_adj), 1, 0); + gtk_widget_show (spinbutton307); + gtk_table_attach (GTK_TABLE (table301), spinbutton307, 4, 5, 1, 2, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + spinbutton303_adj = gtk_adjustment_new (0, 0, 255, 1, 10, 10); + spinbutton303 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton303_adj), 1, 0); + gtk_widget_show (spinbutton303); + gtk_table_attach (GTK_TABLE (table301), spinbutton303, 1, 2, 2, 3, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + spinbutton308_adj = gtk_adjustment_new (0, 0, 1023, 1, 10, 10); + spinbutton308 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton308_adj), 1, 0); + gtk_widget_show (spinbutton308); + gtk_table_attach (GTK_TABLE (table301), spinbutton308, 4, 5, 2, 3, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + spinbutton304_adj = gtk_adjustment_new (0, 0, 255, 1, 10, 10); + spinbutton304 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton304_adj), 1, 0); + gtk_widget_show (spinbutton304); + gtk_table_attach (GTK_TABLE (table301), spinbutton304, 1, 2, 3, 4, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + spinbutton309_adj = gtk_adjustment_new (0, 0, 1023, 1, 10, 10); + spinbutton309 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton309_adj), 1, 0); + gtk_widget_show (spinbutton309); + gtk_table_attach (GTK_TABLE (table301), spinbutton309, 4, 5, 3, 4, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + spinbutton305_adj = gtk_adjustment_new (0, 0, 255, 1, 10, 10); + spinbutton305 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton305_adj), 1, 0); + gtk_widget_show (spinbutton305); + gtk_table_attach (GTK_TABLE (table301), spinbutton305, 1, 2, 4, 5, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + spinbutton310_adj = gtk_adjustment_new (0, 0, 1023, 1, 10, 10); + spinbutton310 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton310_adj), 1, 0); + gtk_widget_show (spinbutton310); + gtk_table_attach (GTK_TABLE (table301), spinbutton310, 4, 5, 4, 5, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + hbuttonbox301 = gtk_hbutton_box_new (); + gtk_widget_show (hbuttonbox301); + gtk_table_attach (GTK_TABLE (table301), hbuttonbox301, 0, 5, 6, 7, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 5); + gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox301), GTK_BUTTONBOX_SPREAD); + + button301 = gtk_button_new_with_mnemonic ("Revert to Defaults"); + gtk_widget_show (button301); + gtk_container_add (GTK_CONTAINER (hbuttonbox301), button301); + GTK_WIDGET_SET_FLAGS (button301, GTK_CAN_DEFAULT); + + button302 = gtk_button_new_with_mnemonic ("Save to EEPROM"); + gtk_widget_show (button302); + gtk_container_add (GTK_CONTAINER (hbuttonbox301), button302); + GTK_WIDGET_SET_FLAGS (button302, GTK_CAN_DEFAULT); + + spinbutton301_adj = gtk_adjustment_new (0, 0, 65535, 1, 10, 10); + spinbutton301 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton301_adj), 1, 0); + gtk_widget_show (spinbutton301); + gtk_table_attach (GTK_TABLE (table301), spinbutton301, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + spinbutton306_adj = gtk_adjustment_new (0, 0, 255, 1, 10, 10); + spinbutton306 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton306_adj), 1, 0); + gtk_widget_show (spinbutton306); + gtk_table_attach (GTK_TABLE (table301), spinbutton306, 4, 5, 0, 1, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + vseparator301 = gtk_vseparator_new (); + gtk_widget_show (vseparator301); + gtk_table_attach (GTK_TABLE (table301), vseparator301, 2, 3, 0, 5, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_FILL), 5, 0); + + label300 = gtk_label_new ("Parameters:"); + gtk_widget_show (label300); + gtk_frame_set_label_widget (GTK_FRAME (frame300), label300); + gtk_label_set_use_markup (GTK_LABEL (label300), TRUE); + gtk_misc_set_padding (GTK_MISC (label300), 5, 0); + + frame100 = gtk_frame_new (NULL); + gtk_widget_show (frame100); + gtk_table_attach (GTK_TABLE (table1), frame100, 0, 1, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_FILL), 0, 0); + gtk_frame_set_shadow_type (GTK_FRAME (frame100), GTK_SHADOW_IN); + + table101 = gtk_table_new (6, 2, FALSE); + gtk_widget_show (table101); + gtk_container_add (GTK_CONTAINER (frame100), table101); + gtk_container_set_border_width (GTK_CONTAINER (table101), 5); + gtk_table_set_row_spacings (GTK_TABLE (table101), 2); + gtk_table_set_col_spacings (GTK_TABLE (table101), 2); + + label101 = gtk_label_new ("I2C Interface:"); + gtk_widget_show (label101); + gtk_table_attach (GTK_TABLE (table101), label101, 0, 1, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label101), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label101), 5, 0); + + combobox101 = gtk_combo_box_new_text (); + gtk_widget_show (combobox101); + gtk_table_attach (GTK_TABLE (table101), combobox101, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (GTK_FILL), 0, 0); + + label102 = gtk_label_new ("I2C Address:"); + gtk_widget_show (label102); + gtk_table_attach (GTK_TABLE (table101), label102, 0, 1, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label102), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label102), 5, 0); + + spinbutton101_adj = gtk_adjustment_new (33, 1, 127, 1, 10, 10); + spinbutton101 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton101_adj), 1, 0); + gtk_widget_show (spinbutton101); + gtk_table_attach (GTK_TABLE (table101), spinbutton101, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + scrolledwindow101 = gtk_scrolled_window_new (NULL, NULL); + gtk_widget_show (scrolledwindow101); + gtk_table_attach (GTK_TABLE (table101), scrolledwindow101, 0, 2, 5, 6, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow101), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow101), GTK_SHADOW_IN); + + textview101 = gtk_text_view_new (); + gtk_widget_show (textview101); + gtk_container_add (GTK_CONTAINER (scrolledwindow101), textview101); + gtk_text_view_set_editable (GTK_TEXT_VIEW (textview101), FALSE); + gtk_text_view_set_accepts_tab (GTK_TEXT_VIEW (textview101), FALSE); + gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (textview101), FALSE); + + hbuttonbox101 = gtk_hbutton_box_new (); + gtk_widget_show (hbuttonbox101); + gtk_table_attach (GTK_TABLE (table101), hbuttonbox101, 0, 2, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0); + gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox101), GTK_BUTTONBOX_SPREAD); + + button101 = gtk_button_new_with_mnemonic ("Connect"); + gtk_widget_show (button101); + gtk_container_add (GTK_CONTAINER (hbuttonbox101), button101); + + button102 = gtk_button_new_with_mnemonic ("Bootloader"); + gtk_widget_show (button102); + gtk_container_add (GTK_CONTAINER (hbuttonbox101), button102); + + button103 = gtk_button_new_with_mnemonic ("Application"); + gtk_widget_show (button103); + gtk_container_add (GTK_CONTAINER (hbuttonbox101), button103); + + hseparator101 = gtk_hseparator_new (); + gtk_widget_show (hseparator101); + gtk_table_attach (GTK_TABLE (table101), hseparator101, 0, 2, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 5); + + hseparator102 = gtk_hseparator_new (); + gtk_widget_show (hseparator102); + gtk_table_attach (GTK_TABLE (table101), hseparator102, 0, 2, 4, 5, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 5); + + label100 = gtk_label_new ("Connection:"); + gtk_widget_show (label100); + gtk_frame_set_label_widget (GTK_FRAME (frame100), label100); + gtk_label_set_use_markup (GTK_LABEL (label100), TRUE); + gtk_misc_set_padding (GTK_MISC (label100), 5, 0); + + g_signal_connect ((gpointer) window, "destroy", + G_CALLBACK (gtk_main_quit), + NULL); + g_signal_connect ((gpointer) window, "delete_event", + G_CALLBACK (gtk_main_quit), + NULL); + g_signal_connect ((gpointer) togglebutton401, "toggled", + G_CALLBACK (on_togglebutton401_toggled), + NULL); + g_signal_connect ((gpointer) button202, "clicked", + G_CALLBACK (on_button202_clicked), + NULL); + g_signal_connect ((gpointer) button204, "clicked", + G_CALLBACK (on_button204_clicked), + NULL); + g_signal_connect ((gpointer) button203, "clicked", + G_CALLBACK (on_button203_clicked), + NULL); + g_signal_connect ((gpointer) button201, "clicked", + G_CALLBACK (on_button201_clicked), + NULL); + g_signal_connect ((gpointer) button207, "clicked", + G_CALLBACK (on_button207_clicked), + NULL); + g_signal_connect ((gpointer) button208, "clicked", + G_CALLBACK (on_button208_clicked), + NULL); + g_signal_connect ((gpointer) button205, "clicked", + G_CALLBACK (on_button205_clicked), + NULL); + g_signal_connect ((gpointer) button206, "clicked", + G_CALLBACK (on_button206_clicked), + NULL); + g_signal_connect ((gpointer) spinbutton302, "value_changed", + G_CALLBACK (on_parameter_value_changed), + NULL); + g_signal_connect ((gpointer) spinbutton307, "value_changed", + G_CALLBACK (on_parameter_value_changed), + NULL); + g_signal_connect ((gpointer) spinbutton303, "value_changed", + G_CALLBACK (on_parameter_value_changed), + NULL); + g_signal_connect ((gpointer) spinbutton308, "value_changed", + G_CALLBACK (on_parameter_value_changed), + NULL); + g_signal_connect ((gpointer) spinbutton304, "value_changed", + G_CALLBACK (on_parameter_value_changed), + NULL); + g_signal_connect ((gpointer) spinbutton309, "value_changed", + G_CALLBACK (on_parameter_value_changed), + NULL); + g_signal_connect ((gpointer) spinbutton305, "value_changed", + G_CALLBACK (on_parameter_value_changed), + NULL); + g_signal_connect ((gpointer) spinbutton310, "value_changed", + G_CALLBACK (on_parameter_value_changed), + NULL); + g_signal_connect ((gpointer) button301, "clicked", + G_CALLBACK (on_button301_clicked), + NULL); + g_signal_connect ((gpointer) button302, "clicked", + G_CALLBACK (on_button302_clicked), + NULL); + g_signal_connect ((gpointer) spinbutton301, "value_changed", + G_CALLBACK (on_parameter_value_changed), + NULL); + g_signal_connect ((gpointer) spinbutton306, "value_changed", + G_CALLBACK (on_parameter_value_changed), + NULL); + g_signal_connect ((gpointer) spinbutton101, "value_changed", + G_CALLBACK (on_spinbutton101_value_changed), + NULL); + g_signal_connect ((gpointer) button101, "clicked", + G_CALLBACK (on_button101_clicked), + NULL); + g_signal_connect ((gpointer) button102, "clicked", + G_CALLBACK (on_button102_clicked), + NULL); + g_signal_connect ((gpointer) button103, "clicked", + G_CALLBACK (on_button103_clicked), + NULL); + return window; +} diff --git a/gtk2-gui.h b/gtk2-gui.h new file mode 100644 index 0000000..e723d07 --- /dev/null +++ b/gtk2-gui.h @@ -0,0 +1,11 @@ +#ifndef _GTK2_GUI_H_ +#define _GTK2_GUI_H_ + +#include + +GtkWidget* gui_create_window(void); + +void gui_add_i2c_interface(const char *path); +void gui_flush_i2c_interfaces(void); + +#endif /* _GTK2_GUI_H_ */ diff --git a/i2c.c b/i2c.c new file mode 100644 index 0000000..798b443 --- /dev/null +++ b/i2c.c @@ -0,0 +1,270 @@ +/*************************************************************************** + * Copyright (C) 09/2007 by Olaf Rempel * + * razzor@kopf-tisch.de * + * * + * 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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "gtk2-gui.h" +#include "i2c.h" + +/* TWIBOOT commands */ +#define CMD_GET_INFO 0x10 +#define CMD_GET_SIGNATURE 0x11 +#define CMD_WRITE_FLASH 0x12 +#define CMD_READ_FLASH 0x13 +#define CMD_WRITE_EEPROM 0x14 +#define CMD_READ_EEPROM 0x15 +#define CMD_BOOT_APPLICATION 0x1F + +#define COOKIE 0x4711 +#define WRITE_COOKIE COOKIE + +/* blctrl commands */ +//#define CMD_GET_INFO 0x10 +#define CMD_SET_PWM 0x21 +#define CMD_GET_STATUS 0x22 +#define CMD_SET_PARAM 0x23 +#define CMD_GET_PARAM 0x24 +#define CMD_BOOT_LOADER 0x2F + +static int i2c_connected; + +void i2c_enumerate_interfaces(void) +{ + gui_flush_i2c_interfaces(); + + char path[64]; + strcpy(path, "/dev"); + + DIR *dp = opendir(path); + if (dp == NULL) { + perror("opendir()"); + return; + } + + char *ptr = path + strlen(path); + *ptr = '/'; + + struct dirent *dentry; + while ((dentry = readdir(dp)) != NULL) { + if (!strcmp(dentry->d_name, ".")) + continue; + + if (!strcmp(dentry->d_name, "..")) + continue; + + if (strncmp(dentry->d_name, "i2c-", 4) != 0) + continue; + + strcpy(ptr +1, dentry->d_name); + + struct stat statbuf; + if (stat(path, &statbuf) == -1) { + perror("stat()"); + continue; + } + + if (!S_ISCHR(statbuf.st_mode)) + continue; + + /* TODO: check permissions */ + + gui_add_i2c_interface(path); + } + closedir(dp); +} + +void i2c_close(int fd) +{ + i2c_connected = 0; + i2c_close(fd); +} + +int i2c_open(const char *path) +{ + int fd = open(path, O_RDWR); + if (fd < 0) { + perror("open()"); + return -1; + } + + unsigned long funcs; + if (ioctl(fd, I2C_FUNCS, &funcs)) { + perror("ioctl(I2C_FUNCS)"); + i2c_close(fd); + return -1; + } + + if (!(funcs & I2C_FUNC_I2C)) { + fprintf(stderr, "I2C_FUNC_I2C not supported!\n"); + i2c_close(fd); + return -1; + } + + i2c_connected = 1; + return fd; +} + +void i2c_set_address(int fd, int address) +{ + if (ioctl(fd, I2C_SLAVE, address) < 0) { + perror("ioctl(I2C_SLAVE)"); + i2c_close(fd); + } +} + +int i2c_isconnected(void) +{ + return i2c_connected; +} + + +void i2c_cmd_bootloader(int fd) +{ + char cmd[] = { CMD_BOOT_LOADER }; + write(fd, cmd, 1); +} + +void i2c_cmd_application(int fd) +{ + char cmd[] = { CMD_BOOT_APPLICATION }; + write(fd, cmd, 1); +} + +void i2c_cmd_getinfo(int fd, char *buf, int size) +{ + char cmd[] = { CMD_GET_INFO }; + write(fd, cmd, 1); + + size = MIN(16, size); + memset(buf, 0, size); + read(fd, buf, size); + + int i; + for (i = 0; i < size; i++) + buf[i] &= ~0x80; +} + +void i2c_cmd_getsignature(int fd, unsigned char *buf, int size) +{ + char cmd[] = { CMD_GET_SIGNATURE }; + write(fd, cmd, 1); + + memset(buf, 0, size); + read(fd, buf, MIN(4, size)); +} + +void i2c_cmd_getparameters(int fd, struct blmc_parameter *blmc) +{ + char cmd[] = { CMD_GET_PARAM }; + write(fd, cmd, 1); + + memset(blmc, 0, sizeof(struct blmc_parameter)); + read(fd, blmc, sizeof(struct blmc_parameter)); +} + +void i2c_cmd_setparameters(int fd, struct blmc_parameter *blmc, int persistent) +{ + char cmd[sizeof(struct blmc_parameter) +1]; + cmd[0] = CMD_SET_PARAM; + memcpy(cmd +1, blmc, sizeof(struct blmc_parameter)); + + write(fd, cmd, sizeof(struct blmc_parameter) + (persistent ? 1 : -1)); +} + +int i2c_write_flash(int fd, const char *filename, void (*progress_cb)(double progress)) +{ + int fd_file = open(filename, O_RDONLY); + if (fd_file < 0) { + perror("open()"); + return -1; + } + + struct stat statbuf; + if (fstat(fd_file, &statbuf) == -1) { + perror("stat()"); + close(fd_file); + return -1; + } + + int file_size = statbuf.st_size; + int address = 0, progress = 0; + + while (1) { + progress_cb((double)progress / (double)file_size); + + char buf[64 +5], buf2[64 + 5]; + int len = read(fd_file, buf +5, sizeof(buf) -5); + if (len <= 0) + break; + + else if (len < 64) + memset(buf + len +5, 0xFF, sizeof(buf) - len -5); + + buf[0] = CMD_WRITE_FLASH; + buf[1] = (address >> 8) & 0xFF; + buf[2] = address & 0xFF; + buf[3] = (COOKIE >> 8) & 0xFF; + buf[4] = COOKIE & 0xFF; + write(fd, buf, sizeof(buf)); + + buf[0] = CMD_READ_FLASH; + buf[1] = (address >> 8) & 0xFF; + buf[2] = address & 0xFF; + write(fd, buf, 3); + read(fd, buf2, 64); + + address += 64; + progress += len; + + if (memcmp(buf +5, buf2, 64) != 0) { + progress = -progress; + break; + } + } + + close(fd_file); + return progress; +} + +void i2c_cmd_setpwm(int fd, int pwm) +{ + char cmd[] = { CMD_SET_PWM, pwm }; + write(fd, cmd, 2); +} + +void i2c_cmd_getstatus(int fd, struct blmc_status *status) +{ + char cmd[] = { CMD_GET_STATUS }; + write(fd, cmd, 1); + + memset(status, 0, sizeof(struct blmc_status)); + read(fd, status, sizeof(struct blmc_status)); +} diff --git a/i2c.h b/i2c.h new file mode 100644 index 0000000..d3c8cc7 --- /dev/null +++ b/i2c.h @@ -0,0 +1,54 @@ +#ifndef _I2C_H_ +#define _I2C_H_ + +#include + +void i2c_enumerate_interfaces(void); +void i2c_close(int fd); +int i2c_open(const char *path); +void i2c_set_address(int fd, int address); +int i2c_isconnected(void); + +void i2c_cmd_bootloader(int fd); +void i2c_cmd_application(int fd); +void i2c_cmd_getinfo(int fd, char *buf, int size); +void i2c_cmd_getsignature(int fd, unsigned char *buf, int size); + +struct blmc_parameter { + uint16_t spinup_ticks; + + uint8_t spinup_tick; + uint8_t spinup_step; + + uint8_t spinup_wait; + uint8_t spinup_pwm; + + uint8_t pwm_min; + uint8_t pwm_max; + + uint16_t current_limit; + uint16_t current_max; + + uint16_t voltage_min; + + uint16_t crc16; +}; + +void i2c_cmd_getparameters(int fd, struct blmc_parameter *blmc); +void i2c_cmd_setparameters(int fd, struct blmc_parameter *blmc, int persistent); + +int i2c_write_flash(int fd, const char *filename, void (*progress_cb)(double progress)); + +void i2c_cmd_setpwm(int fd, int pwm); + +struct blmc_status { + uint8_t pwm_real; + uint8_t pwm; + uint16_t rpm; + uint16_t current; + uint16_t voltage; +}; + +void i2c_cmd_getstatus(int fd, struct blmc_status *status); + +#endif /* _I2C_H_ */