安卓 IIO 传感器 [英] Android IIO sensors
问题描述
如何在 Android Nougat 上捕获由 iio 传感器在应用级别和本机级别(例如来自 adb shell 或通过现有守护进程)生成的 iio_events
?(例如环境光传感器的 in_intensity_falling_threshold 事件)
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 ? (for instance in_intensity_falling_threshold event of an ambient light sensor)
我尝试了经典方法:SensorManager Listener(我自己编写了一个测试应用程序,但也尝试了应用商店中的几个 sensortest 应用程序).
I tried the classical way: SensorManager Listener (I wrote myself a test app but also tried several sensortest apps from app store).
不过似乎 iio 传感器不会触发任何事件(尽管我可以从 sysfs 读取不断变化的数据).
However it seems iio sensors do not trigger any event (although I can read the changing data from sysfs).
iio 设备是否也创建与 Android 中的输入设备相同类型的事件?我应该能够通过 getevent 命令查看事件吗?(如果需要,我可以提供更具体的系统/传感器信息.)
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 ? (I can give more specific system/sensor information if needed.)
推荐答案
让我分享我的所学和经历:
Let me share what i have learned and experienced:
关于如何捕获 iio 事件的简短回答是,它取决于传感器的内核驱动程序和 Android 上的 Sensor-HAL.
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 事件 是由基于硬件的中断驱动的;例如,当有新数据时,连接到板并被板识别的传感器上的中断引脚向板发送信号.
First of all an iio event is driven by an hw-based interrupt ; an interrupt pin on sensor connected to and recognized by board sends signal to the board when for instance there is new data .
其次,传感器管理器/服务不直接与驱动程序通信.它侦听的是 Sensor-HAL.Sensor-HAL 为 Sensor Service 生成事件,而不是直接为驱动程序自身生成事件.这意味着 SensorHAL 应该从 sysfs(由驱动程序创建的文件接口)读取数据并将该数据返回给 Sensor Service 调用(请参阅 poll() , sensor_eventhttps://android.googlesource 中的结构.com/platform/hardware/libhardware/+/master/include/hardware/sensors.h )
Second , the Sensor Manager/Service does not communicate with the driver directly. What it listens is 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 )
最后,catchevent 只针对定义为中断设备的设备(如触摸屏)产生的中断事件".Interrupt、iio 和 hwmon 是 linux 内核中不同类型的基于设备 sw 的结构.
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.
结论:如果您有一个新传感器并想在 Android 中从中捕获/读取数据,您应该
Conclusion : If you have a new sensor and want to catch/read data from it in Android, you should
1.find/用合适的设备模型(输入、iio、hwmon等)编写驱动程序
1.find/ write a driver with a suitable device model(input, iio,hwmon etc.)
2.使电路板识别设备(通过向设备树或电路板配置文件添加信息)
2.make the board recognize the device (by adding information to the device tree or board config. file )
3.找到/编写合适的 Sensor-HAL 或将传感器添加到现有 HAL.
3.find/write a suitable Sensor-HAL or add the sensor to the existing HAL.
只有在这一步之后,应用才能通过 SensorListener 获取传感器数据.
Only after this steps an app can reach sensor data through SensorListener.
如何从本机级别捕获/测试事件捕获:找不到捕获事件的直接方法.获取传感器数据的一般本机方法(在添加适当的驱动程序并让电路板识别设备之后)是使用 sysfs 接口.
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.
例如,来自 android 设备 shell(以 root 身份):
For instance ,from android device shell (as 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
这篇关于安卓 IIO 传感器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!