📄 meter.c
字号:
gtk_clist_clear(GTK_CLIST(probe->lists[2])); rtapi_mutex_get(&(hal_data->mutex)); next = hal_data->pin_list_ptr; row = 0; while (next != 0) { pin = SHMPTR(next); name = pin->name; gtk_clist_append(GTK_CLIST(probe->lists[0]), &name); /* if we have a pin selected, and it matches the current one, mark this row) */ if ((probe->listnum == 0) && (probe->pin == pin)) { gtk_clist_select_row(GTK_CLIST(probe->lists[0]), row, 0); /* Get the text from the list */ gtk_clist_get_text(GTK_CLIST(probe->lists[0]), row, 0, &(probe->pickname)); } next = pin->next_ptr; row++; } next = hal_data->sig_list_ptr; row = 0; while (next != 0) { sig = SHMPTR(next); name = sig->name; gtk_clist_append(GTK_CLIST(probe->lists[1]), &name); /* if we have a signal selected, and it matches the current one, mark this row) */ if ((probe->listnum == 1) && (probe->sig == sig)) { gtk_clist_select_row(GTK_CLIST(probe->lists[1]), row, 0); /* Get the text from the list */ gtk_clist_get_text(GTK_CLIST(probe->lists[1]), row, 0, &(probe->pickname)); } next = sig->next_ptr; row++; } next = hal_data->param_list_ptr; row = 0; while (next != 0) { param = SHMPTR(next); name = param->name; gtk_clist_append(GTK_CLIST(probe->lists[2]), &name); /* if we have a param selected, and it matches the current one, mark this row) */ if ((probe->listnum == 2) && (probe->param == param)) { gtk_clist_select_row(GTK_CLIST(probe->lists[2]), row, 0); /* Get the text from the list */ gtk_clist_get_text(GTK_CLIST(probe->lists[2]), row, 0, &(probe->pickname)); } next = param->next_ptr; row++; } rtapi_mutex_give(&(hal_data->mutex)); gtk_widget_show_all(probe->window);}static void quit(int sig){ gtk_main_quit();}static void exit_from_hal(void){ hal_exit(comp_id);}/* this function refreshes the value display */static int refresh_value(gpointer data){ meter_t *meter; probe_t *probe; char *value_str, *name_str; hal_sig_t *sig; meter = (meter_t *) data; probe = meter->probe; if (probe->pin != NULL) { if (probe->pin->name[0] == '\0') { /* pin has been deleted, can't display it any more */ probe->pin = NULL; return 1; } name_str = probe->pin->name; if (probe->pin->signal == 0) { /* pin is unlinked, get data from dummysig */ value_str = data_value(probe->pin->type, &(probe->pin->dummysig)); } else { /* pin is linked to a signal */ sig = SHMPTR(probe->pin->signal); value_str = data_value(probe->pin->type, SHMPTR(sig->data_ptr)); } } else if (probe->sig != NULL) { if (probe->sig->name[0] == '\0') { /* signal has been deleted, can't display it any more */ probe->sig = NULL; return 1; } name_str = probe->sig->name; value_str = data_value(probe->sig->type, SHMPTR(probe->sig->data_ptr)); } else if (probe->param != NULL) { if (probe->param->name[0] == '\0') { /* parameter has been deleted, can't display it any more */ probe->param = NULL; return 1; } name_str = probe->param->name; value_str = data_value(probe->param->type, SHMPTR(probe->param->data_ptr)); } else { name_str = "-----"; value_str = "---"; } gtk_label_set_text(GTK_LABEL(meter->value_label), value_str); if (!small) { gtk_label_set_text(GTK_LABEL(meter->name_label), name_str); } return 1;}/* Switch function to return var value for the print_*_list functions */static char *data_value(int type, void *valptr){ char *value_str; static char buf[25]; switch (type) { case HAL_BIT: if (*((char *) valptr) == 0) value_str = "FALSE"; else value_str = "TRUE"; break; case HAL_FLOAT: snprintf(buf, 24, "%12.5e", *((float *) valptr)); value_str = buf; break; case HAL_S8: snprintf(buf, 24, "%4d", *((signed char *) valptr)); value_str = buf; break; case HAL_U8: snprintf(buf, 24, "%3u (%02X)", *((unsigned char *) valptr), *((unsigned char *) valptr)); value_str = buf; break; case HAL_S16: snprintf(buf, 24, "%6d", *((signed short *) valptr)); value_str = buf; break; case HAL_U16: snprintf(buf, 24, "%5u (%04X)", *((unsigned short *) valptr), *((unsigned short *) valptr)); value_str = buf; break; case HAL_S32: snprintf(buf, 24, "%10ld", *((signed long *) valptr)); value_str = buf; break; case HAL_U32: snprintf(buf, 24, "%10lu (%08lX)", *((unsigned long *) valptr), *((unsigned long *) valptr)); value_str = buf; break; default: /* Shouldn't get here, but just in case... */ value_str = ""; } return value_str;}static void create_probe_window(probe_t * probe){ GtkWidget *vbox, *hbox, *notebk; GtkWidget *button_OK, *button_apply, *button_cancel; GtkWidget *scrolled_window; gchar *tab_label_text[3]; gint n; /* create window, set it's size */ probe->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_usize(GTK_WIDGET(probe->window), -2, 400); /* allow user to grow but not shrink the window */ gtk_window_set_policy(GTK_WINDOW(probe->window), FALSE, TRUE, FALSE); /* set set_probe window title */ gtk_window_set_title(GTK_WINDOW(probe->window), probe->probe_name); /* a vbox to hold everything */ vbox = gtk_vbox_new(FALSE, 3); gtk_container_set_border_width(GTK_CONTAINER(vbox), 2); /* add the vbox to the window */ gtk_container_add(GTK_CONTAINER(probe->window), vbox); gtk_widget_show(vbox); /* create a notebook to hold pin, signal, and parameter lists */ notebk = gtk_notebook_new(); /* remember the notebook so we can change the pages later */ probe->notebook = notebk; /* add the notebook to the window */ gtk_box_pack_start(GTK_BOX(vbox), notebk, TRUE, TRUE, 0); /* set overall notebook parameters */ gtk_notebook_set_homogeneous_tabs(GTK_NOTEBOOK(notebk), TRUE); /* text for tab labels */ tab_label_text[0] = " Pins "; tab_label_text[1] = " Signals "; tab_label_text[2] = " Parameters "; /* loop to create three identical tabs */ for (n = 0; n < 3; n++) { /* Create a scrolled window to display the 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_widget_show(scrolled_window); /* create a list to hold the data */ probe->lists[n] = gtk_clist_new(1); /* set up a callback for when the user selects a line */ gtk_signal_connect(GTK_OBJECT(probe->lists[n]), "select_row", GTK_SIGNAL_FUNC(selection_made), probe); /* It isn't necessary to shadow the border, but it looks nice :) */ gtk_clist_set_shadow_type(GTK_CLIST(probe->lists[n]), GTK_SHADOW_OUT); /* set list for single selection only */ gtk_clist_set_selection_mode(GTK_CLIST(probe->lists[n]), GTK_SELECTION_BROWSE); /* put the list into the scrolled window */ gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW (scrolled_window), probe->lists[n]); gtk_widget_show(probe->lists[n]); /* create a box for the tab label */ hbox = gtk_hbox_new(TRUE, 0); /* create a label for the page */ gtk_label_new_in_box(tab_label_text[n], hbox, TRUE, TRUE, 0); gtk_widget_show(hbox); /* add page to the notebook */ gtk_notebook_append_page(GTK_NOTEBOOK(notebk), scrolled_window, hbox); /* set tab attributes */ gtk_notebook_set_tab_label_packing(GTK_NOTEBOOK(notebk), hbox, TRUE, TRUE, GTK_PACK_START); } gtk_widget_show(notebk); /* an hbox to hold the OK, apply, and cancel buttons */ hbox = gtk_hbox_new_in_box(TRUE, 0, 0, vbox, FALSE, TRUE, 0); /* create the buttons and add them to the hbox */ button_OK = gtk_button_new_with_label("OK"); button_apply = gtk_button_new_with_label("Apply"); button_cancel = gtk_button_new_with_label("Cancel"); gtk_box_pack_start(GTK_BOX(hbox), button_OK, TRUE, TRUE, 4); gtk_box_pack_start(GTK_BOX(hbox), button_apply, TRUE, TRUE, 4); gtk_box_pack_start(GTK_BOX(hbox), button_cancel, TRUE, TRUE, 4); /* activate the new selection if 'OK' button is clicked */ gtk_signal_connect(GTK_OBJECT(button_OK), "clicked", GTK_SIGNAL_FUNC(apply_selection_and_close), probe); /* activate the new selection if 'apply' button is clicked */ gtk_signal_connect(GTK_OBJECT(button_apply), "clicked", GTK_SIGNAL_FUNC(apply_selection), probe); /* make the window disappear if 'cancel' button is clicked */ gtk_signal_connect(GTK_OBJECT(button_cancel), "clicked", GTK_SIGNAL_FUNC(close_selection), probe); gtk_widget_show(button_OK); gtk_widget_show(button_apply); gtk_widget_show(button_cancel); /* set probe->window to NULL if window is destroyed */ gtk_signal_connect(GTK_OBJECT(probe->window), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &(probe->window)); /* done */}static void apply_selection(GtkWidget * widget, gpointer data){ probe_t *probe; /* get a pointer to the probe data structure */ probe = (probe_t *) data; /* discard info about previous item */ probe->pin = NULL; probe->sig = NULL; probe->param = NULL; if (probe->pickname == NULL) { /* not a valid selection */ /* should pop up a message or something here, instead we ignore it */ return; } if (probe->listnum == 0) { /* search the pin list */ probe->pin = halpr_find_pin_by_name(probe->pickname); } else if (probe->listnum == 1) { /* search the signal list */ probe->sig = halpr_find_sig_by_name(probe->pickname); } else if (probe->listnum == 2) { /* search the parameter list */ probe->param = halpr_find_param_by_name(probe->pickname); } /* at this point, the probe structure contain a pointer to the item we wish to display, or all three are NULL if the item doesn't exist */}static void apply_selection_and_close(GtkWidget * widget, gpointer data){ apply_selection(widget, data); close_selection(widget, data);}static void close_selection(GtkWidget * widget, gpointer data){ probe_t *probe; /* get a pointer to the probe data structure */ probe = (probe_t *) data; /* hide the window */ gtk_widget_hide_all(probe->window);}/* If we come here, then the user has selected a row in the list. */static void selection_made(GtkWidget * clist, gint row, gint column, GdkEventButton * event, gpointer data){ probe_t *probe; GdkEventType type; gint n; /* get a pointer to the probe data structure */ probe = (probe_t *) data; if ((event == NULL) || (clist == NULL)) { /* We get spurious events when the lists are populated I don't know why. If either clist or event is null, it's a bad one! */ return; } type = event->type; if (type != 4) { /* We also 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 we get here, it should be a valid selection */ /* figure out which notebook tab it was */ for (n = 0; n < 3; n++) { if (clist == probe->lists[n]) { probe->listnum = n; } } /* Get the text from the list */ gtk_clist_get_text(GTK_CLIST(clist), row, column, &(probe->pickname)); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -