HACK: libsensors: First attempt at using Inv IIO MPU6050+AK8963
This is just a starting point to see how the new
hardware/invensense/sensors_iio integrates.
The patch needs
https://android-git.corp.google.com/g/#/c/200993/
and the poll loop is based on the sensors_mpl.c.
The way the sensor polling works is messy. I don't yet fully understand
how the read*Events() messes around with data and nb.
But it does allow pressure/light to work with gyro/compass/accel.
The Android.mk only builds for manta because:
- sensors.manta needs to link against the invensense/sensors_iio's
libinvensense_hal
- weirdly, the build always builds devices that are not selected.
- the invensense/sensors_iio produces files that conflict with
those produced by invensense/{sensors,mlsdk} used by non-manta devices.
- only one of the invensense/sensors* can be built.
Without the restriction, sensors.manta fails to link against the non-manta
libinvensense_hal duiring a non-manta build.
Change-Id: I9841d0d48c9792e8adc7b079cbcd9c4d82e2be88
diff --git a/libsensors/sensors.cpp b/libsensors/sensors.cpp
index d10091b..19fcd6a 100644
--- a/libsensors/sensors.cpp
+++ b/libsensors/sensors.cpp
@@ -32,6 +32,7 @@
#include "sensors.h"
+#include "MPLSensor.h"
#include "LightSensor.h"
#include "PressureSensor.h"
@@ -69,7 +70,7 @@
/* The SENSORS Module */
#define LOCAL_SENSORS (2)
-static struct sensor_t sSensorList[LOCAL_SENSORS] = {
+static struct sensor_t sSensorList[LOCAL_SENSORS + MPLSensor::numSensors] = {
{ "BH1721fvc Light sensor",
"Rohm",
1, SENSORS_LIGHT_HANDLE,
@@ -122,7 +123,9 @@
private:
enum {
- light = 0,
+ mpl = 0,
+ compass,
+ light,
pressure,
numSensorDrivers, // wake pipe goes here
numFds,
@@ -136,6 +139,14 @@
int handleToDriver(int handle) const {
switch (handle) {
+ case ID_RV:
+ case ID_LA:
+ case ID_GR:
+ case ID_GY:
+ case ID_A:
+ case ID_M:
+ case ID_O:
+ return mpl;
case ID_L:
return light;
case ID_PR:
@@ -150,7 +161,23 @@
sensors_poll_context_t::sensors_poll_context_t()
{
FUNC_LOG;
- numSensors = LOCAL_SENSORS;
+ CompassSensor *p_compasssensor = new CompassSensor();
+ MPLSensor *p_mplsen = new MPLSensor(p_compasssensor);
+ setCallbackObject(p_mplsen); //setup the callback object for handing mpl callbacks
+ numSensors =
+ LOCAL_SENSORS +
+ p_mplsen->populateSensorList(sSensorList + LOCAL_SENSORS,
+ sizeof(sSensorList[0]) * (ARRAY_SIZE(sSensorList) - LOCAL_SENSORS));
+
+ mSensors[mpl] = p_mplsen;
+ mPollFds[mpl].fd = mSensors[mpl]->getFd();
+ mPollFds[mpl].events = POLLIN;
+ mPollFds[mpl].revents = 0;
+
+ mSensors[compass] = p_mplsen;
+ mPollFds[compass].fd = ((MPLSensor*)mSensors[mpl])->getCompassFd();
+ mPollFds[compass].events = POLLIN;
+ mPollFds[compass].revents = 0;
mSensors[light] = new LightSensor();
mPollFds[light].fd = mSensors[light]->getFd();
@@ -218,7 +245,18 @@
for (int i=0 ; count && i<numSensorDrivers ; i++) {
SensorBase* const sensor(mSensors[i]);
if ((mPollFds[i].revents & POLLIN) || (sensor->hasPendingEvents())) {
- int nb = sensor->readEvents(data, count);
+ int nb;
+ if (i == compass) {
+ nb = ((MPLSensor*) sensor)->readCompassEvents(data, count);
+ continue;
+ }
+ else if (i == mpl) {
+ nb = sensor->readEvents(data, count);
+ continue;
+ }
+ else {
+ nb = sensor->readEvents(data, count);
+ }
if (nb < count) {
// no more data for this sensor
mPollFds[i].revents = 0;
@@ -228,6 +266,14 @@
data += nb;
}
}
+ int nb = ((MPLSensor*) mSensors[mpl])->executeOnData(data, count);
+ if (nb > 0) {
+ count -= nb;
+ nbEvents += nb;
+ data += nb;
+ mPollFds[mpl].revents = 0;
+ mPollFds[compass].revents = 0;
+ }
if (count) {
// we still have some room, so try to see if we can get