android 触摸屏校准

来源:互联网 发布:企业网站源码带手机版 编辑:程序博客网 时间:2024/05/16 04:46

一,触摸校准算法 
   触摸屏校准通用方法。 
  (XL, YL是显示屏坐标,XT, YT是触摸屏坐标,) 
XL = XT*A+YT*B+C 
YL = XT*D+YT*E+F 
   由于具体计算是希望是整数运算,所以实际中保存的ABCDEF为整数,而增加一个参数Div 
XL = (XT*A+YT*B+C) / Div 
YL = (YT*D+YT*E+F) / Div 
    TSLIB把以上的7个参数 ABCDEF Div 保存在 pointercal 文件中。 
不校准的数据: A=1, B=0, C=0, D=0, E=1, F=0, Div=1
 
ABCDEFDiv-41137818-3636780-51325394706558465536
二,Android 事件处理机制 
    android 事件的传入是从EventHub开始的,EventHub是 事件的抽象结构,维护着系统设备的运行情况(设备文件放在/dev/input里),设备类型包括Keyboard、TouchScreen、TraceBall。它在系统启动的时候会通过 open_device方法将系统提供的输入设备都增加到这个抽象结构中,并维护一个所有输入设备的文件描述符,如果输入设备是键盘的话还会读取 /system/usr/keylayout/目录下对应键盘设备的映射文件(修改./development/emulator/keymaps/qwerty.kl来改变键值的映射关系),另外getEvent方法是对EventHub中的设备文件描述符使用poll操作等侍驱动层事件的发生,如果发生的事件是键盘事件,则调用Map函数按照映射文件转换成相应的键值并将扫描码和键码返回给KeyInputQueue. 
frameworks/base/services/jni/com_android_server_KeyInputQueue.cpp 
    根据事件的类型以及事件值进行判断处理,从而确定这个事件对应的设备状态是否发生了改变并相应的改变对这个设备的描述结构InputDevice。 
Windowmanager会创建一个线程(InputDispatcherThread),在这个线程里从事件队列中读取发生的事件 (QueuedEvent ev = mQueue.getEvent()),并根据读取到事件类型的不同分成三类(KEYBOARD、TOUCHSCREEN、TRACKBALL),分别进 行处理,例如键盘事件会调用dispatchKey((KeyEvent)ev.event, 0, 0)以将事件通过Binder发送给具有焦点的窗口应用程序,然后调用 mQueue.recycleEvent(ev)继续等侍键盘事件的发生;如果是触摸屏事件则调用dispatchPointer(ev, (MotionEvent)ev.event, 0, 0),这里会根据事件的种类(UP、DOWN、MOVE、OUT_SIDE等)进行判断并处理,比如Cancel或将事件发送到具有权限的指定的窗口中 去; 
    移植方案 
Android本身并不带触摸屏校准。Android获取到的数据就是驱动上报的原始数据。 
方案一 : 移植TSLIB,通过TSLIB产生 pointercal 校准参数文件。 
方案二 : 从Android框架层获取OnTouch事件产生 pointercal 校准参数文件 
方案一: 数据的校准在驱动中完成。 即把 pointercal 的参数数据通过某种方式(sysfs)传递给驱动程序进行校准。 
方案二: 驱动上报原始点,原始点在框架层拦截后进行校验处理。 
    TSLIB移植过程 
修改源码以适应android的文件结构。 
设定Android.mk 编译选项,生成库即应用。 
etc/ts.conf module_raw input 
src/ts_config.c #define TS_CONF "/system/etc/ts.conf" 
src/ts_load_module.c 
char *plugin_directory="/system/lib/ts/plugins/"; 
tests/fbutils.c 
char *defaultfbdevice = "/dev/graphics/fb0"; 
COPY ts.conf 到 /system/etc/ts.conf 
init.rc. mkdir /data/etc/pointercal 
通过 ts_calibrate 产生pointercal 数据文件。 
框架内获取参数文件制作APK 应用,仿效ts_calibrate采点并计算出各参数,产生 pointercal框架内实现触摸屏校准在 InputDevive.java 中 拦截触摸屏原始数据进行pointercal参数校验后再分发驱动内实现触摸屏校准 
在init.rc 中添加event,在触摸屏加载后把 pointercal参数输送给驱动。 
    结果-效果 
实现细节: 
    扩展init - proper_serivce 系统支持的属性权限,对自定义的特殊系统属性进行权限开放。 
    使用自定义系统属性在 init.rc 中 on property 事件中处理pointercal的读写权限。 
    使用自定义系统属性 触摸屏校准程序.apk 和 InputDevice.java 中的输入事件的同步。 
(在触摸屏校准期间 inputDevice 在输入事件中不能采用算法。 校准程序完成有inputDevice重新启用校准算法) 
    模拟器中至今无法进入 device.absX/Y != null 的代码, 需要了解以下 inputDevice 被调用的步骤。 
三,触摸屏的时间流程: 
驱动层: 
    

C代码 复制代码 收藏代码
  1. /*  
  2.  * Touchscreen absolute values  
  3.  *  
  4.  * These parameters are used to help the input layer discard out of  
  5.  * range readings and reduce jitter etc.  
  6.  *  
  7.  * o min, max:- indicate the min and max values your touch screen returns  
  8.  * o fuzz:- use a higher number to reduce jitter  
  9.  *  
  10.  * The default values correspond to Mainstone II in QVGA mode  
  11.  *  
  12.  * Please read  
  13.  * Documentation/input/input-programming.txt for more details.  
  14.  */  
  15.   
  16. static int abs_x[3] = {350, 3900, 5};   
  17. module_param_array(abs_x, int, NULL, 0);   
  18. MODULE_PARM_DESC(abs_x, "Touchscreen absolute X min, max, fuzz");   
  19.   
  20. static int abs_y[3] = {320, 3750, 40};   
  21. module_param_array(abs_y, int, NULL, 0);   
  22. MODULE_PARM_DESC(abs_y, "Touchscreen absolute Y min, max, fuzz");   
  23.   
  24. static int abs_p[3] = {0, 150, 4};   
  25. module_param_array(abs_p, int, NULL, 0);   
  26. MODULE_PARM_DESC(abs_p, "Touchscreen absolute Pressure min, max, fuzz");   
  27.   
  28. /*  
  29. *  对设备进行初始化设置  
  30. */  
  31.     set_bit(EV_ABS, wm->input_dev->evbit);   
  32.     set_bit(ABS_X, wm->input_dev->absbit);   
  33.     set_bit(ABS_Y, wm->input_dev->absbit);   
  34.     set_bit(ABS_PRESSURE, wm->input_dev->absbit);   
  35.     input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1],   
  36.                  abs_x[2], 0);   
  37.     input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1],   
  38.                  abs_y[2], 0);   
  39.     input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1],   
  40.                  abs_p[2], 0);   
  41.   
  42. /*  
  43. * 事件发生时,提供原始点  
  44. */  
  45. input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff);   
  46.         input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff);   
  47.         input_report_abs(wm->input_dev, ABS_PRESSURE, data.p & 0xfff);   
  48.   
  49. /*  
  50. * 提供给驱动外查询input_dev 的接口  
  51. * struct input_absinfo info;  
  52. * ioctl(fd, EVIOCGABS(axis), &info)  
  53. * src file: evDev.c  
  54. */  
  55. if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) {   
  56.   
  57.                 t = _IOC_NR(cmd) & ABS_MAX;   
  58.   
  59.                 abs.value = dev->abs[t];   
  60.                 abs.minimum = dev->absmin[t];   
  61.                 abs.maximum = dev->absmax[t];   
  62.                 abs.fuzz = dev->absfuzz[t];   
  63.                 abs.flat = dev->absflat[t];  
/* * Touchscreen absolute values * * These parameters are used to help the input layer discard out of * range readings and reduce jitter etc. * * o min, max:- indicate the min and max values your touch screen returns * o fuzz:- use a higher number to reduce jitter * * The default values correspond to Mainstone II in QVGA mode * * Please read * Documentation/input/input-programming.txt for more details. */static int abs_x[3] = {350, 3900, 5};module_param_array(abs_x, int, NULL, 0);MODULE_PARM_DESC(abs_x, "Touchscreen absolute X min, max, fuzz");static int abs_y[3] = {320, 3750, 40};module_param_array(abs_y, int, NULL, 0);MODULE_PARM_DESC(abs_y, "Touchscreen absolute Y min, max, fuzz");static int abs_p[3] = {0, 150, 4};module_param_array(abs_p, int, NULL, 0);MODULE_PARM_DESC(abs_p, "Touchscreen absolute Pressure min, max, fuzz");/**  对设备进行初始化设置*/    set_bit(EV_ABS, wm->input_dev->evbit);    set_bit(ABS_X, wm->input_dev->absbit);    set_bit(ABS_Y, wm->input_dev->absbit);    set_bit(ABS_PRESSURE, wm->input_dev->absbit);    input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1],                 abs_x[2], 0);    input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1],                 abs_y[2], 0);    input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1],                 abs_p[2], 0);/** 事件发生时,提供原始点*/input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff);        input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff);        input_report_abs(wm->input_dev, ABS_PRESSURE, data.p & 0xfff);/** 提供给驱动外查询input_dev 的接口* struct input_absinfo info;* ioctl(fd, EVIOCGABS(axis), &info)* src file: evDev.c*/if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) {                t = _IOC_NR(cmd) & ABS_MAX;                abs.value = dev->abs[t];                abs.minimum = dev->absmin[t];                abs.maximum = dev->absmax[t];                abs.fuzz = dev->absfuzz[t];                abs.flat = dev->absflat[t];


Android 底层驱动 

Cpp代码 复制代码 收藏代码
  1. EventHub.cpp   
  2.   
  3. static const char *device_path = "/dev/input";   
  4.   
  5. openPlatformInput(void)   
  6.   scan_dir(device_path);   
  7.     open_device(devname);   
  8.       fd = open(deviceName, O_RDWR);   
  9.   
  10. /*  
  11. * 对外接口,getEvent,   
  12. * inotify 监控device_path目录, 使用poll机制轮询 inotify 和各个输入设备的可用状态。 解析事件或输入信息,放入各个传出参数中。  
  13. */  
  14. bool EventHub::getEvent(int32_t* outDeviceId, int32_t* outType,   
  15.         int32_t* outScancode, int32_t* outKeycode, uint32_t *outFlags,   
  16.         int32_t* outValue, nsecs_t* outWhen)   
  17.   
  18. JNI 部分: com_android_server_KeyInputQueue.cpp. 提供接口   
  19.   
  20. static JNINativeMethod gInputMethods[] = {   
  21.     /* name, signature, funcPtr */  
  22.     { "readEvent""(Landroid/view/RawInputEvent;)Z",   
  23.             (void*) android_server_KeyInputQueue_readEvent },   
  24.     { "getDeviceClasses""(I)I",   
  25.         (void*) android_server_KeyInputQueue_getDeviceClasses },   
  26.     { "getDeviceName""(I)Ljava/lang/String;",   
  27.         (void*) android_server_KeyInputQueue_getDeviceName },   
  28.     { "getAbsoluteInfo""(IILcom/android/server/InputDevice$AbsoluteInfo;)Z",   
  29.         (void*) android_server_KeyInputQueue_getAbsoluteInfo },   
  30.     { "getSwitchState""(I)I",   
  31.         (void*) android_server_KeyInputQueue_getSwitchState },   
  32.     { "getSwitchState""(II)I",   
  33.         (void*) android_server_KeyInputQueue_getSwitchStateDevice },   
  34.     { "getScancodeState""(I)I",   
  35.         (void*) android_server_KeyInputQueue_getScancodeState },   
  36.     { "getScancodeState""(II)I",   
  37.         (void*) android_server_KeyInputQueue_getScancodeStateDevice },   
  38.     { "getKeycodeState""(I)I",   
  39.         (void*) android_server_KeyInputQueue_getKeycodeState },   
  40.     { "getKeycodeState""(II)I",   
  41.         (void*) android_server_KeyInputQueue_getKeycodeStateDevice },   
  42.     { "hasKeys""([I[Z)Z",   
  43.         (void*) android_server_KeyInputQueue_hasKeys },   
  44. };  
EventHub.cppstatic const char *device_path = "/dev/input";openPlatformInput(void)  scan_dir(device_path);    open_device(devname);      fd = open(deviceName, O_RDWR);/** 对外接口,getEvent, * inotify 监控device_path目录, 使用poll机制轮询 inotify 和各个输入设备的可用状态。 解析事件或输入信息,放入各个传出参数中。*/bool EventHub::getEvent(int32_t* outDeviceId, int32_t* outType,        int32_t* outScancode, int32_t* outKeycode, uint32_t *outFlags,        int32_t* outValue, nsecs_t* outWhen)JNI 部分: com_android_server_KeyInputQueue.cpp. 提供接口static JNINativeMethod gInputMethods[] = {    /* name, signature, funcPtr */    { "readEvent", "(Landroid/view/RawInputEvent;)Z",            (void*) android_server_KeyInputQueue_readEvent },    { "getDeviceClasses", "(I)I",        (void*) android_server_KeyInputQueue_getDeviceClasses },    { "getDeviceName", "(I)Ljava/lang/String;",        (void*) android_server_KeyInputQueue_getDeviceName },    { "getAbsoluteInfo", "(IILcom/android/server/InputDevice$AbsoluteInfo;)Z",        (void*) android_server_KeyInputQueue_getAbsoluteInfo },    { "getSwitchState", "(I)I",        (void*) android_server_KeyInputQueue_getSwitchState },    { "getSwitchState", "(II)I",        (void*) android_server_KeyInputQueue_getSwitchStateDevice },    { "getScancodeState", "(I)I",        (void*) android_server_KeyInputQueue_getScancodeState },    { "getScancodeState", "(II)I",        (void*) android_server_KeyInputQueue_getScancodeStateDevice },    { "getKeycodeState", "(I)I",        (void*) android_server_KeyInputQueue_getKeycodeState },    { "getKeycodeState", "(II)I",        (void*) android_server_KeyInputQueue_getKeycodeStateDevice },    { "hasKeys", "([I[Z)Z",        (void*) android_server_KeyInputQueue_hasKeys },};


java service 部分: KeyInputQueue.java. 循环查询输入设备信息或目录状态并处理 

Java代码 复制代码 收藏代码
  1. Thread mThread = new Thread("InputDeviceReader") {   
  2.         public void run() {   
  3.             android.os.Process.setThreadPriority(   
  4.                     android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);   
  5.                
  6.             try {   
  7.                 RawInputEvent ev = new RawInputEvent();   
  8.                 while (true) {   
  9.                     InputDevice di;   
  10.   
  11.                     // block, doesn't release the monitor   
  12.   
  13.                     readEvent(ev);   
  14.   
  15.                     boolean send = false;   
  16.                     boolean configChanged = false;   
  17.   
  18. ......   
  19.                        
  20.   
  21. //检测到新设备后   
  22.   
  23. if (ev.type == RawInputEvent.EV_DEVICE_ADDED) {   
  24.                         synchronized (mFirst) {   
  25.                             di = newInputDevice(ev.deviceId);   
  26.                             mDevices.put(ev.deviceId, di);   
  27.                             configChanged = true;   
  28.                         }   
  29.                     }   
  30.   
  31. //对触摸屏设备   
  32. InputDevice.AbsoluteInfo absX;   
  33.         InputDevice.AbsoluteInfo absY;   
  34.         InputDevice.AbsoluteInfo absPressure;   
  35.         InputDevice.AbsoluteInfo absSize;   
  36.         if ((classes&RawInputEvent.CLASS_TOUCHSCREEN) != 0) {   
  37.             absX = loadAbsoluteInfo(deviceId, RawInputEvent.ABS_X, "X");   
  38.             absY = loadAbsoluteInfo(deviceId, RawInputEvent.ABS_Y, "Y");   
  39.             absPressure = loadAbsoluteInfo(deviceId, RawInputEvent.ABS_PRESSURE, "Pressure");   
  40.             absSize = loadAbsoluteInfo(deviceId, RawInputEvent.ABS_TOOL_WIDTH, "Size");   
  41.         } else {   
  42.             absX = null;   
  43.             absY = null;   
  44.             absPressure = null;   
  45.             absSize = null;   
  46.         }   
  47.            
  48.         return new InputDevice(deviceId, classes, name, absX, absY, absPressure, absSize);  
Thread mThread = new Thread("InputDeviceReader") {        public void run() {            android.os.Process.setThreadPriority(                    android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);                        try {                RawInputEvent ev = new RawInputEvent();                while (true) {                    InputDevice di;                    // block, doesn't release the monitor                    readEvent(ev);                    boolean send = false;                    boolean configChanged = false;......                    //检测到新设备后if (ev.type == RawInputEvent.EV_DEVICE_ADDED) {                        synchronized (mFirst) {                            di = newInputDevice(ev.deviceId);                            mDevices.put(ev.deviceId, di);                            configChanged = true;                        }                    }//对触摸屏设备InputDevice.AbsoluteInfo absX;        InputDevice.AbsoluteInfo absY;        InputDevice.AbsoluteInfo absPressure;        InputDevice.AbsoluteInfo absSize;        if ((classes&RawInputEvent.CLASS_TOUCHSCREEN) != 0) {            absX = loadAbsoluteInfo(deviceId, RawInputEvent.ABS_X, "X");            absY = loadAbsoluteInfo(deviceId, RawInputEvent.ABS_Y, "Y");            absPressure = loadAbsoluteInfo(deviceId, RawInputEvent.ABS_PRESSURE, "Pressure");            absSize = loadAbsoluteInfo(deviceId, RawInputEvent.ABS_TOOL_WIDTH, "Size");        } else {            absX = null;            absY = null;            absPressure = null;            absSize = null;        }                return new InputDevice(deviceId, classes, name, absX, absY, absPressure, absSize);

   我们对触摸屏的数据修订是在 InputDevice.java 中基于 absX, absY, absPressure != null 的状态下的,当绝对原始点数据从驱动报上来之后,传递到InputDevice.java 经过我们的校准后再dispatch出去到windowManager -> activity 。 这样就是起到了校准效果。 
四,需要注意的补助说明 
EventHub 中有使用IOCTL 对触摸屏的EVIOCGABS(axis)进行了采样,取出内容struct
C代码 复制代码 收藏代码
  1. input_absinfo info;   
  2. struct input_absinfo {   
  3.     __s32 value;   
  4.     __s32 minimum;   
  5.     __s32 maximum;   
  6.     __s32 fuzz;   
  7.     __s32 flat;   
  8.     __s32 resolution;   
  9. };   
  10.   
  11. #define EVIOCGABS(abs)        _IOR('E', 0x40 + abs, struct input_absinfo)        /* get abs value/limits */  
input_absinfo info;struct input_absinfo {    __s32 value;    __s32 minimum;    __s32 maximum;    __s32 fuzz;    __s32 flat;    __s32 resolution;};#define EVIOCGABS(abs)        _IOR('E', 0x40 + abs, struct input_absinfo)        /* get abs value/limits */

    取出的是触摸屏的最大值,最小值等,这些值在com_android_server_KeyInputQueue.cpp 中会把这些值传递给InputDevice.cpp中使用,即把报上来的位置通过算法进行计算成绝对坐标值 
C代码 复制代码 收藏代码
  1. scaledX = ((scaledX-device.absX.minValue)   
  2.                                 / device.absX.range) * w;  
scaledX = ((scaledX-device.absX.minValue)                                / device.absX.range) * w;

当然如果出现了X,Y轴相反或者坐标反向等问题都可通过改写这条语句来进行实际操作。

I have a resistive touchscreen with mechanical misalignments on my 
board. The "5 point calibration method" solves errors caused by these 
misalignments and converts Touchscreen controller data to actual 
screen coordinates. A complete description of mechanical misalignments 
and 5 point calibration method can be found at 
http://focus.tij.co.jp/jp/lit/an/slyt277/slyt277.pdf. 

5-point calibration method is part of the TSLIB touchscreen 
calibration commonly used for our QT based devices. We can extend 
Android's touchscreen Calibration parameters to include the 6 
parameters that are part of the /etc/pointercal file ( calculated when 
we run ts_calibrate on TSLIB). Sample idc file below: 

# See output of /etc/pointercal file after running ts_calibrate on normal Linux 

# Before running ts_calibrate - 
# export TSLIB_TSDEVICE=/dev/input/event1 
# export TSLIB_CALIBFILE=/etc/pointercal 
# export TSLIB_CONFFILE=/etc/ts.conf 
# export TSLIB_FBDEVICE=/dev/fb0 

# Pointercal file format - xscale, xymix, xoffset, yxmix, yscale, 
yoffset, divider. 
# Enter here the values after dividing xscale etc. with the divider. 

touch.5pointcalib.xscale = 0.199488 
touch.5pointcalib.xymix = -0.000325 
touch.5pointcalib.xoffset = -6.898865 
touch.5pointcalib.yxmix = -0.000795 
touch.5pointcalib.yscale = 0.124000 
touch.5pointcalib.yoffset = -8.484802 

I patched the Android Input subsystem to include the 5 point 
calibration method for generating actual screen coordinates. 
Gingerbread currently uses simple scaling of touchscreen X and Y data 
to CLCD screen X and Y coordinates. In frameworks/base made the 
following changes : 

diff --git a/include/ui/InputReader.h b/include/ui/InputReader.h 
index 49351b0..bb3ec5e 100644 
--- a/include/ui/InputReader.h 
+++ b/include/ui/InputReader.h 
@@ -589,6 +589,20 @@ protected: 

     // Immutable calibration parameters in parsed form. 
     struct Calibration { 
+       // 5 point calibration algorithm coefficients 
+       bool havexscale; 
+       float xscale; 
+       bool havexymix; 
+        float xymix; 
+       bool havexoffset; 
+        float xoffset; 
+       bool haveyxmix; 
+        float yxmix; 
+       bool haveyscale; 
+        float yscale; 
+       bool haveyoffset; 
+        float yoffset; 

         // Touch Size 
         enum TouchSizeCalibration { 
             TOUCH_SIZE_CALIBRATION_DEFAULT, 
diff --git a/libs/ui/InputReader.cpp b/libs/ui/InputReader.cpp 
index 3197ab2..9345dca 100644 
--- a/libs/ui/InputReader.cpp 
+++ b/libs/ui/InputReader.cpp 
@@ -1682,6 +1682,20 @@ void TouchInputMapper::parseCalibration() { 
     const InputDeviceCalibration& in = getDevice()->getCalibration(); 
     Calibration& out = mCalibration; 

+    out.havexscale = in.tryGetProperty(String8("touch.5pointcalib.xscale"), 
+            out.xscale); 
+    out.havexymix = in.tryGetProperty(String8("touch.5pointcalib.xymix"), 
+            out.xymix); 
+    out.havexoffset = in.tryGetProperty(String8("touch.5pointcalib.xoffset"), 
+            out.xoffset); 
+    out.haveyxmix = in.tryGetProperty(String8("touch.5pointcalib.yxmix"), 
+            out.yxmix); 
+    out.haveyscale = in.tryGetProperty(String8("touch.5pointcalib.yscale"), 
+            out.yscale); 
+    out.haveyoffset = in.tryGetProperty(String8("touch.5pointcalib.yoffset"), 
+            out.yoffset); 


     // Touch Size 
     out.touchSizeCalibration = Calibration::TOUCH_SIZE_CALIBRATION_DEFAULT; 
     String8 touchSizeCalibrationString; 
@@ -2294,10 +2308,47 @@ void TouchInputMapper::dispatchTouch(nsecs_t 
when, uint32_t policyFlags, 
             uint32_t inIndex = touch->idToIndex[id]; 

             const PointerData& in = touch->pointers[inIndex]; 
+           float x,y; 

             // X and Y 
-            float x = float(in.x - mLocked.xOrigin) * mLocked.xScale; 
-            float y = float(in.y - mLocked.yOrigin) * mLocked.yScale; 
+           if ( mCalibration.havexscale && mCalibration.havexymix && 
+                       mCalibration.havexoffset && mCalibration.haveyxmix && 
+                               mCalibration.haveyscale && mCalibration.haveyoffset) { 

+             x = float(in.x - mLocked.xOrigin) * mLocked.xScale; 
+              y = float(in.y - mLocked.yOrigin) * mLocked.yScale; 
+             LOGI("x_orig = %f, y_orig = %f\n", x, y); 
+             float x_temp = float(in.x - mLocked.xOrigin); 
+             float y_temp = float(in.y - mLocked.yOrigin); 

+              //float xscale = 0.199488; 
+             //float xymix = -0.000325; 
+             //float xoffset = -6.898865; 
+             //float yxmix = -0.000795; 
+             //float yscale = 0.124000; 
+             //float yoffset = -8.484802; 
+       
+             // 5 point Calibration coefficients - from tsc.idc 
+             float xscale = mCalibration.xscale; 
+              float xymix = mCalibration.xymix; 
+              float xoffset = mCalibration.xoffset; 
+              float yxmix = mCalibration.yxmix; 
+              float yscale = mCalibration.yscale; 
+              float yoffset = mCalibration.yoffset; 

+             float x_after_calib = (xscale * x_temp) + (xymix * y_temp) + xoffset; 
+             float y_after_calib = (yxmix * x_temp) + (yscale * y_temp) + yoffset; 
+       

+             LOGI("x_after_calib = %f, y_after_calib = %f\n xscale = %f, 
yoffset = %f\n", x_after_calib, y_after_calib, xscale, yoffset); 
+             x = x_after_calib; 
+             y = y_after_calib; 

+           } 
+           else  { 
+             x = float(in.x - mLocked.xOrigin) * mLocked.xScale; 
+              y = float(in.y - mLocked.yOrigin) * mLocked.yScale; 
+           } 

             // ToolMajor and ToolMinor 
             float toolMajor, toolMinor; 

Touchscreen soft-keyboard inputs were being mis-reported on my WVGA 
screen and with the patch, keypresses are more accurate. 

Regards 







0 0