/ src / hal / utils / scope_usr.h
scope_usr.h
  1  #ifndef HALSC_USR_H
  2  #define HALSC_USR_H
  3  /** This file, 'scope_usr.h', contains declarations used by
  4      'halscope.c' and other source files to implement the user
  5      space portion of the HAL oscilloscope.  Other declarations
  6      used by both user and realtime code are in 'halsc_shm.h', and
  7      those used only by realtime code are in 'halsc_rt.h'.
  8  */
  9  
 10  /** Copyright (C) 2003 John Kasunich
 11                         <jmkasunich AT users DOT sourceforge DOT net>
 12  */
 13  
 14  /** This program is free software; you can redistribute it and/or
 15      modify it under the terms of version 2 of the GNU General
 16      Public License as published by the Free Software Foundation.
 17      This library is distributed in the hope that it will be useful,
 18      but WITHOUT ANY WARRANTY; without even the implied warranty of
 19      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 20      GNU General Public License for more details.
 21  
 22      You should have received a copy of the GNU General Public
 23      License along with this library; if not, write to the Free Software
 24      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 25  
 26      THE AUTHORS OF THIS LIBRARY ACCEPT ABSOLUTELY NO LIABILITY FOR
 27      ANY HARM OR LOSS RESULTING FROM ITS USE.  IT IS _EXTREMELY_ UNWISE
 28      TO RELY ON SOFTWARE ALONE FOR SAFETY.  Any machinery capable of
 29      harming persons must have provisions for completely removing power
 30      from all motors, etc, before persons enter any danger area.  All
 31      machinery must be designed to comply with local and national safety
 32      codes, and the authors of this software can not, and do not, take
 33      any responsibility for such compliance.
 34  
 35      This code was written as part of the EMC HAL project.  For more
 36      information, go to www.linuxcnc.org.
 37  */
 38  
 39  /* import the shared declarations */
 40  #include "scope_shm.h"
 41  
 42  /***********************************************************************
 43  *                         TYPEDEFS AND DEFINES                         *
 44  ************************************************************************/
 45  
 46  /* this struct holds control data related to horizontal control */
 47  /* it lives in user space (as part of the master control struct */
 48  
 49  typedef struct {
 50      /* general data */
 51      gchar *thread_name;		/* name of thread that does sampling */
 52      long thread_period_ns;	/* period of thread in nano-secs */
 53      long sample_period_ns;	/* sample period in nano-secs */
 54      double sample_period;	/* sample period as a double */
 55      double disp_scale;		/* display scale (sec/div) */
 56      int zoom_setting;		/* setting of zoom slider (1-9) */
 57      double pos_setting;		/* setting of position slider (0.0-1.0) */
 58      long x0;
 59      /* widgets for main window */
 60      GtkWidget *disp_area;
 61      GdkGC *disp_context;
 62      GtkWidget *state_label;
 63      GtkWidget *record_button;
 64      GtkWidget *record_label;
 65      GtkWidget *zoom_slider;
 66      GtkObject *zoom_adj;
 67      GtkWidget *pos_slider;
 68      GtkObject *pos_adj;
 69      GtkWidget *scale_label;
 70      /* widgets for thread selection dialog */
 71      GtkWidget *thread_list;
 72      GtkWidget *thread_name_label;
 73      GtkWidget *sample_rate_label;
 74      GtkWidget *sample_period_label;
 75      GtkObject *mult_adj;
 76      GtkWidget *mult_spinbutton;
 77  } scope_horiz_t;
 78  
 79  /* this struct holds control data related to a single channel */
 80  /* it lives in user space (as part of the master control struct) */
 81  
 82  typedef struct {
 83      int data_source_type;	/* 0 = pin, 1 = signal, 2 = param,
 84  				   -1 = no source assigned */
 85      int data_source;		/* points to pin/param/signal struct */
 86      char *name;			/* name of pin/sig/parameter */
 87      hal_type_t data_type;	/* data type */
 88      int data_len;		/* data length */
 89      double vert_offset;		/* offset to be applied */
 90      int ac_offset;              /* TRUE if the signal should be AC-coupled */
 91      int scale_index;		/* scaling (slider setting) */
 92      int max_index;		/* limits of scale slider */
 93      int min_index;
 94      double scale;		/* scaling (units/div) */
 95      double position;		/* vertical pos (0.0-1.0) */
 96  } scope_chan_t;
 97  
 98  /* this struct holds control data related to vertical control */
 99  /* it lives in user space (as part of the master control struct) */
100  
101  typedef struct {
102      /* general data */
103      int chan_enabled[16];	/* chans user wants to display */
104      int data_offset[16];	/* offset within sample, -1 if no data */
105      int selected;		/* channel user has selected */
106      /* widgets for chan sel window */
107      GtkWidget *chan_sel_buttons[16];
108      /* widgets for chan info window */
109      GtkWidget *chan_num_label;
110      GtkWidget *source_name_label;
111      GtkWidget *source_name_button;
112      /* widgets for vert info window */
113      GtkWidget *scale_slider;
114      GtkObject *scale_adj;
115      GtkWidget *scale_label;
116      GtkWidget *pos_slider;
117      GtkObject *pos_adj;
118      GtkWidget *offset_button;
119      GtkWidget *offset_label;
120      GtkWidget *readout_label;
121      /* widgets for offset dialog */
122      GtkWidget *offset_entry;
123      GtkWidget *offset_ac;
124      /* widgets for source selection dialog */
125      GtkWidget *lists[3];	/* lists for pins, signals, and params */
126      GtkWidget *windows[3];	/* scrolled windows for above lists */
127      GtkAdjustment *adjs[3];	/* scrollbars associated with above */
128  } scope_vert_t;
129  
130  /* this struct holds control data related to triggering */
131  /* it lives in user space (as part of the master control struct) */
132  
133  typedef struct {
134      /* general data */
135      double position;		/* horiz position of trigger (0.0-1.0) */
136      double level;		/* setting of level slider (0.0-1.0) */
137      /* widgets for trigger mode window */
138      GtkWidget *normal_button;
139      GtkWidget *auto_button;
140      GtkWidget *force_button;
141      /* widgets for trigger info window */
142      GtkWidget *source_button;
143      GtkWidget *source_label;
144      GtkWidget *edge_button;
145      GtkWidget *edge_label;
146      GtkWidget *level_slider;
147      GtkObject *level_adj;
148      GtkWidget *level_label;
149      GtkWidget *pos_slider;
150      GtkObject *pos_adj;
151  } scope_trig_t;
152  
153  
154  
155  /* this struct holds control data related to the display */
156  /* it lives in user space (as part of the master control struct) */
157  
158  typedef struct {
159      /* general data */
160      int width;			/* height in pixels */
161      int height;			/* width in pixels */
162      double pixels_per_sample;	/* horizontal scaling */
163      double horiz_offset;		/* offset in pixels */
164      int start_sample;		/* first displayable sample */
165      int end_sample;		/* last displayable sample */
166      /* widgets */
167      GtkWidget *drawing;		/* drawing area for display */
168      GtkTooltips *tip;		/* drawing area for display */
169      /* drawing objects (GDK) */
170      GdkDrawable *win;		/* the window */
171      GdkColormap *map;		/* the colormap for the window */
172      GdkColor color_bg;		/* background color */
173      GdkColor color_grid;	/* the grid color */
174      GdkColor color_normal[16];	/* the color for normal waveforms */
175      GdkColor color_selected[16];	/* the color for selected waveforms */
176      GdkColor color_baseline;    /* The baseline color */
177  
178      GdkGC *context;		/* graphics context for drawing */
179      int selected_part;
180  } scope_disp_t;
181  
182  /* this struct holds data relating to logging */ 
183  
184  typedef enum { INTERLACED, NOT_INTERLACED } log_order_t;
185  typedef enum { OVERWRITE, APPEND } log_append_t;
186  typedef struct {
187  	/* logging preferences */
188  	log_order_t order; /* order that fields are written */
189  	int auto_save; /* save log every trigger */
190  	char *filename, *default_filename;
191  	log_append_t append;
192  	GtkWidget *log_win;
193  	GtkWidget *log_prefs_button;
194  	GtkWidget *log_prefs_label;
195  } scope_log_t;
196  
197  /* this is the master user space control structure */
198  
199  typedef enum { STOP = 0, NORMAL, SINGLE, ROLL } scope_run_mode_t;
200  
201  typedef struct {
202      /* general data */
203      scope_data_t *buffer;	/* ptr to shmem buffer (user mapping) */
204      scope_data_t *disp_buf;	/* ptr to user buffer for display */
205      int samples;		/* number of samples in display buffer */
206      int display_refresh_timer;	/* flag for display refresh */
207      scope_run_mode_t run_mode;	/* current run mode */
208      scope_run_mode_t old_run_mode;	/* run mode to restore*/
209      int pending_restart;        /* nonzero if run mode to be restored */
210      /* top level windows */
211      GtkWidget *main_win;
212      GtkWidget *horiz_info_win;
213      GtkWidget *chan_sel_win;
214      GtkWidget *chan_info_win;
215      GtkWidget *vert_info_win;
216      GtkWidget *waveform_win;
217      GtkWidget *run_mode_win;
218  
219      GtkWidget *trig_info_win;
220      GtkWidget *trig_mode_win;
221      /* top level controls */
222      GtkWidget *rm_normal_button;
223      GtkWidget *rm_single_button;
224      GtkWidget *rm_roll_button;
225      GtkWidget *rm_stop_button;
226      /* subsection control data */
227      scope_chan_t chan[16];	/* channel specific data */
228      scope_horiz_t horiz;	/* horizontal control data */
229      scope_vert_t vert;		/* vertical control data */
230      scope_trig_t trig;		/* triggering data */
231      scope_disp_t disp;		/* display data */
232  	scope_log_t log;  		/* logging preferences */
233  } scope_usr_control_t;
234  
235  /***********************************************************************
236  *                              GLOBALS                                 *
237  ************************************************************************/
238  
239  extern scope_usr_control_t *ctrl_usr;	/* main user control structure */
240  extern scope_shm_control_t *ctrl_shm;	/* shared mem control struct */
241  
242  /***********************************************************************
243  *                          FUNCTIONS                                   *
244  ************************************************************************/
245  
246  void init_horiz(void);
247  void init_vert(void);
248  void init_trig(void);
249  void init_display(void);
250  
251  void handle_watchdog_timeout(void);
252  void refresh_state_info(void);
253  void capture_complete(void);
254  void capture_cont(void);
255  void start_capture(void);
256  void request_display_refresh(int delay);
257  void refresh_display(void);
258  void refresh_trigger(void);
259  void invalidate_channel(int chan);
260  void invalidate_all_channels(void);
261  void channel_changed(void);
262  
263  
264  void format_signal_value(char *buf, int buflen, double value);
265  
266  int read_config_file (char *filename);
267  void write_config_file (char *filename);
268  void write_horiz_config(FILE *fp);
269  void write_vert_config(FILE *fp);
270  void write_trig_config(FILE *fp);
271  void write_log_file (char *filename);
272  void write_sample(FILE *fp, char *label, scope_data_t *dptr, hal_type_t type);
273  
274  /* the following functions set various parameters, they are normally
275     called by the GUI, but can also be called by code reading a file
276     that contains a saved front panel setup
277  */
278  
279  int set_sample_thread(char *name);
280  int set_rec_len(int setting);
281  int set_horiz_mult(int setting);
282  int set_horiz_zoom(int setting);
283  int set_horiz_pos(double setting);
284  int set_active_channel(int chan_num);
285  int set_channel_source(int chan, int type, char *name);
286  int set_channel_off(int chan_num);
287  int set_vert_scale(int setting);
288  void format_scale_value(char *buf, int buflen, double value);
289  int set_vert_pos(double setting);
290  int set_vert_offset(double setting, int ac_coupled);
291  int set_trigger_source(int chan);
292  int set_trigger_level(double setting);
293  int set_trigger_pos(double setting);
294  int set_trigger_polarity(int setting);
295  int set_trigger_mode(int mode);
296  int set_run_mode(int mode);
297  void prepare_scope_restart(void);
298  void log_popup(int);
299  #endif /* HALSC_USR_H */