Specifications
Sample Driver Code 61
* *
* *
*
* * * *
* * *
* * * *
*
* * * *
* *
* * *
* *
* *
*
* *
* *
* * *
Figure 5-7. EXAMPLE2.C Finger Painting
In the following source code, the Mode, Calibration, and Scaling commands are
queried, modified, then set. This preserves the contents of reserved bytes. Refer to
the Command Reference in Chapter 6 for details on each command.
/*************************************************************************
EXAMPLE2.C
Polls Elo SmartSet touchscreen controllers.
Acquires calibration points through extrapolation.
Sets calibration, scaling, and mode in controller.
Finishes with 80x25 finger painting.
**************************************************************************/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "packet.c" /* SmartSet interface independent code */
#include "pc_misc.c" /* miscellaneous PC dependent code */
void getcalibration(int *xlow, int *xhigh,
int *ylow, int *yhigh, boolean *xyswap);
void getpoint(int x, int y, int *tx, int *ty);
void outstr(int x, int y, char *s);
void xch(int *i1, int *i2);
/*************************************************************************/
int main(void)
{
int x,y,z,flags,xlow,xhigh,ylow,yhigh;
packettype packet;
unsigned *p;
boolean xyswapflag;
initcontroller();
checkdiags();
/* calibrate touchscreen */
/* To acquire calibration points, controller must be in raw coordinate
mode. We use the point of untouch as our calibration point. */
packet[0] = 'm'; querycommand(packet); /* get current mode */
packet[2] = 0x84; /* untouch and no Z modes */
packet[3] = 0x00; /* raw coordinates only */
setcommand(packet); /* set modes for calibration */
packet[0] = 'c'; packet[1] = 'S'; /* get swap axes flag */
querycommand(packet);
packet[2] = 0; setcommand(packet); /* insure axes are not swapped */
getcalibration(&xlow,&xhigh,&ylow,&yhigh,&xyswapflag); /* corners of image */
packet[0] = 'C'; packet[1] = 'X';
p = (unsigned *)packet; *++p = xlow; *++p = xhigh;
setcommand(packet); /* set X calibration points */
packet[1] = 'Y';
p = (unsigned *)packet; *++p = ylow; *++p = yhigh;
setcommand(packet); /* set Y calibration points */
packet[0] = 'c'; packet[1] = 'S'; querycommand(packet);
packet[2] = (byte)xyswapflag;
setcommand(packet); /* set swap axes flag as necessary */
/* set scaling to 1..80, 1..25 */