tslib库的移植

简介: tslib库的移植

tslib库的移植

1. 下载

下载地址:github仓库

2. 将下载好的压缩包移动到linux虚拟机上,并解压,进入该目录

tar -xJf tslib-1.21.tar.xz
cd tslib-1.21

3. 执行configure来配置Makefile文件

注意: prefix不能随便指明路径,因为以后运行程序的时候,程序会根据该路径去寻找库文件。如果打算将编译好的lib下所有的库文件放在开发板的/lib下,

那么就应该将prefix设置为/;如果打算将编译好的lib下的所有库文件放在开发板的/usr/lib下,那么就应该将prefix设置为/usr

./configure --host=arm-linux-gnueabihf prefix=/

4. 执行make编译库

make DESTDIR=/home/hxd/tools/tslib   # DESTDIR用于指定你的安装位置
make install

5. 将编译好的文件配置到编译工具链

该步骤可做可不做,做了以后编译程序的时候可以不用手动指定需要该库的库文件路径和头文件路径

关于将编译好的库放在那个位置,可以查看这篇文章的1.5小节: https://blog.csdn.net/weixin_47024013/article/details/125527484

cp /home/hxd/tools/tslib/include/* -rfd /usr/lib/gcc-cross/arm-linux-gnueabihf/9/include/   # 第一个路径与你指定的库的安装路径有关
cp /home/hxd/tools/tslib/lib/* -rfd /usr/lib/gcc-cross/arm-linux/gnueabihf/9/
cp /home/hxd/tools/tslib/etc/* -rfd /etc/

6. 将编译好的库配置到开发板上

我们只需要将lib文件夹的所有文件放在开发板的/lib文件夹下(/lib还是/usr/lib取决于你的第三步)

先将tslib文件夹复制nfs的目录下,然后开发板挂载该nfs,也可以通过其他方式将文件拷贝到服务器上
cp -rfd /mnt/tslib/lib/* /lib

7. 实例

7.1 单点触摸

#include<stdio.h>
#include<stdlib.h>
#include<tslib.h>
int main()
{
  struct tsdev *ts = NULL;  // 设备句柄
  struct ts_sample samp;
  int pressure = 0;
  ts = ts_setup(NULL, 0);
  if (ts == NULL) {
    fprintf(stderr, "ts_setup error\n");
    exit(-1);
  }
  for(;;) {
    if (0 > ts_read(ts, &samp, 1)) {
      fprintf(stderr, "ts_read error\n");
      exit(-1);
    }
    if (samp.pressure > 0) {
      if (pressure > 0) {
        printf("移动(%d, %d)\n", samp.x, samp.y);
      } else {
        printf("按下(%d, %d)\n", samp.x, samp.y);
      }
      pressure = samp.pressure;
    } else if (samp.pressure == 0 && pressure > 0) {
      printf("松开(%d, %d)\n", samp.x, samp.y);
      pressure = samp.pressure;
    }
  }
}

7.2 多点触摸

#include<stdio.h>
#include<stdlib.h>
#include<sys/ioctl.h>
#include<linux/input.h>
#include<tslib.h>
#include<string.h>
int main()
{
  struct tsdev *ts = NULL;
  struct ts_sample_mt *mt_ptr = NULL;
  struct ts_sample_mt *mt_old = NULL;
  struct input_absinfo slot;
  int max_slots;
  int i = 0;
  // 初始化
  ts = ts_setup(NULL, 0);
  if (ts < 0) {
    printf("setup error\n");
    return -1;
  }
  // 获取该触摸屏支持的触摸点数
  if (0 > ioctl(ts_fd(ts), EVIOCGABS(ABS_MT_SLOT), &slot)) {
    printf("ioctl error\n");
    return -1;
  }
  max_slots = slot.maximum - slot.minimum + 1;
  printf("max_slots: %d\n", max_slots);
  // 开辟空间
  mt_ptr = (struct ts_sample_mt *)malloc(sizeof(struct ts_sample_mt)*max_slots);
  mt_old = (struct ts_sample_mt *)malloc(sizeof(struct ts_sample_mt)*max_slots);
  if (mt_ptr == NULL || mt_old == NULL) {
    printf("malloc error\n");
    return -1;
  }
  memset(mt_ptr, 0, sizeof(struct ts_sample_mt)*max_slots);
  memset(mt_old, 0, sizeof(struct ts_sample_mt)*max_slots);
  for(;;) {
    if (ts_read_mt(ts, &mt_ptr, max_slots, 1) < 0) {
      printf("ts_read_mt error\n");
      exit(-1);
    }
    //printf("-------debug---------\n");
    for (i=0;i<max_slots;i++) {
      if (mt_ptr[i].valid) {
        printf("i: %d\n", i);
        if (mt_ptr[i].pressure > 0) {
          if (mt_old[i].pressure > 0) {
            printf("slot<%d>, 移动(%d, %d)\n", mt_ptr[i].slot, mt_ptr[i].x, mt_ptr[i].y);
          } else {
            printf("slot<%d>, 按下(%d, %d)\n", mt_ptr[i].slot, mt_ptr[i].x, mt_ptr[i].y);
          }
          memcpy(&mt_old[i], &mt_ptr[i], sizeof(struct ts_sample_mt));
        } else {
          printf("slot<%d>, 松开(%d, %d)\n", mt_ptr[i].slot, mt_ptr[i].x, mt_ptr[i].y);
          memcpy(&mt_old[i], &mt_ptr[i], sizeof(struct ts_sample_mt));
        }
      }
    }
  }
  free(mt_ptr);
  free(mt_old);
  return 0;
}


目录
相关文章
|
C#
WPF技术之BorderBrush和BorderThickness
在WPF中,BorderBrush和BorderThickness是用于创建和定义控件边框的两个属性。
1747 0
|
Web App开发 Linux 开发工具
Centos7 yum 安装chrome
Centos7 yum 安装chrome配置yum源vim /etc/yum.repos.d/google-chrome.repo写入以下内容[google-chrome]name=google-chromebaseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearchenabled=1gpgcheck=1gpgkey=http...
957 0
|
算法 编译器 程序员
Windows下Boost库的安装与使用
Windows下Boost库的安装与使用
3174 0
Windows下Boost库的安装与使用
|
8月前
|
人工智能 自然语言处理 算法
"一丹一世界"一等奖 | 曙光_麦橘超然 创作分享
"一丹一世界"一等奖 | 曙光_麦橘超然 创作分享
203 4
|
9月前
|
机器学习/深度学习 运维 监控
万亿参数模型训练神器:Kubeflow 2025量子加速版下载与TPU集群配置详解
Kubeflow 2025 是一个云原生机器学习操作系统,实现了四大突破性创新:量子混合训练(支持经典-量子混合神经网络协同计算)、神经符号系统集成(融合深度学习与逻辑推理引擎)、边缘智能联邦(5G MEC节点自动弹性扩缩容)和因果可解释性框架(集成Pearl、DoWhy等工具链)。该平台通过混合计算架构、先进的硬件配置矩阵和量子增强型安装流程,提供了从基础设施预配置到核心组件安装和安全加固的完整部署方案。此外,Kubeflow 2025 还涵盖全生命周期开发实战案例、智能运维监控体系、安全与合规框架以及高阶调试技巧,帮助用户高效构建和管理复杂的机器学习项目。
|
调度
【LVGL快速入门】LVGL开源框架入门教程之框架移植(四)
【LVGL快速入门】LVGL开源框架入门教程之框架移植(四)
850 3
|
算法 测试技术 异构计算
【SAM模型超级进化】MobileSAM轻量化的分割一切大模型出现,模型缩小60倍,速度提高40倍,效果不减
【SAM模型超级进化】MobileSAM轻量化的分割一切大模型出现,模型缩小60倍,速度提高40倍,效果不减
|
程序员 Python
Python Qt GUI设计:QScrollBar类实现窗口水平或垂直滑动条效果(拓展篇—4)
使用QScrollBar可以在窗口控件提供了水平的或垂直的滚动条,这样可以扩大当前窗口的有效装载面积,从而装载更多的控件。
|
测试技术 API
Eolink 全新一代「AI+API」协作管理平台,大模型驱动打造 API 研发管理与自动化测试
行业首发!Eolink 全新一代「AI+API」协作管理平台,实现「AI+API」结合,大模型驱动打造 API 研发管理与自动化测试全新体验。 Eolink 「AI+API」为 API 带来什么? 输入语义化指令即可生成 API 文档内容; 在 API 文档测试页中可一键生成测试请求数据; 可实现圈定 API 文档范围智能生成测试方案,自动生成流程测试用例,并提供 API 拓扑图展示
419 0
Eolink 全新一代「AI+API」协作管理平台,大模型驱动打造 API 研发管理与自动化测试
|
安全 Windows
keil5安装教程
keil5安装教程
1501 0
keil5安装教程