简体   繁体   English

Android IIO传感器

[英]Android IIO sensors

How can I catch iio_events generated by iio sensors in app level and in native level( from adb shell for example or via an existing deamon) on Android Nougat ? 如何在Android Nougat上捕获应用程序级别和本机级别中的iio_events传感器生成的iio_events (例如,通过adb shell或通过现有的守护进程)? (for instance in_intensity_falling_threshold event of an ambient light sensor) (例如环境光传感器的in_intensity_falling_threshold事件)

I tried the classical way: SensorManager Listener (I wrote myself a test app but also tried several sensortest apps from app store). 我尝试了经典方式:SensorManager Listener(我为自己编写了一个测试应用程序,但还尝试了来自应用商店的多个sensortest应用程序)。

However it seems iio sensors do not trigger any event (although I can read the changing data from sysfs). 但是,看来iio传感器不会触发任何事件(尽管我可以从sysfs中读取变化的数据)。

Do iio devices also create the same type of event as input devices do in Android ?Should I be able to see the events through getevent command ? iio设备还会创建与Android中输入设备相同类型的事件吗?是否可以通过getevent命令查看事件? (I can give more specific system/sensor information if needed.) (如果需要,我可以提供更具体的系统/传感器信息。)

Let me share what i have learned and experienced: 让我分享我所学到的经验:

The short answer to how to catch iio events is, it depends on the kernel driver of the sensor and the Sensor-HAL on Android. 关于如何捕获iio事件的简短答案是,它取决于传感器的内核驱动程序和Android上的Sensor-HAL。

First of all an iio event is driven by an hw-based interrupt ; 首先,一个iio事件是由基于硬件的中断驱动的; an interrupt pin on sensor connected to and recognized by board sends signal to the board when for instance there is new data . 当连接到板并被板识别的传感器上的中断引脚在例如有新数据时向板发送信号。

Second , the Sensor Manager/Service does not communicate with the driver directly. 其次,传感器管理器/服务不直接与驱动程序通信。 What it listens is Sensor-HAL. 它所侦听的是Sensor-HAL。 The Sensor-HAL generates events for the Sensor Service , not the driver self directly.That means the SensorHAL should read the data from sysfs(file interfaces created by driver) and return that data to the Sensor Service calls (see poll() , sensor_event struct in https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/sensors.h ) Sensor-HAL会为Sensor Service生成事件,而不是直接为驱动程序self生成事件,这意味着SensorHAL应该从sysfs(由驱动程序创建的文件接口)读取数据,并将该数据返回给Sensor Service调用(请参见poll(),sensor_event https://android.googlesource.com/platform/hardware/libhardware/+/master/include/hardware/sensors.h中的结构)

At last, catchevent is only for "interrupt events" which are generated by devices defined as interrupt device(like touchscreen).Interrupt , iio and hwmon are different types of device sw-based structures in linux kernel. 最后,catchevent仅适用于由定义为中断设备(如触摸屏)的设备生成的“中断事件”。Interrupt,iio和hwmon是Linux内核中基于设备sw的结构的不同类型。

Conclusion : If you have a new sensor and want to catch/read data from it in Android, you should 结论 :如果您有一个新传感器,并且想在Android中捕获/读取数据,则应该

1 .find/ write a driver with a suitable device model(input, iio,hwmon etc.) 1。 查找/编写具有合适设备型号(输入,iio,hwmon等)的驱动程序

2 .make the board recognize the device (by adding information to the device tree or board config. file ) 2。 使板识别设备(通过将信息添加到设备树或板配置文件中)

3 .find/write a suitable Sensor-HAL or add the sensor to the existing HAL. 3。 查找/编写合适的Sensor-HAL或将传感器添加到现有的HAL中。

Only after this steps an app can reach sensor data through SensorListener. 仅在执行此步骤之后,应用程序才能通过SensorListener到达传感器数据。

how to catch/test the event catches from native level : Can not find a direct way to catch events. 如何从本机级别捕获/测试事件捕获:找不到捕获事件的直接方法。 The general native way to reach sensor data (after adding the proper driver and getting the board recognize the device ) is to use the sysfs interfaces. 获取传感器数据的常规方法(在添加适当的驱动程序并使开发板识别设备之后)是使用sysfs接口。

For instance ,from android device shell (as root): 例如,从android设备外壳(以root用户身份):

#sys/bus/iio/devices/iio:device0/ls
in_accel_x_raw   in_accel_y_raw   in_accel_z_raw   in_accel_scale ....
#cat in_accel_x_raw 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM