Perhaps a set of buttons are easier to use than a slider for changing the key speed.
struct mybutton mybuttons[100] = { {"CW", 0, 1, 0, 1}, {"CW-REV", 0, 1, 1, 2}, {"10 wpm", 1, 2, 0, 1}, {"15 wpm", 1, 2, 1, 2}, {"20 wpm", 1, 2, 2, 3}, {"25 wpm", 1, 2, 3, 4}, {"30 wpm", 1, 2, 4, 5}, {"35 wpm", 1, 2, 5, 6}, {"40 wpm", 1, 2, 6, 7} } for(int i=0;i<nbutton;i++) { button = gtk_button_new_with_label (mybuttons[i].name); gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (callback), (gpointer) mybuttons[i].name); gtk_table_attach_defaults(GTK_TABLE(table), button, mybuttons[i].left_attach, mybuttons[i].right_attach, mybuttons[i].top_attach, mybuttons[i].bottom_attach); gtk_widget_show (button); }
First you define lots of buttons, their labels and locations. IF one of the buttons is “clicked”, a callback routine is called.
void callback( GtkWidget *widget, gpointer data ) { gint wpm; if(g_str_has_suffix((char *)data, "wpm")) { wpm = atoi( g_strndup((char *) data, 2) ); set_cw_speed(wpm); } }
If the label of a button ends with “wpm”, we have to change the key speed according to the first two digits.
void set_cw_speed(int wpm) { int outputcount = 9; static unsigned char command1[9] = {0xfe, 0xfe, 0x80, 0xe0, 0x14, 0x0c, 0x00, 0x32, 0xfd}; int iii, i100, i10, i1; if(wpm < 6) wpm = 6; if(wpm > 48) wpm = 48; iii = 255 * (wpm - 6) / (48 - 6); i100 = iii / 100; i10 = (iii - 100*i100) / 10; i1 = iii % 10; command1[6] = i100; command1[7] = 16*i10 + i1; write(fd, &command1, outputcount); }
Conversion from “wpm” to a command parameter is necessary. See IC-7410 Keyspeed for the details.