Home Contents | # touch:calibration | Touch | Core4 Lua Event System

## SYNOPSIS

1. cal = touchhandle:calibration()
2. cal = touchhandle:calibration(cal)
3. cal = touchhandle:calibration("clear")

## DESCRIPTION

Query or set the calibration for the touch screen. The table cal contains the fields:

xoffs | X-offset
xscale | X scaling factor
xyscale | Y correction scaling factor
xmax | X display resolution
yoffs | Y-offset
yscale | Y scaling factor
yxscale | X correction scaling factor
ymax | Y display resolution
penthr | Pen pressure threshold
fingerthr | Finger pressure threshold
flags | Flags indicating screen orientation

The following piece of code shows how the calibration data is used. Assume raw_x and raw_y contain the raw data from the hardware, while screen_x and screen_y will receive the calculated result.

if (cal.flags & 1) then local tmp = raw_x raw_x = raw_y raw_y = tmp end screen_x = ((raw_x * cal.xscale) >> 16) + ((raw_y * cal.xyscale) >> 16) - cal.xoffs screen_y = ((raw_y * cal.yscale) >> 16) + ((raw_x * cal.yxscale) >> 16) - cal.yoffs if (cal.flags & 2) then screen_x = cal.xmax - screen_x end if (cal.flags & 4) then screen_y = cal.ymax - screen_y end if (screen_x < 0) then screen_x = 0 end if (screen_x >= cal.xmax) then screen_x = cal.xmax - 1 end if (screen_y < 0) then screen_y = 0 end if (screen_y >= cal.ymax) then screen_y = cal.ymax - 1 end

A touch event will indicate an event if the raw pressure value is greater than cal.penthr. In addition, it will report a finger event if the pressure is greater that cal.fingerthr. Note that the finger pressure threshold is always larger than the pen threshold.

The third form tch:calibration("clear") will clear the current calibration data. For touch screens that need a calibration to work, this immediately prompts the user to calibrate. Touch screens with a hard-wired calibration (e.g. Infrared) revert to their default.

## RETURN VALUE

Returns a table containing the calibration values.

## SEE ALSO

touch:calibrate()