1.tslib庫簡介
??tslib 是電阻式觸摸屏用于校準的一個軟件庫,是一個開源的程序,能夠為觸摸屏驅動獲得的采樣提供諸如濾波、去抖、校準等功能,通常作為觸摸屏驅動的適配層,為上層的應用提供了一個統一的接口。
2 相關工具安裝
??安裝必要工具libtool、automake、autoconf
$ sudo apt-get install libtool $ sudo apt-get install automake $ sudo apt-get install autoconf
3 tslib安裝步驟
系統環境
開發環境: Ubuntu18.04
目標開發板: Tiny4412
交叉編譯器: arm-linux-gcc
Linux內核: Linux3.5
??1.下載tslib庫源碼包,將源碼解壓到用戶目錄下。
tslib源碼下載地址:https://github.com/libts/tslib/releases
[wbyq@wbyq soft_work]$ tar xvf /mnt/hgfs/ubuntu/soft_pack/tslib-master.tar.gz #解壓 [wbyq@wbyq soft_work]$cd tslib-master/tslib-master/ #進入到源碼目錄下 [wbyq@wbyq tslib-master]$ ls
??2.configure配置,生成Makefile文件。
[wbyq@wbyq tslib-master]$ ./autogen.sh [wbyq@wbyq tslib-master]$ ./configure --host=arm-linux ac_cv_func_malloc_0_nonnull=yes --cache-file=arm-linux.cache --prefix=$PWD/_install
- -host=arm-linux - - -指定編譯器
- -prefix=$PWD/_install - - -指定安裝目錄
??3.編譯安裝。
[wbyq@wbyq tslib-master]$ make && make install
??編譯安裝好后會生成 _install 文件夾。
??生成的文件信息:
[wbyq@wbyq tslib-master]$ cd _install/ [wbyq@wbyq _install]$ tree . ├── bin │ ├── ts_calibrate │ ├── ts_harvest │ ├── ts_print │ ├── ts_print_raw │ └── ts_test ├── etc │ └── ts.conf ├── include │ └── tslib.h └── lib ├── libts-1.0.so.0 -> libts-1.0.so.0.0.0 ├── libts-1.0.so.0.0.0 ├── libts.la ├── libts.so -> libts-1.0.so.0.0.0 ├── pkgconfig │ ├── tslib-1.0.pc │ └── tslib.pc └── ts ├── arctic2.la ├── arctic2.so ├── collie.la ├── collie.so ├── corgi.la ├── corgi.so ├── dejitter.la ├── dejitter.so ├── dmc.la ├── dmc.so ├── galax.la ├── galax.so ├── h3600.la ├── h3600.so ├── input.la ├── input.so ├── linear_h2200.la ├── linear_h2200.so ├── linear.la ├── linear.so ├── mk712.la ├── mk712.so ├── pthres.la ├── pthres.so ├── tatung.la ├── tatung.so ├── touchkit.la ├── touchkit.so ├── ucb1x00.la ├── ucb1x00.so ├── variance.la └── variance.so 6 directories, 45 files
?4.拷貝bin目錄下的文件到開發板/bin目錄下。
[wbyq@wbyq _install]$ cp bin/* /home/wbyq/soft_work/rootfs/bin/
?5.拷貝lib目錄下的.so文件到開發板的/lib目錄下。
[wbyq@wbyq _install]$ cp lib/*.so* /home/wbyq/soft_work/rootfs/lib/ -rfdv [wbyq@wbyq _install]$ cp lib/ts/ /home/wbyq/soft_work/rootfs/lib/ -rfdv
??6.拷貝etc/ts.conf文件到開發板的/etc目錄下。
[wbyq@wbyq _install]$ cp etc/ts.conf /home/wbyq/soft_work/rootfs/etc/
? 7.修改配置文件。
??如果希望使用linux輸入層事件接口,需要取消module_raw input 注釋。
[wbyq@wbyq _install]$ vim /home/wbyq/soft_work/rootfs/etc/ts.conf
??8.配置開發板的的啟動文件 profile。
[wbyq@wbyq _install]$ vim /home/wbyq/soft_work/rootfs/etc/profile
export set TSLIB_TSDEVICE=/dev/input/event2 #設置觸摸屏設備節點 export set TSLIB_CONFFILE=/etc/ts.conf #配置文件環境變量 export set TSLIB_PLUGINDIR=/lib/ts #指定tslib插件目錄 export set TSLIB_CALIBFILE=/etc/pointercal #指定校準之后,信息保存的位置(會自動生成) export set TSLIB_CONSOLEDEVICE=none #指定控制臺設備文件名字,默認沒有。填none export set TSLIB_FBDEVICE=/dev/fb0 #屏幕設備節點
注意: 設置完環境變量之后,需要重啟開發板生效,或者使用 source 命令立即生效。
4 開發板運行效果
??安裝觸摸屏驅動,檢查觸摸屏設備節點是否為上面設置的event2,運行ts_test。
[root@wbyq code]# insmod ft5x06_dev.ko [ 759.390000] IIC子系統:設備層注冊成功 [root@wbyq code]# insmod ft5x06_drv.ko [ 762.175000] IIC子系統:驅動層注冊成功 [ 762.175000] 資源匹配成功 [ 762.175000] input: Unspecified device as /devices/virtual/input/input3 [root@wbyq code]# ts_test 874.277420: 388 354 1 874.322712: 384 352 1 874.337917: 369 348 1 874.353162: 355 346 1 874.368397: 332 343 1 874.383524: 304 339 1 874.398664: 277 337 1 874.413889: 258 336 1 874.429156: 243 335 1 874.444247: 234 334 1 874.474649: 230 333 1 874.489914: 236 330 1 874.504974: 248 328 1
??tslib中提供的測試命令,是通過ts.config文件讀取相應的觸摸屏配置信息和LCD屏配置信息。
5 調用tslib庫獲取觸摸屏坐標
#include #include #include #include #include #include #include #include "tslib.h" int main(int argc,char *argv[]) { struct tsdev *ts; char *tsdevice=NULL; /*打開觸摸屏設備節點*/ if( (tsdevice = getenv("TSLIB_TSDEVICE")) != NULL ) { ts = ts_open(tsdevice,0); } else { ts = ts_open("/dev/input/event2",0); } if(ts==NULL) { perror("ts_open"); exit(1); } if (ts_config(ts)) { perror("ts_config"); exit(1); } struct ts_sample samp; int ret; printf(" 時間 t X坐標 t Y坐標t壓力值 n"); while (1) { ret = ts_read(ts, &samp, 1); if (ret < 0) { perror("ts_read"); exit(1); } if (ret != 1) continue; printf("[%ld.%06ld] %6d %6d %6dn", samp.tv.tv_sec, samp.tv.tv_usec, samp.x, samp.y, samp.pressure); } return 0; }
程序編譯:
cflags=-I/home/wbyq/soft_work/tslib-master/tslib-master/_install/include #指定頭文件 cflags+=-L/home/wbyq/soft_work/tslib-master/tslib-master/_install/lib #指定庫文件路徑 cflags+=-lts #指定庫 app: arm-linux-gcc app.c -o app $(cflags)
運行效果:
[root@wbyq code]# ./app 時間 X坐標 Y坐標 壓力值 [4591.061816] 337 369 1 [4591.124190] 337 369 0 [4592.426659] 512 399 1 [4592.502302] 507 400 1 [4592.517474] 503 401 1 [4592.532512] 500 403 1 [4592.547776] 494 405 1 [4592.562922] 489 408 1 [4592.578111] 483 410 1 [4592.593260] 479 412 1 [4592.624739] 475 415 1 [4592.655903] 472 417 0 [4592.972564] 442 402 1 [4593.063510] 445 402 1 [4593.078637] 449 402 1 [4593.093764] 452 403 1 [4593.109025] 459 404 1 [4593.124148] 465 404 1
-
嵌入式
+關注
關注
5092文章
19177瀏覽量
307647 -
觸摸屏
+關注
關注
42文章
2316瀏覽量
116764 -
移植
+關注
關注
1文章
383瀏覽量
28193 -
編譯器
+關注
關注
1文章
1642瀏覽量
49283 -
編譯
+關注
關注
0文章
661瀏覽量
33040
發布評論請先 登錄
相關推薦
評論