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

📄 scope_trig.c

📁 Source code for an Numeric Cmputer
💻 C
📖 第 1 页 / 共 2 页
字号:
/** This file, 'halsc_trig.c', contains the portion of halscope    that deals with triggering*//** Copyright (C) 2003 John Kasunich                       <jmkasunich AT users DOT sourceforge DOT net>*//** This program is free software; you can redistribute it and/or    modify it under the terms of version 2.1 of the GNU General    Public License as published by the Free Software Foundation.    This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public    License along with this library; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111 USA    THE AUTHORS OF THIS LIBRARY ACCEPT ABSOLUTELY NO LIABILITY FOR    ANY HARM OR LOSS RESULTING FROM ITS USE.  IT IS _EXTREMELY_ UNWISE    TO RELY ON SOFTWARE ALONE FOR SAFETY.  Any machinery capable of    harming persons must have provisions for completely removing power    from all motors, etc, before persons enter any danger area.  All    machinery must be designed to comply with local and national safety    codes, and the authors of this software can not, and do not, take    any responsibility for such compliance.    This code was written as part of the EMC HAL project.  For more    information, go to www.linuxcnc.org.*/#ifndef ULAPI#error This is a user mode component only!#endif#include <sys/types.h>#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <string.h>#include "rtapi.h"		/* RTAPI realtime OS API */#include "hal.h"		/* HAL public API decls */#include "../hal_priv.h"	/* private HAL decls */#include <gtk/gtk.h>#include "miscgtk.h"		/* generic GTK stuff */#include "scope_usr.h"		/* scope related declarations */#define BUFLEN 80		/* length for sprintf buffers *//************************************************************************                  GLOBAL VARIABLES DECLARATIONS                       *************************************************************************/#define TRIG_LEVEL_RESOLUTION 100.0#define TRIG_POS_RESOLUTION 100.0/************************************************************************                  LOCAL FUNCTION PROTOTYPES                           *************************************************************************/static void init_trigger_mode_window(void);static void init_trigger_info_window(void);static void trigger_selection_made(GtkWidget * clist, gint row, gint column,    GdkEventButton * event, dialog_generic_t * dptr);static void dialog_select_trigger_source(void);/* callback functions */static void auto_button_clicked(GtkWidget * widget, gpointer * gdata);static void normal_button_clicked(GtkWidget * widget, gpointer * gdata);static void force_button_clicked(GtkWidget * widget, gpointer * gdata);static void source_button_clicked(GtkWidget * widget, gpointer * gdata);static void edge_button_clicked(GtkWidget * widget, gpointer * gdata);static void level_changed(GtkAdjustment * adj, gpointer gdata);static void pos_changed(GtkAdjustment * adj, gpointer gdata);/* helper functions *//************************************************************************                       PUBLIC FUNCTIONS                               *************************************************************************/void init_trig(void){    scope_trig_t *trig;    /* stop sampling */    ctrl_shm->state = IDLE;    /* make a pointer to the trig structure */    trig = &(ctrl_usr->trig);    /* init non-zero members of the trigger structure */    /* set up the windows */    init_trigger_mode_window();    init_trigger_info_window();}void refresh_trigger(void){    scope_trig_t *trig;    scope_chan_t *chan;    gchar buf[BUFLEN + 1];    float fp_level;    trig = &(ctrl_usr->trig);    /* display edge */    if (ctrl_shm->trig_edge == 0) {	snprintf(buf, BUFLEN, "Falling");    } else {	snprintf(buf, BUFLEN, "Rising");    }    gtk_label_set_text_if(trig->edge_label, buf);    /* display source */    if ((ctrl_shm->trig_chan < 1) || (ctrl_shm->trig_chan > 16)) {	/* no source */	ctrl_shm->trig_chan = 0;	gtk_label_set_text_if(trig->source_label, "Source\nNone");	gtk_label_set_text_if(trig->level_label, "  ----  ");	/* nothing left to do */	return;    }    snprintf(buf, BUFLEN, "Source\nChan %2d", ctrl_shm->trig_chan);    gtk_label_set_text_if(trig->source_label, buf);    /* point to source channel data */    chan = &(ctrl_usr->chan[ctrl_shm->trig_chan - 1]);    /* calculate a preliminary value for trigger level */    fp_level =	chan->scale * ((chan->position - trig->level) * 10) -	chan->vert_offset;    /* apply type specific tweaks to trigger level */    switch (chan->data_type) {    case HAL_FLOAT:	ctrl_shm->trig_level.d_float = fp_level;    case HAL_S8:	if (fp_level > 127.0) {	    fp_level = 127.0;	}	if (fp_level < -128.0) {	    fp_level = -128.0;	}	ctrl_shm->trig_level.d_s8 = fp_level;	break;    case HAL_U8:	if (fp_level > 255.0) {	    fp_level = 255.0;	}	if (fp_level < 0.0) {	    fp_level = 0.0;	}	ctrl_shm->trig_level.d_u8 = fp_level;	break;    case HAL_S16:	if (fp_level > 32767.0) {	    fp_level = 32767.0;	}	if (fp_level < -32768.0) {	    fp_level = -32768.0;	}	ctrl_shm->trig_level.d_s16 = fp_level;	break;    case HAL_U16:	if (fp_level > 65535.0) {	    fp_level = 65535.0;	}	if (fp_level < 0.0) {	    fp_level = 0.0;	}	ctrl_shm->trig_level.d_u16 = fp_level;	break;    case HAL_S32:	if (fp_level > 2147483647.0) {	    fp_level = 2147483647.0;	}	if (fp_level < -2147483648.0) {	    fp_level = -2147483648.0;	}	ctrl_shm->trig_level.d_s32 = fp_level;	break;    case HAL_U32:	if (fp_level > 4294967295.0) {	    fp_level = 4294967295.0;	}	if (fp_level < 0.0) {	    fp_level = 0.0;	}	ctrl_shm->trig_level.d_u32 = fp_level;	break;    default:	break;    }    if (chan->data_type == HAL_BIT) {	snprintf(buf, BUFLEN, "  ----  ");    } else {	format_signal_value(buf, BUFLEN, fp_level);    }    gtk_label_set_text_if(trig->level_label, buf);}void write_trig_config(FILE *fp){    scope_trig_t *trig;        trig = &(ctrl_usr->trig);    if (ctrl_shm->trig_chan > 0) {	fprintf(fp, "TSOURCE %d\n", ctrl_shm->trig_chan);	fprintf(fp, "TLEVEL %f\n", trig->level);	fprintf(fp, "TPOS %f\n", trig->position);	fprintf(fp, "TPOLAR %d\n", ctrl_shm->trig_edge);    }    fprintf(fp, "TMODE %d\n", ctrl_shm->auto_trig);}/************************************************************************                       LOCAL FUNCTIONS                                *************************************************************************/static void init_trigger_mode_window(void){    scope_trig_t *trig;    /* make a pointer to the trig structure */    trig = &(ctrl_usr->trig);    /* set initial state to normal */    ctrl_shm->auto_trig = 0;    /* define the radio buttons */    trig->normal_button = gtk_radio_button_new_with_label(NULL, "Normal");    trig->auto_button =	gtk_radio_button_new_with_label(gtk_radio_button_group	(GTK_RADIO_BUTTON(trig->normal_button)), "Auto");    /* and a regular button */    trig->force_button = gtk_button_new_with_label("Force");    /* now put them into the box */    gtk_box_pack_start(GTK_BOX(ctrl_usr->trig_mode_win),	trig->normal_button, FALSE, FALSE, 0);    gtk_box_pack_start(GTK_BOX(ctrl_usr->trig_mode_win),	trig->auto_button, FALSE, FALSE, 0);    gtk_box_pack_start(GTK_BOX(ctrl_usr->trig_info_win),	trig->force_button, FALSE, FALSE, 0);    /* hook callbacks to buttons */    gtk_signal_connect(GTK_OBJECT(trig->normal_button), "clicked",	GTK_SIGNAL_FUNC(normal_button_clicked), NULL);    gtk_signal_connect(GTK_OBJECT(trig->auto_button), "clicked",	GTK_SIGNAL_FUNC(auto_button_clicked), NULL);    gtk_signal_connect(GTK_OBJECT(trig->force_button), "clicked",	GTK_SIGNAL_FUNC(force_button_clicked), NULL);    /* and make them visible */    gtk_widget_show(trig->normal_button);    gtk_widget_show(trig->auto_button);    gtk_widget_show(trig->force_button);}static void init_trigger_info_window(void){    scope_trig_t *trig;    GtkWidget *hbox, *vbox;    /* make a pointer to the trigger structure */    trig = &(ctrl_usr->trig);    /* box for the two sliders */    hbox =	gtk_hbox_new_in_box(TRUE, 0, 0, ctrl_usr->trig_info_win, TRUE, TRUE,	0);    /* box for the level slider */    vbox = gtk_vbox_new_in_box(FALSE, 0, 0, hbox, TRUE, TRUE, 0);    gtk_label_new_in_box("Level", vbox, FALSE, FALSE, 0);    trig->level_adj =	gtk_adjustment_new(TRIG_LEVEL_RESOLUTION / 2, 0,	TRIG_LEVEL_RESOLUTION, 1, 1, 0);    trig->level_slider = gtk_vscale_new(GTK_ADJUSTMENT(trig->level_adj));    gtk_scale_set_digits(GTK_SCALE(trig->level_slider), 0);    gtk_scale_set_draw_value(GTK_SCALE(trig->level_slider), FALSE);    gtk_box_pack_start(GTK_BOX(vbox), trig->level_slider, TRUE, TRUE, 0);    /* set initial trigger level */    trig->level =	(GTK_ADJUSTMENT(trig->level_adj))->value / TRIG_LEVEL_RESOLUTION;    /* connect the slider to a function that re-sets the trigger level */    gtk_signal_connect(GTK_OBJECT(trig->level_adj), "value_changed",	GTK_SIGNAL_FUNC(level_changed), NULL);    gtk_widget_show(trig->level_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);    trig->pos_adj =	gtk_adjustment_new(TRIG_POS_RESOLUTION / 2, 0, TRIG_POS_RESOLUTION, 1,	1, 0);    trig->pos_slider = gtk_vscale_new(GTK_ADJUSTMENT(trig->pos_adj));    gtk_scale_set_digits(GTK_SCALE(trig->pos_slider), 0);    gtk_scale_set_draw_value(GTK_SCALE(trig->pos_slider), FALSE);    gtk_box_pack_start(GTK_BOX(vbox), trig->pos_slider, TRUE, TRUE, 0);    /* set initial trigger position */

⌨️ 快捷键说明

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