summaryrefslogtreecommitdiffstats
path: root/libsensors
diff options
context:
space:
mode:
Diffstat (limited to 'libsensors')
-rw-r--r--libsensors/Android.mk1
-rw-r--r--libsensors/InputEventReader.cpp3
-rw-r--r--libsensors/LightSensor.cpp2
-rw-r--r--libsensors/MPLSensor.cpp166
-rw-r--r--libsensors/MPLSensor.h21
-rw-r--r--libsensors/PressureSensor.cpp2
-rw-r--r--libsensors/ProximitySensor.cpp2
-rw-r--r--libsensors/SamsungSensorBase.cpp6
-rw-r--r--libsensors/SamsungSensorBase.h3
-rw-r--r--libsensors/SensorBase.cpp40
-rw-r--r--libsensors/SensorBase.h9
-rw-r--r--libsensors/TemperatureSensor.cpp2
-rw-r--r--libsensors/sensors.cpp50
13 files changed, 104 insertions, 203 deletions
diff --git a/libsensors/Android.mk b/libsensors/Android.mk
index 2d2d274..42fadb8 100644
--- a/libsensors/Android.mk
+++ b/libsensors/Android.mk
@@ -48,7 +48,6 @@ LOCAL_SRC_FILES := \
LOCAL_SHARED_LIBRARIES := liblog libcutils libutils libdl libmllite libmlplatform
LOCAL_CFLAGS := -DLOG_TAG=\"Sensors\"
LOCAL_CPPFLAGS := -DLINUX=1
-LOCAL_LDFLAGS := -rdynamic
LOCAL_CLANG := true
LOCAL_CFLAGS += -Wall -Werror
diff --git a/libsensors/InputEventReader.cpp b/libsensors/InputEventReader.cpp
index 964eda5..4d1ebbd 100644
--- a/libsensors/InputEventReader.cpp
+++ b/libsensors/InputEventReader.cpp
@@ -65,8 +65,7 @@ ssize_t InputEventCircularReader::fill(int fd)
iov[0].iov_base = mHead;
iov[0].iov_len = numFirst * sizeof(input_event);
- if (numSecond > 0)
- {
+ if (numSecond > 0) {
iovcnt++;
iov[1].iov_base = mBuffer;
iov[1].iov_len = numSecond * sizeof(input_event);
diff --git a/libsensors/LightSensor.cpp b/libsensors/LightSensor.cpp
index 29b222b..a11ee1f 100644
--- a/libsensors/LightSensor.cpp
+++ b/libsensors/LightSensor.cpp
@@ -27,7 +27,7 @@
#include "LightSensor.h"
LightSensor::LightSensor()
- : SamsungSensorBase(NULL, "lightsensor-level", ABS_MISC)
+ : SamsungSensorBase("lightsensor-level", ABS_MISC)
{
mPendingEvent.sensor = ID_L;
mPendingEvent.type = SENSOR_TYPE_LIGHT;
diff --git a/libsensors/MPLSensor.cpp b/libsensors/MPLSensor.cpp
index bbdcf3a..d06a39a 100644
--- a/libsensors/MPLSensor.cpp
+++ b/libsensors/MPLSensor.cpp
@@ -56,7 +56,6 @@ extern "C" {
}
#include "mlcontrol.h"
-#include "sensor_params.h"
#define EXTRA_VERBOSE (0)
//#define FUNC_LOG ALOGV("%s", __PRETTY_FUNCTION__)
@@ -69,39 +68,6 @@ extern "C" {
/******************************************/
-/* Base values for the sensor list, these need to be in the order defined in MPLSensor.h */
-static struct sensor_t sSensorList[] =
-{
- {"MPL Gyroscope", "Invensense", 1, SENSORS_GYROSCOPE_HANDLE,
- SENSOR_TYPE_GYROSCOPE, GYRO_MPU3050_RANGE, GYRO_MPU3050_RESOLUTION,
- GYRO_MPU3050_POWER, 10000, 0, 0, SENSOR_STRING_TYPE_GYROSCOPE, "",
- 0, SENSOR_FLAG_CONTINUOUS_MODE, {}},
- {"MPL Accelerometer", "Invensense", 1, SENSORS_ACCELERATION_HANDLE,
- SENSOR_TYPE_ACCELEROMETER, ACCEL_BMA250_RANGE, ACCEL_BMA250_RESOLUTION,
- ACCEL_BMA250_POWER, 10000, 0, 0, SENSOR_STRING_TYPE_ACCELEROMETER, "",
- 0, SENSOR_FLAG_CONTINUOUS_MODE, {}},
- {"MPL Magnetic Field", "Invensense", 1, SENSORS_MAGNETIC_FIELD_HANDLE,
- SENSOR_TYPE_MAGNETIC_FIELD, COMPASS_YAS530_RANGE, COMPASS_YAS530_RESOLUTION,
- COMPASS_YAS530_POWER, 10000, 0, 0, SENSOR_STRING_TYPE_MAGNETIC_FIELD, "",
- 0, SENSOR_FLAG_CONTINUOUS_MODE, {}},
- {"MPL Orientation", "Invensense", 1, SENSORS_ORIENTATION_HANDLE,
- SENSOR_TYPE_ORIENTATION, NINEAXIS_ORIENTATION_RANGE, NINEAXIS_ORIENTATION_RESOLUTION,
- NINEAXIS_ORIENTATION_POWER, 10000, 0, 0, SENSOR_STRING_TYPE_ORIENTATION, "",
- 0, SENSOR_FLAG_CONTINUOUS_MODE, {}},
- {"MPL Rotation Vector", "Invensense", 1, SENSORS_ROTATION_VECTOR_HANDLE,
- SENSOR_TYPE_ROTATION_VECTOR, NINEAXIS_ROTATION_VECTOR_RANGE, NINEAXIS_ROTATION_VECTOR_RESOLUTION,
- NINEAXIS_ROTATION_VECTOR_POWER, 10000, 0, 0, SENSOR_STRING_TYPE_ORIENTATION, "",
- 0, SENSOR_FLAG_CONTINUOUS_MODE, {}},
- {"MPL Linear Acceleration", "Invensense", 1, SENSORS_LINEAR_ACCEL_HANDLE,
- SENSOR_TYPE_LINEAR_ACCELERATION, NINEAXIS_LINEAR_ACCEL_RANGE, NINEAXIS_LINEAR_ACCEL_RESOLUTION,
- NINEAXIS_LINEAR_ACCEL_POWER, 10000, 0, 0, SENSOR_STRING_TYPE_LINEAR_ACCELERATION, "",
- 0, SENSOR_FLAG_CONTINUOUS_MODE, {}},
- {"MPL Gravity", "Invensense", 1, SENSORS_GRAVITY_HANDLE,
- SENSOR_TYPE_GRAVITY, NINEAXIS_GRAVITY_RANGE, NINEAXIS_GRAVITY_RESOLUTION,
- NINEAXIS_GRAVITY_POWER, 10000, 0, 0, SENSOR_STRING_TYPE_GRAVITY, "",
- 0, SENSOR_FLAG_CONTINUOUS_MODE, {}},
-};
-
static unsigned long long irq_timestamp = 0;
/* ***************************************************************************
* MPL interface misc.
@@ -149,7 +115,7 @@ void setCallbackObject(MPLSensor* gbpt)
#define RV_ENABLED ((1<<ID_RV) & enabled_sensors)
MPLSensor::MPLSensor() :
- SensorBase(NULL, NULL),
+ SensorBase(NULL),
mNewData(0),
mDmpStarted(false),
mMasterSensorMask(INV_ALL_SENSORS),
@@ -157,7 +123,8 @@ MPLSensor::MPLSensor() :
mCurFifoRate(-1), mHaveGoodMpuCal(false), mHaveGoodCompassCal(false),
mUseTimerIrqAccel(false), mUsetimerIrqCompass(true),
mUseTimerirq(false),
- mEnabled(0), mPendingMask(0)
+ mEnabled(0), mPendingMask(0),
+ mForceSleep(false), mNineAxisEnabled(false)
{
FUNC_LOG;
int mpu_int_fd;
@@ -167,13 +134,6 @@ MPLSensor::MPLSensor() :
pthread_mutex_init(&mMplMutex, NULL);
- mForceSleep = false;
-
- /* used for identifying whether 9axis is enabled or not */
- /* this variable will be changed in initMPL() when libmpl is loaded */
- /* sensor list will be changed based on this variable */
- mNineAxisEnabled = false;
-
for (size_t i = 0; i < ARRAY_SIZE(mPollFds); i++) {
mPollFds[i].fd = -1;
mPollFds[i].events = 0;
@@ -214,7 +174,7 @@ MPLSensor::MPLSensor() :
data_fd = mpu_int_fd;
if ((accel_fd == -1) && (timer_fd != -1)) {
- //no accel irq and timer available
+ // no accel irq, but timer is available
mUseTimerIrqAccel = true;
}
@@ -248,8 +208,7 @@ MPLSensor::MPLSensor() :
mPendingEvents[Orientation].version = sizeof(sensors_event_t);
mPendingEvents[Orientation].sensor = ID_O;
mPendingEvents[Orientation].type = SENSOR_TYPE_ORIENTATION;
- mPendingEvents[Orientation].orientation.status
- = SENSOR_STATUS_ACCURACY_HIGH;
+ mPendingEvents[Orientation].orientation.status = SENSOR_STATUS_ACCURACY_HIGH;
mHandlers[RotationVector] = &MPLSensor::rvHandler;
mHandlers[LinearAccel] = &MPLSensor::laHandler;
@@ -272,7 +231,6 @@ MPLSensor::MPLSensor() :
//setup the FIFO contents
setupFIFO();
-
pthread_mutex_unlock(&mMplMutex);
}
@@ -325,17 +283,11 @@ void MPLSensor::setPowerStates(int enabled_sensors)
FUNC_LOG;
bool irq_set[5] = { false, false, false, false, false };
- do {
- if (LA_ENABLED || GR_ENABLED || RV_ENABLED || O_ENABLED) {
- mLocalSensorMask = ALL_MPL_SENSORS_NP;
- break;
- }
-
- if (!A_ENABLED && !M_ENABLED && !GY_ENABLED) {
- mLocalSensorMask = 0;
- break;
- }
-
+ if (LA_ENABLED || GR_ENABLED || RV_ENABLED || O_ENABLED) {
+ mLocalSensorMask = ALL_MPL_SENSORS_NP;
+ } else if (!A_ENABLED && !M_ENABLED && !GY_ENABLED) {
+ mLocalSensorMask = 0;
+ } else {
if (GY_ENABLED) {
mLocalSensorMask |= INV_THREE_AXIS_GYRO;
} else {
@@ -353,7 +305,7 @@ void MPLSensor::setPowerStates(int enabled_sensors)
} else {
mLocalSensorMask &= ~(INV_THREE_AXIS_COMPASS);
}
- } while (0);
+ }
//record the new sensor state
inv_error_t rv;
@@ -446,13 +398,13 @@ void MPLSensor::initMPL()
}
//check for the 9axis fusion library: if available load it and start 9x
- void* h_dmp_lib=dlopen("libinvensense_mpl.so", RTLD_NOW);
- if(h_dmp_lib) {
+ void* h_dmp_lib = dlopen("libinvensense_mpl.so", RTLD_NOW);
+ if (h_dmp_lib) {
const char* error;
error = dlerror();
inv_error_t (*fp_inv_enable_9x_fusion)() =
(inv_error_t(*)()) dlsym(h_dmp_lib, "inv_enable_9x_fusion");
- if((error = dlerror()) != NULL) {
+ if ((error = dlerror()) != NULL) {
ALOGE("%s %s", error, "inv_enable_9x_fusion");
} else if ((*fp_inv_enable_9x_fusion)() != INV_SUCCESS) {
ALOGE( "Warning : 9 axis sensor fusion not available "
@@ -534,12 +486,10 @@ void MPLSensor::setupCallbacks()
FUNC_LOG;
if (inv_set_motion_callback(mot_cb_wrapper) != INV_SUCCESS) {
ALOGE("Error : Motion callback could not be set.\n");
-
}
if (inv_set_fifo_processed_callback(procData_cb_wrapper) != INV_SUCCESS) {
ALOGE("Error : Processed data callback could not be set.");
-
}
}
@@ -552,7 +502,7 @@ void MPLSensor::cbOnMotion(uint16_t val)
//after the first no motion, the gyro should be calibrated well
if (val == 2) {
if ((inv_get_dl_config()->requested_sensors) & INV_THREE_AXIS_GYRO) {
- //if gyros are on and we got a no motion, set a flag
+ // if gyros are on and we got a no motion, set a flag
// indicating that the cal file can be written.
mHaveGoodMpuCal = true;
}
@@ -567,8 +517,8 @@ void MPLSensor::cbProcData()
mNewData = 1;
}
-//these handlers transform mpl data into one of the Android sensor types
-// scaling and coordinate transforms should be done in the handlers
+// these handlers transform mpl data into one of the Android sensor types.
+// scaling and coordinate transforms should be done in the handlers
void MPLSensor::gyroHandler(sensors_event_t* s, uint32_t* pending_mask,
int index)
@@ -603,7 +553,7 @@ int MPLSensor::estimateCompassAccuracy()
int rv;
res = inv_get_compass_accuracy(&rv);
- if(rv >= SENSOR_STATUS_ACCURACY_MEDIUM) {
+ if (rv >= SENSOR_STATUS_ACCURACY_MEDIUM) {
mHaveGoodCompassCal = true;
}
ALOGE_IF(res != INV_SUCCESS, "error returned from inv_get_compass_accuracy");
@@ -763,34 +713,7 @@ int MPLSensor::enable(int32_t handle, int en)
{
FUNC_LOG;
- int what = -1;
-
- switch (handle) {
- case ID_A:
- what = Accelerometer;
- break;
- case ID_M:
- what = MagneticField;
- break;
- case ID_O:
- what = Orientation;
- break;
- case ID_GY:
- what = Gyro;
- break;
- case ID_GR:
- what = Gravity;
- break;
- case ID_RV:
- what = RotationVector;
- break;
- case ID_LA:
- what = LinearAccel;
- break;
- default: //this takes care of all the gestures
- what = handle;
- break;
- }
+ int what = handleToDriver(handle);
if (uint32_t(what) >= numSensors)
return -EINVAL;
@@ -819,33 +742,8 @@ int MPLSensor::setDelay(int32_t handle, int64_t ns)
FUNC_LOG;
ALOGV_IF(EXTRA_VERBOSE,
" setDelay handle: %d rate %d", handle, (int) (ns / 1000000LL));
- int what = -1;
- switch (handle) {
- case ID_A:
- what = Accelerometer;
- break;
- case ID_M:
- what = MagneticField;
- break;
- case ID_O:
- what = Orientation;
- break;
- case ID_GY:
- what = Gyro;
- break;
- case ID_GR:
- what = Gravity;
- break;
- case ID_RV:
- what = RotationVector;
- break;
- case ID_LA:
- what = LinearAccel;
- break;
- default:
- what = handle;
- break;
- }
+
+ int what = handleToDriver(handle);
if (uint32_t(what) >= numSensors)
return -EINVAL;
@@ -895,7 +793,7 @@ int MPLSensor::update_delay()
rv = (res == INV_SUCCESS);
}
- if (((inv_get_dl_config()->requested_sensors & INV_DMP_PROCESSOR) == 0)) {
+ if ((inv_get_dl_config()->requested_sensors & INV_DMP_PROCESSOR) == 0) {
if (mUseTimerirq) {
ioctl(mIrqFds.valueFor(TIMERIRQ_FD), TIMERIRQ_STOP, 0);
clearIrqData(irq_set);
@@ -934,9 +832,7 @@ int MPLSensor::readEvents(sensors_event_t* data, int count)
if (mDmpStarted) {
rv = inv_update_data();
ALOGE_IF(rv != INV_SUCCESS, "inv_update_data error (code %d)", (int) rv);
- }
-
- else {
+ } else {
//probably just one extra read after shutting down
ALOGV_IF(EXTRA_VERBOSE,
"MPLSensor::readEvents called, but there's nothing to do.");
@@ -1032,8 +928,8 @@ void MPLSensor::wakeEvent()
pthread_mutex_lock(&mMplMutex);
if (mForceSleep) {
setPowerStates((mOldEnabledMask | mEnabled));
+ mForceSleep = false;
}
- mForceSleep = false;
pthread_mutex_unlock(&mMplMutex);
}
@@ -1042,25 +938,19 @@ void MPLSensor::wakeEvent()
* parameter list must point to a memory region of at least 7*sizeof(sensor_t)
* parameter len gives the length of the buffer pointed to by list
*/
-
int MPLSensor::populateSensorList(struct sensor_t *list, size_t len)
{
- int numsensors;
+ int numsensors = 7;
- if(len < 7*sizeof(sensor_t)) {
+ if (len < numsensors * sizeof(sensor_t)) {
ALOGE("sensor list too small, not populating.");
return 0;
}
- /* fill in the base values */
- memcpy(list, sSensorList, sizeof (struct sensor_t) * 7);
-
- if (mNineAxisEnabled) {
- numsensors = 7;
- } else {
+ if (!mNineAxisEnabled) {
/* no 9-axis sensors, zero fill that part of the list */
numsensors = 3;
- memset(list+3, 0, 4*sizeof(struct sensor_t));
+ memset(list + numsensors, 0, (7 - numsensors) * sizeof(struct sensor_t));
}
return numsensors;
diff --git a/libsensors/MPLSensor.h b/libsensors/MPLSensor.h
index eba750a..fc65708 100644
--- a/libsensors/MPLSensor.h
+++ b/libsensors/MPLSensor.h
@@ -118,8 +118,27 @@ private:
long int mOldEnabledMask;
android::KeyedVector<int, int> mIrqFds;
- /* added for dynamic get sensor list */
bool mNineAxisEnabled;
+
+ int handleToDriver(int handle) const {
+ switch (handle) {
+ case ID_A:
+ return Accelerometer;
+ case ID_M:
+ return MagneticField;
+ case ID_O:
+ return Orientation;
+ case ID_GY:
+ return Gyro;
+ case ID_GR:
+ return Gravity;
+ case ID_RV:
+ return RotationVector;
+ case ID_LA:
+ return LinearAccel;
+ }
+ return handle;
+ }
};
void setCallbackObject(MPLSensor*);
diff --git a/libsensors/PressureSensor.cpp b/libsensors/PressureSensor.cpp
index dc34b95..a273811 100644
--- a/libsensors/PressureSensor.cpp
+++ b/libsensors/PressureSensor.cpp
@@ -33,7 +33,7 @@
#define PRESSURE_HECTO (1.0f/100.0f)
PressureSensor::PressureSensor()
- : SamsungSensorBase(NULL, "barometer", ABS_PRESSURE)
+ : SamsungSensorBase("barometer", ABS_PRESSURE)
{
mPendingEvent.sensor = ID_PR;
mPendingEvent.type = SENSOR_TYPE_PRESSURE;
diff --git a/libsensors/ProximitySensor.cpp b/libsensors/ProximitySensor.cpp
index 56efc8d..b29485d 100644
--- a/libsensors/ProximitySensor.cpp
+++ b/libsensors/ProximitySensor.cpp
@@ -30,7 +30,7 @@
/*****************************************************************************/
ProximitySensor::ProximitySensor()
- : SamsungSensorBase(NULL, "proximity", ABS_DISTANCE)
+ : SamsungSensorBase("proximity", ABS_DISTANCE)
{
mPendingEvent.sensor = ID_P;
mPendingEvent.type = SENSOR_TYPE_PROXIMITY;
diff --git a/libsensors/SamsungSensorBase.cpp b/libsensors/SamsungSensorBase.cpp
index 0492d94..4cea484 100644
--- a/libsensors/SamsungSensorBase.cpp
+++ b/libsensors/SamsungSensorBase.cpp
@@ -55,10 +55,9 @@ int SamsungSensorBase::handleEnable(int en __unused) {
return 0;
}
-SamsungSensorBase::SamsungSensorBase(const char *dev_name,
- const char *data_name,
+SamsungSensorBase::SamsungSensorBase(const char *data_name,
int sensor_code)
- : SensorBase(dev_name, data_name),
+ : SensorBase(data_name),
mEnabled(true),
mHasPendingEvent(false),
mInputReader(4),
@@ -182,5 +181,4 @@ int SamsungSensorBase::readEvents(sensors_event_t* data, int count)
done:
pthread_mutex_unlock(&mLock);
return numEventReceived;
-
}
diff --git a/libsensors/SamsungSensorBase.h b/libsensors/SamsungSensorBase.h
index 1440e37..8faa978 100644
--- a/libsensors/SamsungSensorBase.h
+++ b/libsensors/SamsungSensorBase.h
@@ -52,8 +52,7 @@ protected:
virtual bool handleEvent(input_event const * event);
public:
- SamsungSensorBase(const char* dev_name,
- const char* data_name,
+ SamsungSensorBase(const char* data_name,
int sensor_code);
virtual ~SamsungSensorBase();
diff --git a/libsensors/SensorBase.cpp b/libsensors/SensorBase.cpp
index 6d6ab25..5649d90 100644
--- a/libsensors/SensorBase.cpp
+++ b/libsensors/SensorBase.cpp
@@ -31,11 +31,9 @@
/*****************************************************************************/
-SensorBase::SensorBase(
- const char* dev_name,
- const char* data_name)
- : dev_name(dev_name), data_name(data_name),
- dev_fd(-1), data_fd(-1)
+SensorBase::SensorBase(const char* data_name)
+ : data_name(data_name),
+ data_fd(-1)
{
if (data_name) {
data_fd = openInput(data_name);
@@ -46,31 +44,9 @@ SensorBase::~SensorBase() {
if (data_fd >= 0) {
close(data_fd);
}
- if (dev_fd >= 0) {
- close(dev_fd);
- }
-}
-
-int SensorBase::open_device() {
- if (dev_fd<0 && dev_name) {
- dev_fd = open(dev_name, O_RDONLY);
- ALOGE_IF(dev_fd<0, "Couldn't open %s (%s)", dev_name, strerror(errno));
- }
- return 0;
-}
-
-int SensorBase::close_device() {
- if (dev_fd >= 0) {
- close(dev_fd);
- dev_fd = -1;
- }
- return 0;
}
int SensorBase::getFd() const {
- if (!data_name) {
- return dev_fd;
- }
return data_fd;
}
@@ -90,19 +66,19 @@ int SensorBase::openInput(const char* inputName) {
DIR *dir;
struct dirent *de;
dir = opendir(dirname);
- if(dir == NULL)
+ if (dir == NULL)
return -1;
strcpy(devname, dirname);
filename = devname + strlen(devname);
*filename++ = '/';
- while((de = readdir(dir))) {
- if(de->d_name[0] == '.' &&
+ while ((de = readdir(dir))) {
+ if (de->d_name[0] == '.' &&
(de->d_name[1] == '\0' ||
(de->d_name[1] == '.' && de->d_name[2] == '\0')))
continue;
strcpy(filename, de->d_name);
fd = open(devname, O_RDONLY);
- if (fd>=0) {
+ if (fd >= 0) {
char name[80];
if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
name[0] = '\0';
@@ -117,6 +93,6 @@ int SensorBase::openInput(const char* inputName) {
}
}
closedir(dir);
- ALOGE_IF(fd<0, "couldn't find '%s' input device", inputName);
+ ALOGE_IF(fd < 0, "couldn't find '%s' input device", inputName);
return fd;
}
diff --git a/libsensors/SensorBase.h b/libsensors/SensorBase.h
index eb50550..b76748b 100644
--- a/libsensors/SensorBase.h
+++ b/libsensors/SensorBase.h
@@ -29,21 +29,14 @@ struct sensors_event_t;
class SensorBase {
protected:
- const char* dev_name;
const char* data_name;
char input_name[PATH_MAX];
- int dev_fd;
int data_fd;
int openInput(const char* inputName);
- int open_device();
- int close_device();
-
public:
- SensorBase(
- const char* dev_name,
- const char* data_name);
+ SensorBase(const char* data_name);
virtual ~SensorBase();
diff --git a/libsensors/TemperatureSensor.cpp b/libsensors/TemperatureSensor.cpp
index 74a6cd5..b782e0a 100644
--- a/libsensors/TemperatureSensor.cpp
+++ b/libsensors/TemperatureSensor.cpp
@@ -29,7 +29,7 @@
#define TEMPERATURE_CELCIUS (1.0f/10.0f)
TemperatureSensor::TemperatureSensor()
- : SamsungSensorBase(NULL, "barometer", ABS_MISC)
+ : SamsungSensorBase("barometer", ABS_MISC)
{
mPendingEvent.sensor = ID_T;
mPendingEvent.type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
diff --git a/libsensors/sensors.cpp b/libsensors/sensors.cpp
index fe2070e..84b2682 100644
--- a/libsensors/sensors.cpp
+++ b/libsensors/sensors.cpp
@@ -34,6 +34,7 @@
#include <utils/Log.h>
#include "sensors.h"
+#include "sensor_params.h"
#include "MPLSensor.h"
#include "LightSensor.h"
@@ -93,6 +94,34 @@ static struct sensor_t sSensorList[LOCAL_SENSORS + MPLSensor::numSensors] =
{"BMP180 Temperature", "Bosch", 1, SENSORS_TEMPERATURE_HANDLE,
SENSOR_TYPE_AMBIENT_TEMPERATURE, 850.0f, 0.1f, 0.67f, 20000, 0, 0,
SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE, "", 20000, SENSOR_FLAG_CONTINUOUS_MODE, {}},
+ {"MPL Gyroscope", "Invensense", 1, SENSORS_GYROSCOPE_HANDLE,
+ SENSOR_TYPE_GYROSCOPE, GYRO_MPU3050_RANGE, GYRO_MPU3050_RESOLUTION,
+ GYRO_MPU3050_POWER, 10000, 0, 0, SENSOR_STRING_TYPE_GYROSCOPE, "",
+ 0, SENSOR_FLAG_CONTINUOUS_MODE, {}},
+ {"MPL Accelerometer", "Invensense", 1, SENSORS_ACCELERATION_HANDLE,
+ SENSOR_TYPE_ACCELEROMETER, ACCEL_BMA250_RANGE, ACCEL_BMA250_RESOLUTION,
+ ACCEL_BMA250_POWER, 10000, 0, 0, SENSOR_STRING_TYPE_ACCELEROMETER, "",
+ 0, SENSOR_FLAG_CONTINUOUS_MODE, {}},
+ {"MPL Magnetic Field", "Invensense", 1, SENSORS_MAGNETIC_FIELD_HANDLE,
+ SENSOR_TYPE_MAGNETIC_FIELD, COMPASS_YAS530_RANGE, COMPASS_YAS530_RESOLUTION,
+ COMPASS_YAS530_POWER, 10000, 0, 0, SENSOR_STRING_TYPE_MAGNETIC_FIELD, "",
+ 0, SENSOR_FLAG_CONTINUOUS_MODE, {}},
+ {"MPL Orientation", "Invensense", 1, SENSORS_ORIENTATION_HANDLE,
+ SENSOR_TYPE_ORIENTATION, NINEAXIS_ORIENTATION_RANGE, NINEAXIS_ORIENTATION_RESOLUTION,
+ NINEAXIS_ORIENTATION_POWER, 10000, 0, 0, SENSOR_STRING_TYPE_ORIENTATION, "",
+ 0, SENSOR_FLAG_CONTINUOUS_MODE, {}},
+ {"MPL Rotation Vector", "Invensense", 1, SENSORS_ROTATION_VECTOR_HANDLE,
+ SENSOR_TYPE_ROTATION_VECTOR, NINEAXIS_ROTATION_VECTOR_RANGE, NINEAXIS_ROTATION_VECTOR_RESOLUTION,
+ NINEAXIS_ROTATION_VECTOR_POWER, 10000, 0, 0, SENSOR_STRING_TYPE_ORIENTATION, "",
+ 0, SENSOR_FLAG_CONTINUOUS_MODE, {}},
+ {"MPL Linear Acceleration", "Invensense", 1, SENSORS_LINEAR_ACCEL_HANDLE,
+ SENSOR_TYPE_LINEAR_ACCELERATION, NINEAXIS_LINEAR_ACCEL_RANGE, NINEAXIS_LINEAR_ACCEL_RESOLUTION,
+ NINEAXIS_LINEAR_ACCEL_POWER, 10000, 0, 0, SENSOR_STRING_TYPE_LINEAR_ACCELERATION, "",
+ 0, SENSOR_FLAG_CONTINUOUS_MODE, {}},
+ {"MPL Gravity", "Invensense", 1, SENSORS_GRAVITY_HANDLE,
+ SENSOR_TYPE_GRAVITY, NINEAXIS_GRAVITY_RANGE, NINEAXIS_GRAVITY_RESOLUTION,
+ NINEAXIS_GRAVITY_POWER, 10000, 0, 0, SENSOR_STRING_TYPE_GRAVITY, "",
+ 0, SENSOR_FLAG_CONTINUOUS_MODE, {}},
};
static int numSensors = LOCAL_SENSORS;
@@ -253,7 +282,7 @@ sensors_poll_context_t::sensors_poll_context_t()
sensors_poll_context_t::~sensors_poll_context_t()
{
FUNC_LOG;
- for (int i=0 ; i<numSensorDrivers ; i++) {
+ for (int i = 0; i < numSensorDrivers; i++) {
delete mSensors[i];
}
close(mPollFds[wake].fd);
@@ -269,7 +298,7 @@ int sensors_poll_context_t::activate(int handle, int enabled)
if (!err) {
const char wakeMessage(WAKE_MESSAGE);
int result = write(mWritePipeFd, &wakeMessage, 1);
- ALOGE_IF(result<0, "error sending wake message (%s)", strerror(errno));
+ ALOGE_IF(result < 0, "error sending wake message (%s)", strerror(errno));
}
return err;
}
@@ -291,7 +320,7 @@ int sensors_poll_context_t::pollEvents(sensors_event_t* data, int count)
do {
// see if we have some leftover from the last poll()
- for (int i=0 ; count && i<numSensorDrivers ; i++) {
+ 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);
@@ -304,13 +333,12 @@ int sensors_poll_context_t::pollEvents(sensors_event_t* data, int count)
data += nb;
//special handling for the mpl, which has multiple handles
- if(i==mpl) {
- i+=2; //skip accel and timer
+ if (i == mpl) {
+ i += 2; //skip accel and timer
mPollFds[mpl_accel].revents = 0;
mPollFds[mpl_timer].revents = 0;
- }
- if(i==mpl_accel) {
- i+=1; //skip timer
+ } else if (i == mpl_accel) {
+ i += 1; //skip timer
mPollFds[mpl_timer].revents = 0;
}
}
@@ -323,18 +351,18 @@ int sensors_poll_context_t::pollEvents(sensors_event_t* data, int count)
do {
n = poll(mPollFds, numFds, nbEvents ? 0 : polltime);
} while (n < 0 && errno == EINTR);
- if (n<0) {
+ if (n < 0) {
ALOGE("poll() failed (%s)", strerror(errno));
return -errno;
}
if (mPollFds[wake].revents & POLLIN) {
char msg;
int result = read(mPollFds[wake].fd, &msg, 1);
- ALOGE_IF(result<0, "error reading from wake pipe (%s)", strerror(errno));
+ ALOGE_IF(result < 0, "error reading from wake pipe (%s)", strerror(errno));
ALOGE_IF(msg != WAKE_MESSAGE, "unknown message on wake queue (0x%02x)", int(msg));
mPollFds[wake].revents = 0;
}
- if(mPollFds[mpl_power].revents & POLLIN) {
+ if (mPollFds[mpl_power].revents & POLLIN) {
((MPLSensor*)mSensors[mpl])->handlePowerEvent();
mPollFds[mpl_power].revents = 0;
}