⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scope.c

📁 Source code for an Numeric Cmputer
💻 C
📖 第 1 页 / 共 2 页
字号:
	break;    case SINGLE:	/* 'push' the stop button */	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ctrl_usr->		rm_stop_button), TRUE);	break;    default:	break;    }		//uncomment me to write log files	//write_log_file("scope.log");    refresh_display();}/************************************************************************                      LOCAL INIT FUNCTION CODE                        *************************************************************************/static void init_usr_control_struct(void *shmem){    char *cp;    int n, skip;    hal_comp_t *comp;    /* first clear entire user struct to all zeros */    cp = (char *) ctrl_usr;    for (n = 0; n < sizeof(scope_usr_control_t); n++) {	cp[n] = 0;    }         /* save pointer to shared control structure */    ctrl_shm = shmem;    /* round size of shared struct up to a multiple of 4 for alignment */    skip = (sizeof(scope_shm_control_t) + 3) & ~3;    /* the rest of the shared memory area is the data buffer */    ctrl_usr->buffer = (scope_data_t *) (((char *) (shmem)) + skip);    /* is the realtime component loaded already? */    comp = halpr_find_comp_by_name("scope_rt");    if (comp == NULL) {	/* no, must init shared structure */	init_shared_control_struct();    }    /* init any non-zero fields */    /* set all 16 channels to "no source assigned" */    for (n = 0; n < 16; n++) {	ctrl_usr->chan[n].data_source_type = -1;    }    /* done */}static void init_shared_control_struct(void){    char *cp;    int skip, n;    /* first clear entire struct to all zeros */    cp = (char *) ctrl_shm;    for (n = 0; n < sizeof(scope_shm_control_t); n++) {	cp[n] = 0;    }    /* round size of shared struct up to a multiple of 4 for alignment */    skip = (sizeof(scope_shm_control_t) + 3) & ~3;    /* remainder of shmem area is buffer */    ctrl_shm->buf_len = (SCOPE_SHM_SIZE - skip) / sizeof(scope_data_t);    /* init any non-zero fields */    ctrl_shm->mult = 1;    ctrl_shm->state = IDLE;}/** 'define_scope_windows()' defines the overall layout of the main    window.  It does not connect signals or load content into the    windows - it only creates the windows (actually each "window" is    either an hbox or vbox).  The layout is as shown below:    **************************************************************    *                horiz_info_win              *  run  * trig  *    **********************************************  mode * info  *    *                                        * c *  win  * win   *    *                                        * h *       *       *    *                                        * a *       *       *    *                                        * n *********       *    *                                        *   *       *       *    *                waveform_win            * s *       *       *    *                                        * e *       *       *    *                                        * l * vert  *       *    *                                        *   * info  *       *    *                                        * w * win   *       *    *                                        * i *       *       *    *                                        * n *       *       *    **********************************************       *       *    *               chan_info_win                *       *       *    **************************************************************    Pointers to each of the windows named in the above diagram are    saved in the control structure.  There are a few other boxes    used to build the nested windows, but they are not needed later    so pointers are not saved.*/static void define_scope_windows(void){    GtkWidget *hbox, *vboxleft, *vboxright, *hboxright;    /* create main window, set it's size */    ctrl_usr->main_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);    /* set the minimum size *///    gtk_widget_set_usize(GTK_WIDGET(ctrl_usr->main_win), 500, 350);    /* allow the user to expand it */    gtk_window_set_policy(GTK_WINDOW(ctrl_usr->main_win), FALSE, TRUE, FALSE);    /* set main window title */    gtk_window_set_title(GTK_WINDOW(ctrl_usr->main_win), "HAL Oscilloscope");    /* top level - one big hbox */    hbox = gtk_hbox_new(FALSE, 0);    gtk_container_set_border_width(GTK_CONTAINER(hbox), 0);    /* add the hbox to the main window */    gtk_container_add(GTK_CONTAINER(ctrl_usr->main_win), hbox);    gtk_widget_show(hbox);    /* end of top level */    /* second level of windows */    vboxleft = gtk_vbox_new_in_box(FALSE, 0, 0, hbox, TRUE, TRUE, 0);    hboxright = gtk_hbox_new_in_box(TRUE, 0, 0, hbox, FALSE, FALSE, 0);    /* third level of windows */    /* left side */    ctrl_usr->horiz_info_win =	gtk_vbox_framed_new_in_box("Horizontal", FALSE, 0, 0, vboxleft, FALSE,	FALSE, 1);    /* horizontal row of select buttons */    ctrl_usr->waveform_win =	gtk_vbox_new_in_box(FALSE, 0, 0, vboxleft, TRUE, TRUE, 0);    ctrl_usr->chan_sel_win =	gtk_hbox_new_in_box(TRUE, 0, 0, vboxleft, FALSE, FALSE, 0);    ctrl_usr->chan_info_win =	gtk_hbox_framed_new_in_box("Selected Channel", FALSE, 0, 0, vboxleft,	FALSE, FALSE, 0);    /* right side */    vboxleft = gtk_vbox_new_in_box(FALSE, 0, 0, hboxright, FALSE, FALSE, 0);    vboxright = gtk_vbox_new_in_box(FALSE, 0, 0, hboxright, FALSE, FALSE, 0);    ctrl_usr->run_mode_win =	gtk_vbox_framed_new_in_box("Run Mode", TRUE, 0, 0, vboxleft, FALSE,	FALSE, 0);    ctrl_usr->trig_info_win =	gtk_vbox_framed_new_in_box("Trigger", FALSE, 0, 0, vboxright, TRUE,	TRUE, 0);    ctrl_usr->trig_mode_win =	gtk_vbox_new_in_box(TRUE, 0, 0, ctrl_usr->trig_info_win, FALSE,	FALSE, 0);    ctrl_usr->vert_info_win =	gtk_vbox_framed_new_in_box("Vertical", FALSE, 0, 0, vboxleft, TRUE,	TRUE, 0);    /* all windows are now defined */}static void init_run_mode_window(void){    /* define the radio buttons */    ctrl_usr->rm_stop_button = gtk_radio_button_new_with_label(NULL, "Stop");    ctrl_usr->rm_normal_button =	gtk_radio_button_new_with_label(gtk_radio_button_group	(GTK_RADIO_BUTTON(ctrl_usr->rm_stop_button)), "Normal");    ctrl_usr->rm_single_button =	gtk_radio_button_new_with_label(gtk_radio_button_group	(GTK_RADIO_BUTTON(ctrl_usr->rm_stop_button)), "Single");    ctrl_usr->rm_roll_button =	gtk_radio_button_new_with_label(gtk_radio_button_group	(GTK_RADIO_BUTTON(ctrl_usr->rm_stop_button)), "Roll");    /* now put them into the box */    gtk_box_pack_start(GTK_BOX(ctrl_usr->run_mode_win),	ctrl_usr->rm_normal_button, FALSE, FALSE, 0);    gtk_box_pack_start(GTK_BOX(ctrl_usr->run_mode_win),	ctrl_usr->rm_single_button, FALSE, FALSE, 0);    gtk_box_pack_start(GTK_BOX(ctrl_usr->run_mode_win),	ctrl_usr->rm_roll_button, FALSE, FALSE, 0);    gtk_box_pack_start(GTK_BOX(ctrl_usr->run_mode_win),	ctrl_usr->rm_stop_button, FALSE, FALSE, 0);    /* hook callbacks to buttons */    gtk_signal_connect(GTK_OBJECT(ctrl_usr->rm_normal_button), "clicked",	GTK_SIGNAL_FUNC(rm_normal_button_clicked), NULL);    gtk_signal_connect(GTK_OBJECT(ctrl_usr->rm_single_button), "clicked",	GTK_SIGNAL_FUNC(rm_single_button_clicked), NULL);    gtk_signal_connect(GTK_OBJECT(ctrl_usr->rm_roll_button), "clicked",	GTK_SIGNAL_FUNC(rm_roll_button_clicked), NULL);    gtk_signal_connect(GTK_OBJECT(ctrl_usr->rm_stop_button), "clicked",	GTK_SIGNAL_FUNC(rm_stop_button_clicked), NULL);    /* and make them visible */    gtk_widget_show(ctrl_usr->rm_normal_button);    gtk_widget_show(ctrl_usr->rm_single_button);#if 0 /* FIXME - roll mode not implemented yet */    gtk_widget_show(ctrl_usr->rm_roll_button);#endif    gtk_widget_show(ctrl_usr->rm_stop_button);}/*  FIXME - things not yet finished *//** roll mode - display updates as frequently as possible, not just    when acquisition is complete.  Also need to revisit pretrig    logic - would like to have a full buffer of pretrig samples    until trigger occurs, then start dropping the oldest ones.*//** cursor area = slider for cursor position, two labels, one for    timevalue, one for signal value, three buttons [1] [2] [d]    [1] causes labels to display cursor1 data, slider moves    cursor1, [2] displays cursor 2 data, slider moves cursor2    [d] displays delta data, slider moves both cursors    (can we eliminate sliders and let user click on the waveforms?)*//************************************************************************                    LOCAL CALLBACK FUNCTION CODE                      *************************************************************************/static void exit_from_hal(void){    rtapi_shmem_delete(shm_id, comp_id);    hal_exit(comp_id);}static void main_window_closed(GtkWidget * widget, gpointer * gdata){    quit(0);}static void quit(int sig){    gtk_main_quit();}int set_run_mode(int mode){    GtkWidget *button;    if ( mode == 0 ) {	/* stop mode */	button = ctrl_usr->rm_stop_button;    } else if ( mode == 1 ) {	/* normal mode */	button = ctrl_usr->rm_normal_button;    } else if ( mode == 2 ) {	/* single sweep mode */	button = ctrl_usr->rm_single_button;#if 0 /* FIXME - roll mode not implemented yet */    } else if ( mode == 3 ) {	/* roll mode */	button = ctrl_usr->rm_roll_button;#endif    } else {	/* illegal mode */	return -1;    }    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), 1);    return 0;}static void rm_normal_button_clicked(GtkWidget * widget, gpointer * gdata){    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)) != TRUE) {	/* not pressed, ignore it */	return;    }    ctrl_usr->run_mode = NORMAL;    if (ctrl_shm->state == IDLE) {	start_capture();    }}static void rm_single_button_clicked(GtkWidget * widget, gpointer * gdata){    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)) != TRUE) {	/* not pressed, ignore it */	return;    }    ctrl_usr->run_mode = SINGLE;    if (ctrl_shm->state == IDLE) {	start_capture();    }}static void rm_roll_button_clicked(GtkWidget * widget, gpointer * gdata){    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)) != TRUE) {	/* not pressed, ignore it */	return;    }    printf("Sorry, ROLL mode is not supported yet\n");    /* 'push' the stop button */    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ctrl_usr->rm_stop_button),	TRUE);}static void rm_stop_button_clicked(GtkWidget * widget, gpointer * gdata){    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)) != TRUE) {	/* not pressed, ignore it */	return;    }    if (ctrl_shm->state != IDLE) {	/* RT code is sampling, tell it to stop */	ctrl_shm->state = RESET;    }    ctrl_usr->run_mode = STOP;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -