summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libsensors_iio/CompassSensor.IIO.9150.cpp8
-rw-r--r--libsensors_iio/MPLSensor.cpp21
-rw-r--r--libsensors_iio/MPLSensor.h6
3 files changed, 27 insertions, 8 deletions
diff --git a/libsensors_iio/CompassSensor.IIO.9150.cpp b/libsensors_iio/CompassSensor.IIO.9150.cpp
index ce0df34..d9f2e0c 100644
--- a/libsensors_iio/CompassSensor.IIO.9150.cpp
+++ b/libsensors_iio/CompassSensor.IIO.9150.cpp
@@ -375,7 +375,7 @@ int CompassSensor::inv_init_sysfs_attributes(void)
dptr = (char**)&compassSysFs;
if (sptr == NULL)
return -1;
-
+
do {
*dptr++ = sptr;
sptr += sizeof(char[MAX_SYSFS_NAME_LEN]);
@@ -383,7 +383,11 @@ int CompassSensor::inv_init_sysfs_attributes(void)
// get proper (in absolute/relative) IIO path & build MPU's sysfs paths
// inv_get_sysfs_abs_path(sysfs_path);
- inv_get_sysfs_path(sysfs_path);
+ if(INV_SUCCESS != inv_get_sysfs_path(sysfs_path)) {
+ ALOGE("CompassSensor failed get sysfs path");
+ return -1;
+ }
+
inv_get_iio_trigger_path(iio_trigger_path);
#if defined COMPASS_YAS530 || defined COMPASS_AK8975
diff --git a/libsensors_iio/MPLSensor.cpp b/libsensors_iio/MPLSensor.cpp
index ae82459..e23ecc9 100644
--- a/libsensors_iio/MPLSensor.cpp
+++ b/libsensors_iio/MPLSensor.cpp
@@ -136,6 +136,7 @@ static FILE *logfile = NULL;
MPLSensor::MPLSensor(CompassSensor *compass)
: SensorBase(NULL, NULL),
+ mMplSensorInitialized(false),
mNewData(0),
mMasterSensorMask(INV_ALL_SENSORS),
mLocalSensorMask(ALL_MPL_SENSORS_NP),
@@ -183,7 +184,10 @@ MPLSensor::MPLSensor(CompassSensor *compass)
#endif
/* setup sysfs paths */
- inv_init_sysfs_attributes();
+ if(inv_init_sysfs_attributes()) {
+ ALOGE("MPLSensor failed to init sysfs attributes");
+ return;
+ }
/* get chip name */
if (inv_get_chip_name(chip_ID) != INV_SUCCESS) {
@@ -203,7 +207,7 @@ MPLSensor::MPLSensor(CompassSensor *compass)
/* Load DMP image if capable, ie. MPU6xxx/9xxx */
// TODO: disabled for GED tablet
#ifdef ENABLE_LP_QUAT_FEAT
- loadDMP();
+ loadDMP();
#endif
/* open temperature fd for temp comp */
@@ -220,7 +224,7 @@ MPLSensor::MPLSensor(CompassSensor *compass)
if (USE_THIRD_PARTY_ACCEL == 0) {
char buf[3];
int count = 0;
- LOGV_IF(SYSFS_VERBOSE,
+ LOGV_IF(SYSFS_VERBOSE,
"HAL:sysfs:cat %s (%lld)", mpu.accel_fsr, getTimestamp());
fd = open(mpu.accel_fsr, O_RDONLY);
@@ -323,6 +327,8 @@ MPLSensor::MPLSensor(CompassSensor *compass)
if (logfile)
inv_turn_on_data_logging(logfile);
#endif
+
+ mMplSensorInitialized = true;
}
@@ -2472,6 +2478,12 @@ int MPLSensor::inv_init_sysfs_attributes(void)
char **dptr;
int num;
+ // get proper (in absolute/relative) IIO path & build MPU's sysfs paths
+ // inv_get_sysfs_abs_path(sysfs_path);
+ if(INV_SUCCESS != inv_get_sysfs_path(sysfs_path)) {
+ ALOGE("MPLSensor failed get sysfs path");
+ return -1;
+ }
sysfs_names_ptr =
(char*)malloc(sizeof(char[MAX_SYSFS_ATTRB][MAX_SYSFS_NAME_LEN]));
sptr = sysfs_names_ptr;
@@ -2486,9 +2498,6 @@ int MPLSensor::inv_init_sysfs_attributes(void)
return -1;
}
- // get proper (in absolute/relative) IIO path & build MPU's sysfs paths
- // inv_get_sysfs_abs_path(sysfs_path);
- inv_get_sysfs_path(sysfs_path);
inv_get_iio_trigger_path(iio_trigger_path);
sprintf(mpu.key, "%s%s", sysfs_path, "/key");
diff --git a/libsensors_iio/MPLSensor.h b/libsensors_iio/MPLSensor.h
index 4c38c57..3ef1ba3 100644
--- a/libsensors_iio/MPLSensor.h
+++ b/libsensors_iio/MPLSensor.h
@@ -112,6 +112,9 @@ public:
int populateSensorList(struct sensor_t *list, int len);
void cbProcData();
+ // Do not work with this object unless it is initialized
+ bool isValid() { return mMplSensorInitialized; };
+
//static pointer to the object that will handle callbacks
static MPLSensor* gMPLSensor;
@@ -122,6 +125,9 @@ public:
int readCompassEvents(sensors_event_t* data, int count);
protected:
+ // Lets us know if the constructor was actually able to finish its job.
+ // E.g. false if init sysfs failed.
+ bool mMplSensorInitialized;
CompassSensor *mCompassSensor;
int gyroHandler(sensors_event_t *data);