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)
I tried the classical way: SensorManager Listener (I wrote myself a test app but also tried several sensortest apps from app store).
However it seems iio sensors do not trigger any event (although I can read the changing data from 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 ? (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.
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 .
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 )
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.
Conclusion : If you have a new sensor and want to catch/read data from it in Android, you should
1 .find/ write a driver with a suitable device model(input, iio,hwmon etc.)
2 .make the board recognize the device (by adding information to the device tree or board config. file )
3 .find/write a suitable Sensor-HAL or add the sensor to the existing HAL.
Only after this steps an app can reach sensor data through 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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.