Typically, SmartSet controllers are setup through software and/or NVRAM to supply the host with calibrated and scaled touch coordinates, as described in Chapter 5. If you cannot set up the controller with this procedure, you will receive raw coordinates from the controller. The host software must then map these coordinates within the calibration range (defining the position and size of the screen image) and scaled into screen coordinates, such as 80x25. These operations can be performed with the formula given below. (For more information on calibration and scaling, see the tutorial in Chapter 4).
Figure 4-5 shows a bezel opening and the position of an image within it. The touchscreen extends beyond the image into the overscan area, which is inaccessible to a program. The points at the extremes of the image are given two names, one in raw coordinates (denoted by "R") and one in screen coordinates (denoted by "S"). Low points may be greater than high points and vice versa -- the formula works with any orientation. The point of touch to be converted will be at the "+". It is also given two names: Cx,Cy for the raw coordinates, and X,Y for the screen coordinates.
The coordinates at the corners of the image are obtained by a calibration program that you write. See Chapter 5 for an example. This program simply outputs a point near one corner, lets the user touch it, then repeats the process near the opposite corner. These points are then extrapolated to the actual corners of the image, to reduce the effects of non-linearities in the display image. The calibration program stores the raw coordinates for each corner in a file. The driver or application you write will later load these points and use them in the conversion formula.
The screen coordinates in our example will be from 1 to 80 in X, and 1 to 25 in Y. Therefore, Sxlow=1, Sxhigh=80, Sylow=1, and Syhigh=25. Any coordinate scaling may be used, such as 0 to 99999 or -10 to 10.
The conversion process must be performed for both X and Y, but for simplicity, we will only give the formula in X:
X = (![]() ![]() |
where
Cx is the raw coordinate at "+" in the X-axis. |
X is the translated coordinate at "+" in screen coordinates. |
|
|
This algorithm can be computed with integer arithmetic if you do the following:
Do the multiply Sx(Cx-Rxlow)
before dividing by
Rx.
Rx
and
Sx
can be pre-computed to improve performance, but
Sx/
Rx
will likely be zero if pre-computed because
Sx
may be smaller than
Rx.
To adjust for slight rounding errors introduced in integer arithmetic, add a rounding constant to the formula:
X = (Sx(Cx-Rxlow+(
Rx/2
Sx))/
Rx)
+ Sxlow
The rounding constant may be pre-computed.
Other notes:
IF Cx < Rxlow THEN Cx := Rxlow |
ELSE IF Cx > Rxhigh THEN Cx := Rxhigh; |