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

📄 scope_horiz.c

📁 Source code for an Numeric Cmputer
💻 C
📖 第 1 页 / 共 3 页
字号:
int set_horiz_pos(double setting){    scope_horiz_t *horiz;    GtkAdjustment *adj;    /* range check setting */    if (( setting < 0.0 ) || ( setting > 1.0 )) {	return -1;    }    /* point to data */    horiz = &(ctrl_usr->horiz);    /* save new value */    horiz->pos_setting = setting;    /* set position slider based on new setting */    adj = GTK_ADJUSTMENT(horiz->pos_adj);    gtk_adjustment_set_value(adj, setting * 1000);    /* refresh other stuff */        refresh_horiz_info();    request_display_refresh(1);    return 0;}/************************************************************************                       LOCAL FUNCTIONS                                *************************************************************************/static void dialog_realtime_not_loaded(void){    gchar *title, *msg;    gint retval;    static int first_time=1;    if(first_time) {        first_time = 0;        system("halcmd loadrt scope_rt");        sleep(1);        return;    }    title = "Realtime component not loaded";    msg = "HALSCOPE uses a realtime component called scope_rt'\n"	"to sample signals for display.  It is not currently loaded\n"        "and attempting to load it automatically failed.  More information\n"        "may be available in the terminal where halscope was started.\n\n"	"Please do one of the following:\n\n"	"Load the component (using 'halcmd loadrt scope_rt'), then click 'OK'\n"	"or\n" "Click 'Quit' to exit HALSCOPE";    retval =	dialog_generic_msg(ctrl_usr->main_win, title, msg, "OK", "Quit",	NULL, NULL);    if ((retval == 0) || (retval == 2)) {	/* user either closed dialog, or hit cancel - end the program */	gtk_main_quit();    }}static void dialog_realtime_not_linked(void){    scope_horiz_t *horiz;    dialog_generic_t dialog;    int next, colwidth, sel_row, n;    float period;    hal_thread_t *thread;    gchar *strs[2];    gchar buf[BUFLEN + 1];    GtkWidget *hbox, *label;    GtkWidget *button;    GtkWidget *buttons[5];    GSList *buttongroup;    GtkWidget *scrolled_window;    gchar *titles[2];    gchar *title, *msg;    horiz = &(ctrl_usr->horiz);    if (horiz->thread_name == NULL) {	title = "Realtime function not linked";	msg = "The HALSCOPE realtime sampling function\n"	    "must be called from a HAL thread in to\n"	    "determine the sampling rate.\n\n"	    "Please do one of the following:\n\n"	    "Select a thread name and multiplier then click 'OK'\n"	    "or\n" "Click 'Quit' to exit HALSCOPE";    } else {	title = "Select Sample Rate";	msg = "Select a thread name and multiplier then click 'OK'\n"	    "or\n" "Click 'Quit' to exit HALSCOPE";    }    /* create dialog window, disable resizing */    dialog.retval = 0;    dialog.window = gtk_dialog_new();    gtk_window_set_policy(GTK_WINDOW(dialog.window), FALSE, FALSE, FALSE);    /* 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);    /* thread name display */    hbox =	gtk_hbox_new_in_box(TRUE, 0, 0, (GTK_DIALOG(dialog.window)->vbox),	FALSE, TRUE, 5);    gtk_label_new_in_box("Thread:", hbox, TRUE, TRUE, 0);    horiz->thread_name_label =	gtk_label_new_in_box("------", hbox, TRUE, TRUE, 0);    /* sample period display */    hbox =	gtk_hbox_new_in_box(TRUE, 0, 0, (GTK_DIALOG(dialog.window)->vbox),	FALSE, TRUE, 5);    gtk_label_new_in_box("Sample Period:", hbox, TRUE, TRUE, 0);    horiz->sample_period_label =	gtk_label_new_in_box("------", hbox, TRUE, TRUE, 0);    /* sample rate display */    hbox =	gtk_hbox_new_in_box(TRUE, 0, 0, (GTK_DIALOG(dialog.window)->vbox),	FALSE, TRUE, 5);    gtk_label_new_in_box("Sample Rate:", hbox, TRUE, TRUE, 0);    horiz->sample_rate_label =	gtk_label_new_in_box("------", hbox, TRUE, TRUE, 0);    /* a separator */    gtk_hseparator_new_in_box(GTK_DIALOG(dialog.window)->vbox, 0);    /* Create a scrolled window to display the thread list */    scrolled_window = gtk_scrolled_window_new(NULL, NULL);    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),	GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog.window)->vbox),	scrolled_window, TRUE, TRUE, 5);    gtk_widget_show(scrolled_window);    /* create a list to hold the threads */    titles[0] = "Thread";    titles[1] = "Period";    horiz->thread_list = gtk_clist_new_with_titles(2, titles);    gtk_clist_column_titles_passive(GTK_CLIST(horiz->thread_list));    /* set up a callback for when the user selects a line */    gtk_signal_connect(GTK_OBJECT(horiz->thread_list), "select_row",	GTK_SIGNAL_FUNC(acquire_selection_made), NULL);    /* It isn't necessary to shadow the border, but it looks nice :) */    gtk_clist_set_shadow_type(GTK_CLIST(horiz->thread_list), GTK_SHADOW_OUT);    /* set list for single selection only */    gtk_clist_set_selection_mode(GTK_CLIST(horiz->thread_list),	GTK_SELECTION_BROWSE);    /* put the list into the scrolled window */    gtk_container_add(GTK_CONTAINER(scrolled_window), horiz->thread_list);    gtk_widget_show(horiz->thread_list);    /* generate list of threads */    gtk_clist_clear(GTK_CLIST(horiz->thread_list));    /* get mutex before traversing list */    rtapi_mutex_get(&(hal_data->mutex));    n = 0;    sel_row = -1;    next = hal_data->thread_list_ptr;    while (next != 0) {	thread = SHMPTR(next);	/* check thread period */	if (thread->period <= 1000000000) {	    /* period is less than 1 sec, add to list */	    period = thread->period / 1000000000.0;	    /* create a string for display */	    format_time_value(buf, BUFLEN, period);	    strs[1] = buf;	    /* get thread name */	    strs[0] = thread->name;	    /* add to list */	    gtk_clist_append(GTK_CLIST(horiz->thread_list), strs);	    if ((horiz->thread_name != NULL)		&& (strcmp(horiz->thread_name, thread->name) == 0)) {		/* found the current thread, remember it's row number */		sel_row = n;		/* and make sure thread_period is correct */		horiz->thread_period_ns = thread->period;	    }	}	n++;	next = thread->next_ptr;    }    rtapi_mutex_give(&(hal_data->mutex));    /* set column widths */    colwidth =	gtk_clist_optimal_column_width(GTK_CLIST(horiz->thread_list), 0);    gtk_clist_set_column_min_width(GTK_CLIST(horiz->thread_list), 0,	(colwidth * 17) / 16);    colwidth =	gtk_clist_optimal_column_width(GTK_CLIST(horiz->thread_list), 1);    gtk_clist_set_column_min_width(GTK_CLIST(horiz->thread_list), 1,	(colwidth * 17) / 16);    /* set up the the layout for the multiplier spinbutton */    hbox =	gtk_hbox_new_in_box(TRUE, 0, 0, (GTK_DIALOG(dialog.window)->vbox),	FALSE, TRUE, 5);    gtk_label_new_in_box("Multiplier:", hbox, FALSE, FALSE, 0);    /* set up the multiplier spinbutton */    horiz->mult_adj =	gtk_adjustment_new(ctrl_shm->mult, 1, ctrl_shm->mult, 1, 1, 0);    horiz->mult_spinbutton =	gtk_spin_button_new(GTK_ADJUSTMENT(horiz->mult_adj), 1, 0);    gtk_box_pack_start(GTK_BOX(hbox), horiz->mult_spinbutton, FALSE, TRUE, 0);    gtk_widget_show(horiz->mult_spinbutton);    /* connect the multiplier spinbutton to a function */    gtk_signal_connect(GTK_OBJECT(horiz->mult_adj), "value_changed",	GTK_SIGNAL_FUNC(mult_changed), NULL);    /* a separator */    gtk_hseparator_new_in_box(GTK_DIALOG(dialog.window)->vbox, 0);    /* box for record length buttons */    gtk_label_new_in_box("Record Length",	GTK_DIALOG(dialog.window)->vbox, TRUE, TRUE, 0);    hbox =	gtk_hbox_new_in_box(TRUE, 0, 0, (GTK_DIALOG(dialog.window)->vbox),	FALSE, TRUE, 5);    /* now define the radio buttons */    snprintf(buf, BUFLEN, "%5d samples (1 channel)", ctrl_shm->buf_len);    buttons[0] = gtk_radio_button_new_with_label(NULL, buf);    buttongroup = gtk_radio_button_group(GTK_RADIO_BUTTON(buttons[0]));    snprintf(buf, BUFLEN, "%5d samples (2 channels)", ctrl_shm->buf_len / 2);    buttons[1] =	gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(buttons	    [0]), buf);    snprintf(buf, BUFLEN, "%5d samples (4 channels)", ctrl_shm->buf_len / 4);    buttons[2] =	gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(buttons	    [0]), buf);    snprintf(buf, BUFLEN, "%5d samples (8 channels)", ctrl_shm->buf_len / 8);    buttons[3] =	gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(buttons	    [0]), buf);    snprintf(buf, BUFLEN, "%5d samples (16 channels)",	ctrl_shm->buf_len / 16);    buttons[4] =	gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(buttons	    [0]), buf);    /* now put them into the box and make visible */    for (n = 0; n < 5; n++) {	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog.window)->vbox),	    buttons[n], FALSE, FALSE, 0);	gtk_widget_show(buttons[n]);    }    /* determine which button should be pressed by default */    if (ctrl_shm->sample_len == 1) {	n = 0;    } else if (ctrl_shm->sample_len == 2) {	n = 1;    } else if (ctrl_shm->sample_len == 4) {	n = 2;    } else if (ctrl_shm->sample_len == 8) {	n = 3;    } else if (ctrl_shm->sample_len == 16) {	n = 4;    } else {	n = 2;	ctrl_shm->sample_len = 4;	ctrl_shm->rec_len = ctrl_shm->buf_len / ctrl_shm->sample_len;    }    /* set the default button */    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(buttons[n]), TRUE);    /* set up callbacks for the buttons */    gtk_signal_connect(GTK_OBJECT(buttons[0]), "clicked",	GTK_SIGNAL_FUNC(rec_len_button), (gpointer) 1);    gtk_signal_connect(GTK_OBJECT(buttons[1]), "clicked",	GTK_SIGNAL_FUNC(rec_len_button), (gpointer) 2);    gtk_signal_connect(GTK_OBJECT(buttons[2]), "clicked",	GTK_SIGNAL_FUNC(rec_len_button), (gpointer) 4);    gtk_signal_connect(GTK_OBJECT(buttons[3]), "clicked",	GTK_SIGNAL_FUNC(rec_len_button), (gpointer) 8);    gtk_signal_connect(GTK_OBJECT(buttons[4]), "clicked",	GTK_SIGNAL_FUNC(rec_len_button), (gpointer) 16);    /* was a thread previously used? */    if (sel_row > -1) {	/* yes, preselect appropriate line */	gtk_clist_select_row(GTK_CLIST(horiz->thread_list), sel_row, 1);    } else {	/* no */	horiz->thread_name = NULL;	ctrl_shm->mult = 1;    }    /* 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);    button = gtk_button_new_with_label("Quit");    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();    /* these items no longer exist - NULL them */    horiz->thread_list = NULL;    horiz->thread_name_label = NULL;    horiz->sample_rate_label = NULL;    horiz->sample_period_label = NULL;    horiz->mult_adj = NULL;    horiz->mult_spinbutton = NULL;    /* we get here when the user hits OK or Cancel or closes the window */    if ((dialog.retval == 0) || (dialog.retval == 2)) {	/* user either closed dialog, or hit cancel - end the program */	gtk_main_quit();    } else {	activate_sample_thread();    }}static void dialog_realtime_not_running(void){    gchar *title, *msg;    gint retval;    title = "Realtime thread(s) not running";    msg = "HALSCOPE uses code in a realtime HAL thread to sample\n"	"signals for display.  The HAL thread(s) are not running.\n"	"Threads are usually started by the application you are\n"	"attempting to run, or you can use the 'halcmd start' command.\n\n"	"Please do one of the following:\n\n"	"Start the threads, then click 'OK'\n"	"or\n" "Click 'Quit' to exit HALSCOPE";    retval =	dialog_generic_msg(ctrl_usr->main_win, title, msg, "OK", "Quit",	NULL, NULL);    if ((retval == 0) || (retval == 2)) {	/* user either closed dialog, or hit cancel - end the program */	gtk_main_quit();    }}static void acquire_popup(GtkWidget * widget, gpointer gdata){    /* 'push' the stop button */    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ctrl_usr->rm_stop_button),	TRUE);    /** This function doesn't directly cause the acquire menu to        pop up.  Instead is disconnects the acquire function from        whatever thread is calling it.  This will result in a        watchdog timeout, and that in turn will pop up the dialog        requesting you to reconnect it.    */    deactivate_sample_thread();    /* presetting the watchdog to 10 avoids the delay that would otherwise       take place while the watchdog times out. */    ctrl_shm->watchdog = 10;    return;}static void acquire_selection_made(GtkWidget * clist, gint row, gint column,    GdkEventButton * event, gpointer gdata){    scope_horiz_t *horiz;    GdkEventType type;    gchar *picked;    if (clist == NULL) {	/* spurious event, ignore it */	return;    }    type = 4;    if (event != NULL) {	type = event->type;    }    if (type != 4) {	/* We get bad callbacks if you drag the mouse across the list with	   the button held down.  They can be distinguished because their	   event type is 3, not 4. */	return;    }    if (column < 0) {	/* this is the initial selection automatically made by GTK */	/* we don't want to act on it */	return;    }    /* must be a valid user selection or preselection */    /* Get the text from the list */    gtk_clist_get_text(GTK_CLIST(clist), row, 0, &picked);    /* set thread */    set_sample_thread_name(picked);    /* get a pointer to the horiz data structure */    horiz = &(ctrl_usr->horiz);    /* set mult spinbutton to (possibly) new value */    gtk_spin_button_set_value(GTK_SPIN_BUTTON(horiz->mult_spinbutton), ctrl_shm->mult);}static int set_sample_thread_name(char *name){    scope_horiz_t *horiz;    hal_thread_t *thread;    long max_mult;    /* get a pointer to the horiz data structure */    horiz = &(ctrl_usr->horiz);    /* look for a new thread that matches name*/    thread = halpr_find_thread_by_name(name);    if (thread == NULL) {	return -1;    }    /* shut down any prior thread */    deactivate_sample_thread();    /* save info about the thread */     horiz->thread_name = thread->name;

⌨️ 快捷键说明

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