linux的触摸屏之三:解析android平台上的tslib过程

(1)在tslib目录下有设置环境变量的文本文件:settsenv.sh,内容:

export T_ROOT=/system

export LD_LIBRARY_PATH=$T_ROOT/lib

export TSLIB_CONSOLEDEVICE=

export TSLIB_FBDEVICE=/dev/graphics/fb0

export TSLIB_TSDEVICE=/dev/input/event1

export TSLIB_PLUGINDIR=$T_ROOT/lib/ts

export TSLIB_CONFFILE=$T_ROOT/etc/tslib/ts.conf

export TSLIB_CALIBFILE=/data/data/pointercal

设定的TSLIB的TS设备,FB设备,配置文件,动态库文件的路径。当然,具体的要用的可以在程序代码中重新设定。

(2)tslib目录下的etc目录ts.conf是配置文件,内容:

# Uncomment if you wish to use the linux input layer event interface
module_raw input1

# Uncomment if you're using a Sharp Zaurus SL-5500/SL-5000d
# module_raw collie

# Uncomment if you're using a Sharp Zaurus SL-C700/C750/C760/C860
# module_raw corgi

# Uncomment if you're using a device with a UCB1200/1300/1400 TS interface
# module_raw ucb1x00

# Uncomment if you're using an HP iPaq h3600 or similar
# module_raw h3600

# Uncomment if you're using a Hitachi Webpad
# module_raw mk712

# Uncomment if you're using an IBM Arctic II
# module_raw arctic2

module pthres pmin=1
module variance delta=30
module dejitter delta=100
module linear
可见,上面有很多模块可以调用,最终是选择了input1,也即是linux的input获取方式。这些模块的源代码在plugins目录下都有定义。

(3)分析流程,接触摸屏分析之一,在ts_main中:

void get_sample (struct tsdev *ts, calibration *cal,   int index, int x, int y, char *name) 

{

       put_cross(x, y, 2 | XORMODE);   //画十字座标

       getxy (ts, &cal->x [index], &cal->y [index]); //取得x,y的LCD坐标值

       put_cross(x, y, 2 | XORMODE);

 

       last_x = cal->xfb [index] = x; 
       last_y = cal->yfb [index] = y;        //赋值cal的触摸屏坐标

}

(4)解析getxy

struct ts_sample {
     int  x;
     int  y;
     unsigned int pressure;
     struct timeval tv;
};

void getxy(struct tsdev *ts, int *x, int *y)

{

       #define MAX_SAMPLES 128
       struct ts_sample samp[MAX_SAMPLES];     //采样128次

       do

       {
              if (index < MAX_SAMPLES-1)
                   index++;
              if (ts_read_raw(ts, &samp[index], 1) < 0) {    //循环读取采样数据保存到samp数组中
                   close_framebuffer ();
                   exit(1);
               }
        } while (samp[index].pressure > 0);//(samp[0].pressure == 0);

       //然后根据采样的samp值运算得到*x,*y。

}

int ts_read_raw(struct tsdev *ts, struct ts_sample *samp, int nr)
{
       int result = ts->list_raw->ops->read(ts->list_raw, samp, nr);  //执行采样读函数
       return result;
}
(5)那上述最后的函数指针是在哪里执行的呢?可以回溯到tsmain函数里面的ts_config,它用来配置ts设备。

int ts_config(struct tsdev *ts)

{

         //读取ts.conf文件

         if (strcasecmp(tok, "module") == 0) {
                module_name = strsep(&p, " /t");
                ret = ts_load_module(ts, module_name, p);    

         }
         else if (strcasecmp(tok, "module_raw") == 0) {
                module_name = strsep(&p, " /t");
                ret = ts_load_module_raw(ts, module_name, p);
         }                                                //选择确定的模块加入,选择的是input1
}

载入模块的函数定义:

int ts_load_module(struct tsdev *ts, const char *module, const char *params)
{
      return __ts_load_module(ts, module, params, 0);
}

int ts_load_module_raw(struct tsdev *ts, const char *module, const char *params)
{
      return __ts_load_module(ts, module, params, 1);
}
int __ts_load_module(struct tsdev *ts, const char *module, const char *params, int raw)

{

      char fn[1024];

      struct tslib_module_info *info;

      strcpy(fn,getenv("TSLIB_PLUGINDIR"));   //TSLIB_PLUGINDIR=$T_ROOT/lib/ts

      strcat(fn, "/");
      strcat(fn, module);
      strcat(fn, ".so");

 

      void *handle = dlopen(fn, RTLD_NOW);   

      init = dlsym(handle, "mod_init");     //获得特定的mod_init,也即input-raw.c这个文件模块

      info = init(ts, params);                              //用params初始化ts。

      __ts_attach(ts, info);                               //再将info与ts绑定

}

(6)接着看input-raw.c里面的处理。

mod_init()-》i->module.ops = &__ts_input_ops;

static const struct tslib_ops __ts_input_ops = {
      .read = ts_input_read,
      .fini = ts_input_fini,
};

这里的read指针的赋值函数就是(4)末尾要执行的那个。

static int ts_input_read(struct tslib_module_info *inf,struct ts_sample *samp, int nr)

{

      struct tslib_input *i = (struct tslib_input *)inf;    //从特定的input1的所在功能模块获得inf参数输入,也即触摸屏参数转化后

      struct input_event ev;

      struct tsdev *ts = inf->dev;

      read(ts->fd, &ev, sizeof(struct input_event));   //读入ts设备 特定的input event信息

 

      samp->x = i->current_x = ev.value;
      samp->y = i->current_y;
      samp->pressure = i->current_p;                      //赋给samp的值,从而获得LCD的x,y

}

到这步为止,获得了完整的5个点的LCD参数。

(7)真正的校正函数perform_calibration:

perform_calibration(calibration *cal) 通过传入的cal所带的5个点的XY两个方向的触摸屏值和LCD值,经过运算得到最终的7个cal.a[7]参数。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用:D:\Linux-4.9.88.tar\Linux-4.9.88\include\uapi\linux input.h 。 引用:cp -d lib/*so* /home/book/100ask_imx6ull-sdk/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/lib/ (2)板子上测试编译 。 引用:1,上网搞个源码库,如果你可爱到不会用百度,没关系,戳我下载( http://download.csdn.net/detail/vincent040/9662825 )。 2,将源代码丢到Ubuntu,并通过以下命令解压到Ubuntu的家目录下: tar xjvf tslib-1.4.tar.bz2 -C ~ 3,进入源码顶层目录,依次执行如下命令: mkdir ~/tslib ./configure --prefix=/home/xxx/tslib --host=arm-none-linux-gnueabi make make install A) --prefix= 后面的路径就是你要安装 tslib 库的路径,墙裂建议设置为家目录下的空目录(比如~/tslib),因为如果设置系统其它目录的话,后期 make install 的时候会让你解决权限的问题,当你自作聪明地使用sudo的时候,系统却又可能会抱怨找不到工具链,因此除非你是 Ubuntu科学家,对系统环境变量了如指掌,否则不要用小白的身份去作死,乖乖将 --prefix 指定为 ~/tslib 即可。 根据提供的引用内容,可以看出tslib是一个Linux上的触摸屏输入子系统库。它提供了在嵌入式系统中处理触摸屏输入的功能和接口。要安装tslib库,可以按照以下步骤进行操作:首先,下载源码库并将源代码解压到Ubuntu的家目录下;接着进入源码顶层目录,创建一个空目录(比如~/tslib)作为安装路径,并执行configure命令来配置安装参数;然后使用make命令编译源代码;最后使用make install命令安装tslib库到指定的安装路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值