Powered by Drupal, an open source content management system

การแก้ไขปัญหา touch screen บน Mini2440 ของ xserver-xorg-input-tslib + X-window

การใช้ tslib บน X-window ของ Debian มีปัญหาซึ่งจำเป็นต้องแก้ไขและคอมไพล์โปรแกรมใหม่ บทความนี้จะแสดงถึงวิธีการดึงซอสโค๊ดและคอมไพล์ด้วยวิธีแบบ Debian ดังนี้

tslib เป็น Touch screen ที่ได้รับความนิยมเป็นอันดับต้นๆ แต่ lib สำหรับ x-window บน debian มีปัญหาในเรื่องของเสกล ซึ่งปัญหาเกิดจากบั๊กในซอสโค๊ดที่กำหนดขนาดของจอไว้คงที่ดังนี้ (ตัวหนังสือสีเขียวคือโค๊ดที่มีปัญหา สีน้ำเงินคือโค๊ดที่ได้รับการแก้ไข)


--- a/src/tslib.c   (revision 28)

04 +++ b/src/tslib.c   (working copy)
05 @@ -184,9 +184,11 @@
06     InputInfoPtr pInfo;
07     unsigned char map[MAXBUTTONS + 1];
08     int i;
09 +   struct ts_priv *priv;
10   
11     ErrorF("%s\n", __FUNCTION__);
12     pInfo = device->public.devicePrivate;
13 +   priv = pInfo->private;
14   
15     switch (what) {
16     case DEVICE_INIT:
17 @@ -222,15 +224,17 @@
18             return !Success;
19         }
20   
21 -       InitValuatorAxisStruct(device, 0, 0, /* min val */ 1023,    /* max val */
22 -                          1024,    /* resolution */
23 -                          0,   /* min_res */
24 -                          1024);   /* max_res */
25 +       InitValuatorAxisStruct(device, 0, 0,        /* min val */
26 +                          priv->width - 1,  /* max val */
27 +                          priv->width,  /* resolution */
28 +                          0,       /* min_res */
29 +                          priv->width); /* max_res */
30   
31 -       InitValuatorAxisStruct(device, 1, 0, /* min val */ 1023,    /* max val */
32 -                          1024,    /* resolution */
33 -                          0,   /* min_res */
34 -                          1024);   /* max_res */
35 +       InitValuatorAxisStruct(device, 1, 0,        /* min val */
36 +                          priv->height - 1,/* max val */
37 +                          priv->height, /* resolution */
38 +                          0,       /* min_res */
39 +                          priv->height);    /* max_res */

ดังนั้นเราจึงจำเป็นต้องแก้ไขโปรแกรมเพื่อให้อ่านค่าของขนาดจอจาก Option ของ xorg.conf  การคอมไพล์จะทำบน mini2440 โดยตรงไม่ผ่าน cross compiler

1. แก้ไขไฟล์  /etc/apt/sources.list โดยเพิ่มบรรทัดดังนี้หากยังไม่มี

deb-src http://ftp.de.debian.org/debian lenny main

2. ติดตั้งโปรแกรมที่เกี่ยวข้องเพื่อใช้ในการคอมไพล์  

# apt-get update
# apt-get install devscripts

3. ดึงซอสโค๊ดหลักและตัวที่เกี่ยวข้องด้วยคำสั่ง

# mkdir tslib
# cd tslib
# apt-get source xserver-xorg-input-tslib
# apt-get build-dep xserver-xorg-input-tslib

 4. ทำการ patch file

# wget http://www.project4fun.com/sites/default/files/tslibpatch/xf86-input-tslib-0.0.4.patch
# patch -p0 < xf86-input-tslib-0.0.4.patch

 

5. ตรวจสอบไฟล์ xf86-input-tslib-0.0.4/src/tslib.c ว่าได้ถูกแก้ไขเรียบร้อยดัง patch

6. ใช้คำสั่ง dch ในการกำหนดรายละเอียดของ version และ debuild เพื่อทำการสร้าง package ใหม่

# cd xf86-input-tslib-0.0.4
# dch -l local 'fixed-problem'
# debuild -us -uc

 

 7. หากไม่มีอะไรผิดพลาด เราก็จะได้ไฟล์ xserver-xorg-input-tslib_0.0.4-5local1_armel.deb ดังนี้

8. และก็ได้เวลาทดสอบแล้วครับ ถ้ายังไม่ได้ติดตั้ง x-window ก็ให้ติดตั้งตามนี้ครับ

# apt-get install xorg

9. หลังจากนั้นก็ติดตั้ง touch screen library ดังนี้

# apt-get install libts-0.0-0 libts-bin

10. ติดตั้ง package tslib สำหรับ x-window ที่เราสร้างขึ้นมาใหม่ดังนี้

# dpkg -i xserver-xorg-input-tslib_0.0.4-5local1_armel.deb

 11. แก้ไขไฟล์ /etc/profile เพื่อเพิ่มเติมเซ็ทอัพเมื่อรีบูทใหม่สำหรับ TouchScreen

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

export TSLIB_TSEVENTTYPE=input
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/etc/ts.conf
export TSLIB_PLUGINDIR=/usr/lib/ts

 

12. ทำการ export ค่าที่จำเป็นต่อการ Calibrate และเริ่มต้น Calibrate ด้วยคำสั่ง ts_calibrate หลังจากนั้นก็แตะจุดตามที่กำหนดบนจอ

13. โปรแกรม ts_calibrate จะสร้างไฟล์ /etc/pointercal มาเก็บค่าไว้ สามารถทดสอบด้วยคำสั่ง ts_test

14. ต่อไปก็จะเริ่มทดสอบกับ x-window ก่อนอื่นให้แก้ไขไฟล์ /etc/X11/xorg.conf ในส่วนของ Input Device ที่เกี่ยวกับ TouchScreen ดังนี้

section "ServerLayout"
        Identifier     "XFree86 Configured"
        Screen      0  "Screen0" 0 0
        InputDevice    "Mouse0"
        InputDevice    "Keyboard0" "CoreKeyboard"
        InputDevice    "Touchpad0" "CorePointer"
        Option      "OffTime" "10"
EndSection
 
Section "InputDevice"
# Change "XkbModel" to "macintosh_old" if you are using
# the deprecated adb keycodes.
        Identifier  "Keyboard0"
        Driver      "kbd"
        Option      "XkbModel" "pc105"
EndSection
 
Section "InputDevice"
        Identifier  "Touchpad0"
        Driver      "tslib"
        Option "CorePointer" "true"
        Option "TslibDevice" "/dev/input/event1"
        Option "DeviceName" "touchscreen"
 Option "ScreenNumber" "0"
 Option "Width" "240"
 Option "Height" "320"
 Option "Rotate" "0"
EndSection
 
Section "InputDevice"
       Identifier  "Mouse0"
       Driver      "mouse"
EndSection
Section "Monitor"
        Identifier   "Monitor0"
        ModelName    "Monitor Model"
        DisplaySize 240 320
EndSection
Section "Device"
        #Option "ShadowFB"      "true"
        Identifier  "Card0"
        Driver      "fbdev"
        Option  "fbdev" "/dev/fb0"
EndSection
Section "Screen"
        Identifier "Screen0"
        Device     "Card0"
        Monitor    "Monitor0"
EndSection

 

15. หลังจากนั้นก็ให้เริ่มต้น X-window ด้วยคำสั่งดังนี้

# X&

ซึ่งเมื่อแตะหน้าจอตัว x ก็จะวิ่งไปยังตำแหน่งที่แตะได้อย่างถูกต้อง

 

 

ไฟล์ที่เกี่ยวข้อง

xf86-input-tslib-0.0.4.patch

xserver-xorg-input-tslib_0.0.4-5local1_armel.deb

อ้างอิง

http://boundarydevices.com/blogs/debian-in-more-depth-adding-touch-support

http://www.debian.org/doc/FAQ/ch-pkg_basics.en.html

http://www.openminddev.net/projects/wiki/4/Debian_on_a_Chumby