home *** CD-ROM | disk | FTP | other *** search
- /* Control display functions -- maintain graphic displays of
- system variables.
-
- Each display has two variables, one displayed by a vertical line
- whose length changes in proportion to the variable value, and the
- other variable represented by a short horizontal bar whose position
- moves in porportion to its value.
-
- Typical uses are for displaying a process output variable and the
- associated setpoint, or, when only the vertical bar is used, to display
- other process variables, output values, etc.
-
- Each display is described by a data structure containing all of the
- relevant information. Functions are provided to fill the structure and
- operate on it, so the user programmer need only declare the structure
- and assign storaage for it.
-
- When defining display units in a user program, all that is needed is
- to define the storage space for each and call the set-up program.
- The storage is allocated with one of the following declarations:
-
- DISPLAY temp_dsp;
-
- or to define a group of displays with,
-
- DISPLAY dsp[10];
-
- or to use the memory allocator,
-
- DISPLAY *pr_dsp;
- char *malloc();
- ...
- pr_dsp = (DISPLAY *)malloc(NDSP * sizeof(DISPLAY));
-
- Then, the function dsp_set() is called to put data into the structure.
-
- copyright (c) 1987, D. M. Auslander
-
- Created: 25 June 87
-
- Updates:
- 10-July-87, DMA, bugs
- */
-
- #include "display.h" /* Contains the description of the data structure */
- #include "dparam.h" /* Contains system-specific parameters */
-
- /* Set up a structure for a display --
- pd is a pointer to a (blank) structure -- space for the structure must
- be assigned in the **calling** function */
-
- dsp_set(pd,x,y,label,lngth,lcolor,vbot,vtop,fv1,fv2,fmt,dblnk) /*
- -------------------------------------------------------------- */
- struct display *pd;
- float (*fv1)(),(*fv2)(); /* Functions called to get
- data */
- float x,y; /* Position of the bottom of the vertical bar */
- float vbot,vtop; /* Variable values at the top and bottom of the
- line */
- float lngth; /* Line length (in cm) */
- int lcolor; /* Data display color */
- char *label; /* Label for this display */
- char *fmt; /* String with format to convert data */
- char *dblnk; /* String ob blanks to erase old data */
- {
- pd->x = x;
- pd->y = y;
- pd->label = label;
- pd->lngth = lngth;
- pd->lcolor = lcolor;
- pd->vbot = vbot;
- pd->vtop = vtop;
- pd->fv1 = fv1;
- pd->fv2 = fv2;
- pd->fmt = fmt;
- pd->dblnk = dblnk;
- dsp_flag(pd,1,1,1,1); /* Default is for all displays to be on */
- }
-
- dsp_flag(pd,v1l,v1d,v2b,v2d) /* Set the enabling flags for each of the
- ------------------------- itemss */
- int v1l,v1d,v2b,v2d;
- struct display *pd;
- {
- pd->v1line = v1l;
- pd->v1data = v1d;
- pd->v2bar = v2b;
- pd->v2data = v2d;
- }
-
-
- dsp_init(pd) /* Initialize a display -- put on the labels, blank the spot
- ------------ where the line goes, etc. */
- struct display *pd;
- {
- char cc[50]; /* Space for a character buffer */
- float x,y,lngth;
- int lcolor;
-
- x = pd->x; /* Copy to local variables */
- y = pd->y;
- lngth = pd->lngth;
- lcolor = pd->lcolor;
-
- mv_cur(x,y - laboff); /* Move cursor to label position */
- pstr(pd->label); /* Write the label to the screen */
-
- drawl(x,y,x,y + lngth,backc); /* Erase the old line */
-
- /* Draw the top and bottom tick bars */
-
- drawl(x + bx,y,x + bx + bw,y,lcolor); /* Bottom */
-
- sprintf(cc,pd->fmt,pd->vbot); /* Value */
- mv_cur(x + bx + bw + blx,y); /* Print it */
- pstr(cc);
-
- drawl(x + bx,y + lngth,x + bx + bw,y +lngth,lcolor); /* Top */
-
- sprintf(cc,pd->fmt,pd->vtop); /* Value */
- mv_cur(x + bx + bw + blx,y + lngth); /* Print it */
- pstr(cc);
-
- pd->val1 = pd->vbot; /* Initialize values to point to the bottom */
- pd->val2 = pd->vbot;
-
- pd->l1old = 0.0; /* Old length values */
- pd->l2old = 0.0;
- }
-
- dsp_data(pd) /* Display the data
- ------------ */
- struct display *pd;
- {
- float x,y,lngth,vbot,vtop;
- float val,lnew,l1old,l2old,lim();
- char cc[50];
- char cbuf[20];
-
- int lcolor,color;
-
- x = pd->x; /* Copy to local variables */
- y = pd->y;
- lngth = pd->lngth;
- lcolor = pd->lcolor;
- vbot = pd->vbot;
- vtop = pd->vtop;
- l1old = pd->l1old;
- l2old = pd->l2old;
-
- if(pd->v1line || pd->v1data)
- {
- val = (*(pd->fv1))(); /* Get the value of the first variable */
-
- if((pd->v1line) && (val != pd->val1))
- {
- /* Only proceed if the value has changed and the line
- is to be drawn */
-
- lnew = (val - vbot) * lngth / (vtop - vbot);
- lnew = lim(lnew,0.0,lngth);
-
- /* Check to see if line goes up or down */
- if(lnew > l1old)color = lcolor;
- else color = backc;
- drawl(x,y + l1old,x,y + lnew,color); /* Draw */
- pd->l1old = lnew; /* Save the new line length */
- }
-
- if(pd->v1data && (val != pd->val1))
- {
- /* Write the data value */
-
- if(pd->v1line)
- mv_cur(x - v1x,y + l1old);
- else
- mv_cur(x - v1x,y + v1y);
-
- pstr(pd->dblnk); /* Erase old value */
- if(pd->v1line)
- mv_cur(x - v1x,y + lnew);
- else
- mv_cur(x - v1x,y + v1y);
-
- sprintf(cc,pd->fmt,val);
- pstr(cc); /* Print value */
- }
- }
- pd->val1 = val; /* Save value */
-
- /* Now do second value */
-
- if(pd->v2bar || pd->v2data)
- {
- val = (*(pd->fv2))(); /* Get the value of the first variable */
-
- if(pd->v2bar && (pd->val2 != val))
- {
- /* Only draw if bar is enabled and data has changed */
-
- lnew = (val - vbot) * lngth / (vtop - vbot);
- lnew = lim(lnew,0.0,lngth);
-
- /* Erase the old value; Check first for overlap with top
- and bottom fiducial marks */
-
- if((l2old > ltol) && (l2old < (lngth - ltol)))
- {
- drawl(x + bx,y + l2old,x + bx + bw,y + l2old,backc);
- }
-
- /* Draw the new value's bar */
- if((lnew > ltol) && (lnew < (lngth - ltol)))
- {
- drawl(x + bx,y + lnew,x + bx + bw,y + lnew,lcolor);
- }
- pd->l2old = lnew; /* Save the new line length */
- }
-
- if(pd->v2data && (pd->val2 != val))
- {
- /* Write the data value */
-
- if(pd->v2bar)
- mv_cur(x + v2x,y + l2old);
- else
- mv_cur(x + v2x,y + v2y);
-
- pstr(pd->dblnk); /* Erase old value */
- if(pd->v2bar)
- mv_cur(x + v2x,y + lnew);
- else
- mv_cur(x + v2x,y + v2y);
-
- sprintf(cc,pd->fmt,val);
- pstr(cc); /* Print value */
- }
- }
- pd->val2 = val; /* Save the value */
- }
-
- float lim(x,xmin,xmax) /* Return x or its limits
- --------------------- */
- float x,xmin,xmax;
- {
- if(x < xmin)return(xmin);
- else if (x > xmax)return(xmax);
- return(x);
- }
-