📄 scope_vert.c
字号:
snprintf(buf, buflen, "%c%10.3e", sign, value); return; } units = &(symbols[4]); while (value < 1.0) { value *= 1000.0; units--; } while (value >= 1000.0) { value /= 1000.0; units++; } decimals = 3; if (value >= 9.999) { decimals--; } if (value >= 99.99) { decimals--; } snprintf(buf, buflen, "%c%0.*f%c", sign, decimals, value, *units);}void write_vert_config(FILE *fp){ int n; scope_vert_t *vert; scope_chan_t *chan; vert = &(ctrl_usr->vert); /* first write disabled channels */ for ( n = 1 ; n <= 16 ; n++ ) { if ( vert->chan_enabled[n-1] != 0 ) { // channel enabled, do it later continue; } chan = &(ctrl_usr->chan[n-1]); if ( chan->name == NULL ) { // no source for this channel, skip it continue; } fprintf(fp, "CHAN %d\n", n); write_chan_config(fp, chan); fprintf(fp, "CHOFF\n"); } /* next write enabled channels */ for ( n = 1 ; n <= 16 ; n++ ) { if ( vert->chan_enabled[n-1] == 0 ) { // channel disabled, skip it continue; } if ( vert->selected == n ) { // channel selected, do it last continue; } chan = &(ctrl_usr->chan[n-1]); if ( chan->name == NULL ) { // no source for this channel, skip it continue; } fprintf(fp, "CHAN %d\n", n); write_chan_config(fp, chan); } /* write selected channel last */ if ((vert->selected < 1) || (vert->selected > 16)) { return; } chan = &(ctrl_usr->chan[vert->selected-1]); fprintf(fp, "CHAN %d\n", vert->selected); write_chan_config(fp, chan);}/************************************************************************ LOCAL FUNCTIONS *************************************************************************/void set_color(GdkColor *color, unsigned char red, unsigned char green, unsigned char blue) { color->red = ((unsigned long) red) << 8; color->green = ((unsigned long) green) << 8; color->blue = ((unsigned long) blue) << 8; color->pixel = ((unsigned long) red) << 16 | ((unsigned long) green) << 8 | ((unsigned long) blue);}extern int normal_colors[16][3], selected_colors[16][3];static void init_chan_sel_window(void){ scope_vert_t *vert; GtkWidget *button; long n; gchar buf[5]; GdkColor c; vert = &(ctrl_usr->vert); for (n = 0; n < 16; n++) { snprintf(buf, 4, "%ld", n + 1); /* define the button */ button = gtk_toggle_button_new_with_label(buf); /* set up colors of the label */ set_color(&c, normal_colors[n][0], normal_colors[n][1], normal_colors[n][2]); gtk_widget_modify_bg(button, GTK_STATE_ACTIVE, &c); gtk_widget_modify_bg(button, GTK_STATE_SELECTED, &c); set_color(&c, selected_colors[n][0], selected_colors[n][1], selected_colors[n][2]); gtk_widget_modify_bg(button, GTK_STATE_PRELIGHT, &c); set_color(&c, 0, 0, 0); gtk_widget_modify_fg(button, GTK_STATE_ACTIVE, &c); gtk_widget_modify_fg(button, GTK_STATE_SELECTED, &c); gtk_widget_modify_fg(button, GTK_STATE_PRELIGHT, &c); /* put it in the window */ gtk_box_pack_start(GTK_BOX(ctrl_usr->chan_sel_win), button, TRUE, TRUE, 0); gtk_widget_show(button); /* hook a callback function to it */ gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(chan_sel_button), (gpointer) n + 1); /* save the button pointer */ vert->chan_sel_buttons[n] = button; }}static void init_chan_info_window(void){ scope_vert_t *vert; vert = &(ctrl_usr->vert); vert->chan_num_label = gtk_label_new_in_box("--", ctrl_usr->chan_info_win, FALSE, FALSE, 5); gtk_label_size_to_fit(GTK_LABEL(vert->chan_num_label), "99"); gtk_vseparator_new_in_box(ctrl_usr->chan_info_win, 3); /* a button to change the source */ vert->source_name_button = gtk_button_new_with_label("------"); gtk_box_pack_start(GTK_BOX(ctrl_usr->chan_info_win), vert->source_name_button, FALSE, FALSE, 3); vert->source_name_label = (GTK_BIN(vert->source_name_button))->child; gtk_label_set_justify(GTK_LABEL(vert->source_name_label), GTK_JUSTIFY_LEFT); gtk_label_size_to_fit(GTK_LABEL(vert->source_name_label), "--longest possible source name--"); /* activate the source selection dialog if button is clicked */ gtk_signal_connect(GTK_OBJECT(vert->source_name_button), "clicked", GTK_SIGNAL_FUNC(change_source_button), NULL); gtk_widget_show(vert->source_name_button); vert->readout_label = gtk_label_new_in_box("", ctrl_usr->chan_info_win, FALSE, FALSE, 0); gtk_misc_set_alignment(GTK_MISC(vert->readout_label), 0, 0); gtk_label_set_justify(GTK_LABEL(vert->readout_label), GTK_JUSTIFY_LEFT); gtk_label_size_to_fit(GTK_LABEL(vert->readout_label), "f(99999.9999) = 99999.9999");}static void init_vert_info_window(void){ scope_vert_t *vert; GtkWidget *hbox, *vbox; GtkWidget *button; vert = &(ctrl_usr->vert); /* box for the two sliders */ hbox = gtk_hbox_new_in_box(TRUE, 0, 0, ctrl_usr->vert_info_win, TRUE, TRUE, 0); /* box for the scale slider */ vbox = gtk_vbox_new_in_box(FALSE, 0, 0, hbox, TRUE, TRUE, 0); gtk_label_new_in_box("Gain", vbox, FALSE, FALSE, 0); vert->scale_adj = gtk_adjustment_new(0, -5, 5, 1, 1, 0); vert->scale_slider = gtk_vscale_new(GTK_ADJUSTMENT(vert->scale_adj)); gtk_scale_set_digits(GTK_SCALE(vert->scale_slider), 0); gtk_scale_set_draw_value(GTK_SCALE(vert->scale_slider), FALSE); gtk_box_pack_start(GTK_BOX(vbox), vert->scale_slider, TRUE, TRUE, 0); /* connect the slider to a function that re-calcs vertical scale */ gtk_signal_connect(GTK_OBJECT(vert->scale_adj), "value_changed", GTK_SIGNAL_FUNC(scale_changed), NULL); gtk_widget_show(vert->scale_slider); /* box for the position slider */ vbox = gtk_vbox_new_in_box(FALSE, 0, 0, hbox, TRUE, TRUE, 0); gtk_label_new_in_box("Pos", vbox, FALSE, FALSE, 0); vert->pos_adj = gtk_adjustment_new(VERT_POS_RESOLUTION / 2, 0, VERT_POS_RESOLUTION, 1, 1, 0); vert->pos_slider = gtk_vscale_new(GTK_ADJUSTMENT(vert->pos_adj)); gtk_scale_set_digits(GTK_SCALE(vert->pos_slider), 0); gtk_scale_set_draw_value(GTK_SCALE(vert->pos_slider), FALSE); gtk_box_pack_start(GTK_BOX(vbox), vert->pos_slider, TRUE, TRUE, 0); /* connect the slider to a function that re-calcs vertical pos */ gtk_signal_connect(GTK_OBJECT(vert->pos_adj), "value_changed", GTK_SIGNAL_FUNC(pos_changed), NULL); gtk_widget_show(vert->pos_slider); /* Scale display */ gtk_hseparator_new_in_box(ctrl_usr->vert_info_win, 3); gtk_label_new_in_box("Scale", ctrl_usr->vert_info_win, FALSE, FALSE, 0); vert->scale_label = gtk_label_new_in_box(" ---- ", ctrl_usr->vert_info_win, FALSE, FALSE, 0); /* Offset control */ vert->offset_button = gtk_button_new_with_label("Offset\n----"); vert->offset_label = (GTK_BIN(vert->offset_button))->child; gtk_box_pack_start(GTK_BOX(ctrl_usr->vert_info_win), vert->offset_button, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(vert->offset_button), "clicked", GTK_SIGNAL_FUNC(offset_button), NULL); gtk_widget_show(vert->offset_button); /* a button to turn off the channel */ button = gtk_button_new_with_label("Chan Off"); gtk_box_pack_start(GTK_BOX(ctrl_usr->vert_info_win), button, FALSE, FALSE, 0); /* turn off the channel if button is clicked */ gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(channel_off_button), NULL); gtk_widget_show(button);}static void scale_changed(GtkAdjustment * adj, gpointer gdata){ set_vert_scale(adj->value);}static void pos_changed(GtkAdjustment * adj, gpointer gdata){ set_vert_pos(adj->value / VERT_POS_RESOLUTION);}static void offset_button(GtkWidget * widget, gpointer gdata){ scope_vert_t *vert; scope_chan_t *chan; int chan_num; vert = &(ctrl_usr->vert); chan_num = vert->selected; if ((chan_num < 1) || (chan_num > 16)) { return; } chan = &(ctrl_usr->chan[chan_num - 1]); if (chan->data_type == HAL_BIT) { /* no offset for bits */ return; } if (dialog_set_offset(chan_num)) { if (chan_num == ctrl_shm->trig_chan) { refresh_trigger(); } channel_changed(); request_display_refresh(1); }}static gboolean dialog_set_offset(int chan_num){ scope_vert_t *vert; scope_chan_t *chan; dialog_generic_t dialog; gchar *title, msg[BUFLEN], *cptr; struct offset_data data; GtkWidget *label, *button; float tmp; vert = &(ctrl_usr->vert); chan = &(ctrl_usr->chan[chan_num - 1]); title = "Set Offset"; snprintf(msg, BUFLEN - 1, "Set the vertical offset\n" "for channel %d.", chan_num); /* create dialog window, disable resizing */ dialog.retval = 0; dialog.window = gtk_dialog_new(); dialog.app_data = &data; /* allow user to grow but not shrink the window */ gtk_window_set_policy(GTK_WINDOW(dialog.window), FALSE, TRUE, FALSE); /* window should appear in center of screen */ gtk_window_set_position(GTK_WINDOW(dialog.window), GTK_WIN_POS_CENTER); /* set title */ gtk_window_set_title(GTK_WINDOW(dialog.window), title); /* display message */ label = gtk_label_new(msg); gtk_misc_set_padding(GTK_MISC(label), 15, 5); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog.window)->vbox), label, FALSE, TRUE, 0); /* a separator */ gtk_hseparator_new_in_box(GTK_DIALOG(dialog.window)->vbox, 0); /* a checkbox: AC coupled */ vert->offset_ac = gtk_check_button_new_with_label("AC Coupled"); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog.window)->vbox), vert->offset_ac, FALSE, TRUE, 0); /* react to changes to the checkbox */ gtk_signal_connect(GTK_OBJECT(vert->offset_ac), "toggled", GTK_SIGNAL_FUNC(offset_changed), &data); /* the entry */ vert->offset_entry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog.window)->vbox), vert->offset_entry, FALSE, TRUE, 0); snprintf(data.buf, BUFLEN, "%f", chan->vert_offset); gtk_entry_set_text(GTK_ENTRY(vert->offset_entry), data.buf); gtk_entry_set_max_length(GTK_ENTRY(vert->offset_entry), BUFLEN-1); /* point at first char */ gtk_entry_set_position(GTK_ENTRY(vert->offset_entry), 0); /* select all chars, so if the user types the original value goes away */ gtk_entry_select_region(GTK_ENTRY(vert->offset_entry), 0, strlen(data.buf)); /* make it active so user doesn't have to click on it */ gtk_widget_grab_focus(GTK_WIDGET(vert->offset_entry)); gtk_widget_show(vert->offset_entry); /* capture entry data to the buffer whenever the user types */ gtk_signal_connect(GTK_OBJECT(vert->offset_entry), "changed", GTK_SIGNAL_FUNC(offset_changed), data.buf); /* set up a callback function when the window is destroyed */ gtk_signal_connect(GTK_OBJECT(dialog.window), "destroy", GTK_SIGNAL_FUNC(dialog_generic_destroyed), &dialog); /* make OK and Cancel buttons */ button = gtk_button_new_with_label("OK"); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog.window)->action_area), button, TRUE, TRUE, 4); gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(dialog_generic_button1), &dialog); /* hit the "OK" button if the user hits enter */ gtk_signal_connect(GTK_OBJECT(vert->offset_entry), "activate", GTK_SIGNAL_FUNC(offset_activated), button); button = gtk_button_new_with_label("Cancel"); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog.window)->action_area), button, TRUE, TRUE, 4); gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(dialog_generic_button2), &dialog); /* make window transient and modal */ gtk_window_set_transient_for(GTK_WINDOW(dialog.window), GTK_WINDOW(ctrl_usr->main_win)); gtk_window_set_modal(GTK_WINDOW(dialog.window), TRUE); gtk_widget_show_all(dialog.window); gtk_main(); /* we get here when the user makes a selection, hits Cancel, or closes the window */ if ((dialog.retval == 0) || (dialog.retval == 2)) { /* user either closed dialog, or hit cancel */ return FALSE; } tmp = strtod(data.buf, &cptr); if (cptr == data.buf) { return FALSE; } set_vert_offset(tmp, data.ac_coupled); return TRUE;}static void offset_changed(GtkEditable * editable, struct offset_data *data){ const char *text; /* maybe user hit "ac coupled" button" */ data->ac_coupled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ctrl_usr->vert.offset_ac)); gtk_entry_set_editable(GTK_ENTRY(ctrl_usr->vert.offset_entry), !data->ac_coupled); /* maybe user typed something, save it in the buffer */ text = gtk_entry_get_text(GTK_ENTRY(ctrl_usr->vert.offset_entry)); strncpy(data->buf, text, BUFLEN);}static void offset_activated(GtkEditable * editable, gchar * button){ /* user hit enter, generate a "clicked" event for the OK button */ gtk_button_clicked(GTK_BUTTON(button));}static void chan_sel_button(GtkWidget * widget, gpointer gdata){ long chan_num; int n, count; scope_vert_t *vert; scope_chan_t *chan; char *title, *msg; vert = &(ctrl_usr->vert); chan_num = (long) gdata; chan = &(ctrl_usr->chan[chan_num - 1]); if (ignore_click != 0) { ignore_click = 0; return; } if (vert->chan_enabled[chan_num - 1] == 0 ) { /* channel is disabled, want to enable it */ if (ctrl_shm->state != IDLE) { /* acquisition in progress, must restart it */ prepare_scope_restart(); } count = 0; for (n = 0; n < 16; n++) { if (vert->chan_enabled[n]) { count++; } } if (count >= ctrl_shm->sample_len) { /* max number of channels already enabled */ /* force the button to pop back out */ ignore_click = 1; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE); title = "Too many channels"; msg = "You cannot add another channel.\n\n" "Either turn off one or more channels, or shorten\n" "the record length to allow for more channels"; dialog_generic_msg(ctrl_usr->main_win, title, msg, "OK", NULL, NULL, NULL); return; } if (chan->name == NULL) { /* need to assign a source */ if (dialog_select_source(chan_num) != TRUE) { /* user failed to assign a source */ /* force the button to pop back out */ ignore_click = 1; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE); return; } } vert->chan_enabled[chan_num - 1] = 1; } else { /* channel was already enabled, user wants to select it */ /* button should stay down, so we force it */ ignore_click = 1; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE); } if (vert->selected != chan_num) { /* make chan_num the selected channel */ vert->selected = chan_num;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -