Enabling Sensors in Celadon

This tutorial explains about sensors usage in project Celadon.

Sensors overview

Sensors are integrated into platforms powered by Intel using Integrated Sensor Hub (ISH). In the host OS, sensors are populated using the Linux IIO subsystem. If a platform has support for sensors, we can find the sensor devices in /sys/bus/iio/devices/. Please refer to https://docs.kernel.org/hid/intel-ish-hid.html for more information about the ISH module.

Sensors support in CiV

CiV has support for sensors and uses the sensor mediation HAL to access IIO-based sensor devices available on host OS. The current implementation of the mediation HAL is based on Android Sensor HAL 2.0. Figure 1 illustrates the block diagram of sensors implementation in CiV.

../_images/fig1-block-diagram-sensors.png

Figure 1: Block diagram of sensors in CiV

To communicate with Host OS IIO sensor devices, the mediation HAL uses the libiio library with a network back end. We require the libiio daemon (iiod) to be run on the host before launching CiV. The source code path of the sensors HAL is vendor/intel/hardware/interfaces/sensors/2.0 and the GitHub project reference is https://github.com/projectceladon/vendor-hardware-interfaces/tree/master/sensors/2.0

Currently CiV has support for the following sensors:

  • Accelerometer

  • Gyroscope

  • Magnetic field

  • Light

  • Gravity

  • Rotation vector

  • Geomagnetic rotation vector

  • Orientation

Enabling sensors in CiV

By default, Celadon has support for sensors. To enable sensors, add sensors information in mixins.spec as shown below:

$device/intel/project-celadon/$(lunch_target)/mixins.spec

sensors: mediation(enable_sensor_list=true)

The sepolicy configuration for the sensor mediation HAL is present in

$device/intel/sepolicy/sensors/mediation/

Disabling sensors

To disable sensors in CiV, assign false to the sensors filed in your lunch target’s mixins.spec.

$device/intel/project-celadon/$(lunch_target)/mixins. spec

sensors: false

Run the following command to update mixin changes:

$./device/intel/mixins/mixin-update

Starting the IIO daemon

Start the IIO daemon to provide access to sensors for CiV running as Guest.

The IIO daemon is an open-source project developed by Analog Devices. To start iio-daemon(iiod), we must build it from source code. Follow the steps below to clone, build, and run iiod.

git clone https://github.com/analogdevicesinc/libiio.git
git checkout tags/v0.19 -b v0.19
cd libiio
mkdir build && cd build && cmake .. && make && sudo make install
sudo iiod &

Confirm that iiod is running by running the following command:

$ps -aux | grep -i iiod

Validating sensors in CiV

After following the steps to enable sensors, confirm that the sensors are up and running in CiV by running the steps shown below.

Connect to CiV using adb and run $dumpsys sensorservice to check the list of supported sensors and their data in Android. Figure 2 shows an example of the output to verify sensors from the host OS.

../_images/fig2-verify-sensors-output.png

Figure 2 Verify sensors example

Here is a snapshot of Accelerometer data in dumpsys output.

../_images/fig3-accelerometer-data-example.png

Figure 3 Accelerometer data example

Figure 4 shows an example of the sensor data reading from the third-party Sensors Toolbox Android app.

../_images/fig4-sensor-data-example.png

Figure 4 Sensor data example