The text of a manual · part 7 of 23
VRC 4000 Software Driver Manual: Chapter 2 TBDriver Touchscreen Driver for DOS, pages 53 to 62
Pages 53 to 62 of 206, from VRC 4000 Software Driver Manual
The original document is the PDF (1.2 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Symbol VRC-4000
Page 53
Chapter 2: TBDriver Touchscreen Driver for DOS
In an ideal world, such a simple calibration scheme would be all that was required to ensure that the touch coordinates correctly reflected the position on the visual image at all times. Unfortunately however, when driven in different modes, many monitors display images of considerably different size, and/or in different positions on the CRT. Normally of course this doesn't matter very much, but it is very inconvenient for a touchscreen user.
Soft Calibration Imagine a hypothetical application which uses a graphics mode in some parts, and a text mode in others. Also suppose that your monitor displays graphics images half an inch smaller than text images, and that you hard calibrated the touchscreen in graphics mode. Everything works perfectly in graphics mode, with the program responding to touches exactly as the user expects. However, when the screen is switched to text mode, things start to go wrong. The touchscreen system thinks that the edges of the screen are a quarter of an inch away from where the user sees them, and the program starts responding to areas a quarter of an inch away from where the user is touching. Fortunately, a technique called soft calibration comes to the rescue. Soft calibration is a means of defining different calibrations for different video modes. Again, two touches are used to define the edges of the image. The resulting coordinates are used to re-map the raw coordinates to the new edges. TBdriver provides a number of facilities for managing the different soft calibrations required in various video modes. Most cases are handled fully automatically.
Automatic Soft Calibration The TBcal utility program supplied allows you to soft calibrate in most of the commonly used video modes, as well as any two other modes of your choice. The calibration coordinates are stored in a file called TBcalib. TBdriver reads TBcalib when it loads, and remembers all the soft calibrations stored in it. It then monitors changes in the current video mode and automatically switches to the most appropriate soft calibration if it exists in the file. If no calibration is defined for a particular mode, then the hard calibration is used. This automatic mode is the default, and can handle virtually all situations. All you have to do is run TBcal and provide two touches for each mode. TBdriver does the rest. 2-11
Page 54
VRC 4000 Software Driver Manual
User Defined Calibrations The calibration utility program allows you to specify the video modes which are used to calibrate in the two user defined calibration modes, and also to edit the mappings of system video modes to calibration modes used by the driver. This provides a complete solution to the problem of calibration for nonstandard video modes and non-standard video hardware.
API Call Soft Calibration In order to cater for the unlikely event that an application needs to use more video modes than are handled by automatic calibration, TBdriver provides a set of API calls which allow an application to capture its own soft calibrations, store them, and activate them at any time. A pair of calls return the raw coordinates of the bottom left and top right corners of the image, based on two touches. The application can then store these coordinates, and can issue another call to activate any set of previously stored calibration coordinates. The application can therefore arrange to capture calibrations for any number of modes, store them in a file, and activate them when it puts the video system into those modes. While such user defined calibrations are active, TBdriver's automatic re-calibration is disabled, since the application is assumed to want to manage soft calibration itself. Another API call allows the application to deactivate its own soft calibrations, and return to automatic mode.
Calibration Summary Always use TBcal to perform hard calibration when you first assemble a new system, and soft calibrate in all the video resolutions you might use. Allow TBdriver to handle soft calibration automatically unless you have a good reason for doing otherwise. Note that the soft calibrated area cannot be larger than the hard calibrated area, so the hard calibration must be to the extreme edge of the monitor bezel.
2-12
Page 55
Chapter 2: TBDriver Touchscreen Driver for DOS
Sensitivity TBdriver allows you to control the amount of time it takes to register that a finger has been lifted off the screen. A setting of 1 corresponds to the shortest possible amount of time, which means the lift is recognized immediately, giving maximum sensitivity. As the sensitivity value is increased, the finger lift is detected more slowly, decreasing sensitivity. Usually, maximum sensitivity (1) is used, where areas of the screen are simply being touched, like keys on a keyboard, in a data-entry type manner. A touchscreen can offer data entry techniques which a keyboard cannot, in particular using the ability to sense that a stylus is sliding around on the screen. For example a graphical picture of a sliding scale can be a rapid way of scanning through a list of values or items. Pieces of text or graphics can be dragged around the screen, or lines can be drawn. When sliding on some types of touchscreen, the user's finger can accidentally lose contact with the screen, invoking an undesired response from the application. This problem can be alleviated by the application temporarily reducing sensitivity, say to a value of 3. This will cause finger lifts of very short duration to go undetected, while intentional finger lifts will still be detected reasonably quickly.
Pads It is very common to want to match incoming touch coordinates to rectangles or other shapes displayed on the screen. For example, a touch menu screen might consist of a number of boxes inviting the user to touch one of the options. The menu program would then have to determine, from the X and Y coordinates and the current scale, which box had been touched and act accordingly. This can easily be done by the application, but it is easier and more efficient to have TBdriver do it.
2-13
Page 56
VRC 4000 Software Driver Manual
An API call allows you to define the coordinates of up to 99 rectangular areas on the screen, and subsequently refer to these areas, or pads, by number. Once defined, pads can be activated and de-activated. That is, they can be made touch sensitive, or not touch sensitive. When you read the driver, you always receive a touch type and a pair of X and Y coordinates. In addition, if the coordinates fall within the bounds of a currently active pad, you also receive the pad number in one of the other registers. If the coordinates do not fall within the bounds of an active pad, you receive a pad number of zero. So in our menu example above, you would define the option 1 box as pad 1, option 2 as pad 2, and so on, and then activate all or some of the pads. Then you read TBdriver and examine the pad number. If it is zero you might just make a rude noise and try again, but if it is non-zero, you just execute that particular option. There is nothing to stop two active pads from having coordinates which overlap each other on the screen. If a touch falls inside the bounds of more than one active pad definition, TBdriver assigns the lowest numbered active pad number to the touch. Overlapped pads will occur in, for example, applications which make use of popup windows. The simplest way of handling this from a pad point of view is to de-activate pads which are partially or fully obscured. If you must leave overlapped pads active, you will have to assign pad numbers carefully. Pads are numbered 1 to 99, and their coordinates are defined in the current scale.
Stability On some touchscreens, if you keep your finger stationary in contact with the screen, the reported coordinates are subject to continual slight variations, known as 'jitter'. In certain types of application, you may need to dampen this effect in order to provide a more stable visual response. An API call allows you to specify a number of coordinates which are historically averaged to dampen the effect of these slight variations. The penalty for setting this value high is of course that it takes longer for movements to be reported, since stabilized coordinates are affected by the values of a number of previous coordinates.
2-14
Page 57
Chapter 2: TBDriver Touchscreen Driver for DOS
Stabilization is not implemented for infra-red touchscreens, which never suffer from jitter.
The Time Axis TBdriver internally monitors the length of time that your finger remains stationary in contact with the screen, and returns it with the X, Y and Z coordinates. The Time axis adds a useful extra dimension to touch screen programming. While your finger slides around on the screen, the time axis is zero, or a small value. As soon as you hold your finger stationary, the Time axis begins to increase, at the rate of one unit per clock tick (the clock ticks 18.2 times per second). The Time axis can be used, for example, to perform some special action when the user's finger has remained stationary on a pad for a period of time.
Event Driven Applications TBdriver allows your application to drive the touchscreen in two ways. You can 'poll' the driver to read the touch state through the Read Touches API call, or you can set TBdriver to interrupt you when a touch event occurs. This is done by giving TBdriver the address of a 'User Interrupt Service Routine' - a procedure within your application which will be called when an event occurs. An event is defined as: • The touch buffer is not empty • A Repeat touch and either the X or Y coordinates have changed, i.e. the finger is sliding around. • A Repeat touch and the Z axis threshold is crossed by the rising Z coordinate. • A Repeat touch and the Time axis threshold is crossed by the rising Time coordinate. TBdriver handles all the tricky bits of this for you by saving all the CPU registers, swapping stacks to one provided by the application, and setting up the data segment register to point to your data space. TBdriver continues to operate normally, for example buffering touches, while the User Interrupt Service Routine executes.
2-15
Page 58
VRC 4000 Software Driver Manual
Application Programming Interface Before Calling The API Before you make any calls to TBdriver, you must make sure that it is loaded. One very simple check you can make is to examine the address in the chosen interrupt vector. If it is zero, then TBdriver is definitely not loaded, and if you were to call this null interrupt, you would certainly crash the machine. If the address is non-zero, you can be sure that some API is loaded, although you can't be sure it is TBdriver. Usually your system will be set up such that this simple check will be quite adequate, but to be really certain, you can check the 8 bytes preceding the address pointed to by the interrupt vector. If it is truly TBdriver, then these 8 bytes will contain the string 'TBDRIVER'. The default API interrupt vector is 66 hex, but if some other API in your system is already using this, you may change it as described in ’Hardware Configuration’. In this case your application should call the new vector. TBdriver saves the DS register on entry to the API and restores it on exit. All other registers are destroyed.
2-16
Page 59
Chapter 2: TBDriver Touchscreen Driver for DOS
Function:
Activate Pad
Calling Sequence:
AL=13 hex AH=Pad number Call API interrupt
Return Values:
None
Description:
Makes a pad touch sensitive. Subsequent touches within the pad are reported as such. There is no harm in activating an already active pad, but it makes no sense to activate a pad which has not yet been defined.
See Also:
De-activate Pad Define Pad Get Pad Definition
2-17
Page 60
VRC 4000 Software Driver Manual
Function:
Activate Soft Calibration Coordinates
Calling Sequence:
AL =9 BX=X1 (Left edge) CX=Y1 (Bottom edge) DX=X2 (Right edge) ES=Y2 (Top edge) Call API interrupt
Return Values:
None
Description:
Activates soft calibration for the area defined. Subsequent coordinates are relative to this new area. The coordinates must have been obtained using the Read Soft Calibration Coordinates function. Note that while such API call soft calibration is active, TBdriver's normal function of automatically loading soft calibrations appropriate to the current video mode is disabled. For most purposes, the usage of this call has been superseded by the Soft Calibrate API call.
See Also:
2-18
Read Soft Calibration Coordinates De-activate Soft Calibration Get Current Calibration
Page 61
Chapter 2: TBDriver Touchscreen Driver for DOS
Function: Calling Sequence:
De-Activate Soft Calibration
Return Values:
None
Description:
De-activates the soft calibration which was defined using the Activate Soft Calibration Coordinates function. Automatic calibration is resumed.
AL =10 hex Call API interrupt
For most purposes, the usage of this call has been superseded by the Soft Calibrate API call.
See Also:
Activate Soft Calibration Coordinates Read Soft Calibration Coordinates Get Current Calibration
2-19
Page 62
VRC 4000 Software Driver Manual
Function: Calling Sequence:
De-Activate Pad AL = 14 hex AH = Pad number, or zero to de-activate all pads Call API interrupt
Return Values:
None
Description:
Stops a pad from being touch sensitive, but retains its coordinates. Subsequent touches within the pad are not reported as being within the pad. Any touched area not within an active pad is reported as pad zero. An inactive pad may later be re-activated.
See Also:
Activate Pad Define Pad Get Pad Definition
2-20