问题现象:

当休眠后,再次打开preesure sensor的时候,会出现隔一段时候后,APK才会出现数据;(数据有时候会很难出现)

问题分析:

从上面几节中,我们可以知道,framework到HAL是通过调用sensors.msm8909.so调用到函数PressureSensor::readEvents中取出的;

  1. int PressureSensor::readEvents(sensors_event_t* data, int count)
  2. {
  3. int i = 0;
  4. if (count < 1)
  5. return -EINVAL;
  6. if (mHasPendingEvent) {
  7. mHasPendingEvent = false;
  8. mPendingEvent.timestamp = getTimestamp();
  9. *data = mPendingEvent;
  10. return mEnabled ? 1 : 0;
  11. }
  12. if (mHasPendingMetadata) {
  13. mHasPendingMetadata--;
  14. meta_data.timestamp = getTimestamp();
  15. *data = meta_data;
  16. return mEnabled ? 1 : 0;
  17. }
  18. ssize_t n = mInputReader.fill(data_fd);
  19. if (n < 0)
  20. return n;
  21. int numEventReceived = 0;
  22. input_event const* event;
  23. #if FETCH_FULL_EVENT_BEFORE_RETURN
  24. again:
  25. #endif
  26. while (count && mInputReader.readEvent(&event)) {
  27. int type = event->type;
  28. if (type == EV_ABS) {
  29. float value = event->value;
  30. mPendingEvent.pressure = value * CONVERT_PRESSURE;
  31. ALOGI("the pressure is %f\n", mPendingEvent.pressure);
  32. } else if (type == EV_SYN) {
  33. switch (event->code) {
  34. case SYN_TIME_SEC:
  35. mUseAbsTimeStamp = true;
  36. report_time = event->value*1000000000LL;
  37. break;
  38. case SYN_TIME_NSEC:
  39. mUseAbsTimeStamp = true;
  40. mPendingEvent.timestamp = report_time+event->value;
  41. break;
  42. case SYN_REPORT:
  43. if(mUseAbsTimeStamp != true) {
  44. mPendingEvent.timestamp = timevalToNano(event->time);
  45. }
  46. if (mEnabled) {
  47. // ALOGI("timestamp = %ld mEnabledTime = %ld mUseAbsTimeStamp = %d enable here\n", mPendingEvent.timestamp, mEnabledTime, mUseAbsTimeStamp);
  48. // if (mPendingEvent.timestamp >= mEnabledTime)
  49. {
  50. *data = mPendingEvent;
  51. ALOGI("data pressure is %f\n", data->pressure);
  52. // data++;
  53. numEventReceived++;
  54. }
  55. count--;
  56. }
  57. break;
  58. }
  59. } else {
  60. ALOGE("PressureSensor: unknown event (type=%d, code=%d)",
  61. type, event->code);
  62. }
  63. mInputReader.next();
  64. }
  65. #if FETCH_FULL_EVENT_BEFORE_RETURN
  66. /* if we didn't read a complete event, see if we can fill and
  67. try again instead of returning with nothing and redoing poll. */
  68. if (numEventReceived == 0 && mEnabled == 1) {
  69. n = mInputReader.fill(data_fd);
  70. if (n)
  71. goto again;
  72. }
  73. #endif
  74. ALOGI("end the data the pressure is %f\n", mPendingEvent.pressure);
  75. return numEventReceived;
  76. }

增加if (mPendingEvent.timestamp >= mEnabledTime)判断是为了判断SYN_REPORT不延迟的情况;

mPendingEvent.timestamp在这里被赋值:

  1. input_event const* event;
  2. //这个可以一直进来
  3. if(mUseAbsTimeStamp != true) {
  4. mPendingEvent.timestamp = timevalToNano(event->time);
  5. }

event->time代表了按键时间;可以用struct timeval获取系统时间。

其中input_eventtimeval结构体如下:

  1. struct input_event {
  2. struct timeval time; //按键时间
  3. __u16 type; //类型,在下面有定义
  4. __u16 code; //要模拟成什么按键
  5. __s32 value;//是按下还是释放
  6. };
  7. struct timeval {
  8. __kernel_time_t tv_sec; /* seconds */
  9. __kernel_suseconds_t tv_usec; /* microseconds */
  10. };
  1. //将时间转换为ns
  2. static int64_t timevalToNano(timeval const& t) {
  3. return t.tv_sec*1000000000LL + t.tv_usec*1000;
  4. }

通过打印可以知道问题出现的时候mPendingEvent.timestamp是小于mEnabledTime的,进不了判断,所以上层也就无法获取相应的数据;

mEnabledTime是在int PressureSensor::enable(int32_t, int en)函数中实现:

  1. ....
  2. mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
  3. ....
  1. int64_t SensorBase::getTimestamp() {
  2. struct timespec t;
  3. t.tv_sec = t.tv_nsec = 0;
  4. clock_gettime(CLOCK_BOOTTIME, &t);
  5. return int64_t(t.tv_sec)*1000000000LL + t.tv_nsec;
  6. }
  7. //不过CLOCK_BOOTTIME计算系统suspend的时间,也就是说,不论是running还是suspend(这些都算是启动时间),CLOCK_BOOTTIME都会累积计时,直到系统reset或者shutdown。

所以在睡眠起来后mEnabledTime会大于mPendingEvent.timestamp,所以此时是没有上报数据的;将判断去掉即可;

patch地址

patch

高通非adsp 架构下的sensor的bug调试的更多相关文章

  1. 高通adsp架构下sensor

    一.高通sensor架构: linux驱动由浅入深系列:高通sensor架构实例分析之一(整体概览+AP侧代码分析) linux驱动由浅入深系列:高通sensor架构实例分析之二(adsp驱动代码结构 ...

  2. 高通Android display架构分析

    目录(?)[-] Kernel Space Display架构介绍 函数和数据结构介绍 函数和数据结构介绍 函数和数据结构介绍 数据流分析 初始化过程分析 User Space display接口 K ...

  3. 高通camera基本代码架构【转】

    本文转载自:http://blog.sina.com.cn/s/blog_c0de2be70102vyn1.html 1  camera基本代码架构 高通平台对于camera的代码组织,大体上还是遵循 ...

  4. 在高通平台Android环境下编译内核模块【转】

    本文转载自:http://blog.xeonxu.info/blog/2012/12/04/zai-gao-tong-ping-tai-androidhuan-jing-xia-bian-yi-nei ...

  5. 【转】高通平台android 环境配置编译及开发经验总结

    原文网址:http://blog.csdn.net/dongwuming/article/details/12784535 1.高通平台android开发总结 1.1 搭建高通平台环境开发环境 在高通 ...

  6. 高通安卓调试LCD几方面总结

    来公司上班现在已经整整一个月了,蔽人不才,能力有限,学习进度缓慢,不过也是有一点点的收获与心得,在这里写出来与大家分享,养成良好的记录习惯也免得后忘记. 不啰嗦了,开入正题.来公司一个月左右的时间,主 ...

  7. linux驱动由浅入深系列:高通sensor架构实例分析之三(adsp上报数据详解、校准流程详解)【转】

    本文转载自:https://blog.csdn.net/radianceblau/article/details/76180915 本系列导航: linux驱动由浅入深系列:高通sensor架构实例分 ...

  8. linux驱动由浅入深系列:高通sensor架构实例分析之二(驱动代码结构)【转】

    本文转载自:https://blog.csdn.net/radianceblau/article/details/73498303 本系列导航: linux驱动由浅入深系列:高通sensor架构实例分 ...

  9. 高通HAL层之Sensor HAL

    高通的HAL层其实分为两种,一种是直接从kernel这边报数据上来的,由sensor HAL层来监听,另一种是走ADSP的模式,HAL层是通过qmi的形式进行监听的: 走ADSP架构的可以看下面的博客 ...

随机推荐

  1. JAVA中的COPYONWRITE容器

    Copy-On-Write简称COW,是一种用于程序设计中的优化策略.其基本思路是,从一开始大家都在共享同一个内容,当某个人想要修改这个内容的时候,才会真正把内容Copy出去形成一个新的内容然后再改, ...

  2. oracle中查询用户表/索引/视图创建语句

    不多说,直接上干货 1.查询当前用户下表的创建语句 select dbms_metadata.get_ddl('TABLE','ux_future') from dual; 2.查询其他用户下表的创建 ...

  3. 【Java基本功】一文读懂final关键字的用法

    本文主要介绍了final关键字的基本使用方法及原理 final关键字可以修饰类.方法和引用. 修饰类,该类不能被继承.并且这个类的对象在堆中分配内存后地址不可变. 修饰方法,方法不能被子类重写. 修饰 ...

  4. Vue + Element UI 实现权限管理系统 前端篇(十一):第三方图标库

    使用第三方图标库 用过Elment的同鞋都知道,Element UI提供的字体图符少之又少,实在是不够用啊,幸好现在有不少丰富的第三方图标库可用,引入也不会很麻烦. Font Awesome Font ...

  5. Ribbon使用Hystrix

    1.导入依赖spring-cloud-starter-hystrix <dependency> <groupId>org.springframework.cloud</g ...

  6. SpringBoot2.0源码分析(一):SpringBoot简单分析

    SpringBoot2.0简单介绍:SpringBoot2.0应用(一):SpringBoot2.0简单介绍 本系列将从源码角度谈谈SpringBoot2.0. 先来看一个简单的例子 @SpringB ...

  7. mysql 循环

    DELIMITER $$ DROP PROCEDURE IF EXISTS student_insert_while; $$ ), in birthday date, in age int) begi ...

  8. 设计模式教程(Design Patterns Tutorial)笔记之三 行为型模式(Behavioral Patterns)

    目录 · Strategy · When to use the Strategy Design Pattern? · Sample Code · Observer · When to use the  ...

  9. python文件处理b模式

    执行环境:windows+Python3.51.rb模式,从文件中读取内容,得到的是bytes类型 因为我们使用的是b模式,所以在open函数中不能指定编码格式,所以打印出来的格式的二进制的格式,而我 ...

  10. SpringBoot入门之Thymeleaf的使用

    在.net的MVC3 或更高版本等支持 Razor 的框架里使用cshtml,Razor是一种简单的编程语法,用于在网页中嵌入服务器端代码.在使用springboot开发mvc时也有与.net类似的视 ...