diff options
-rw-r--r-- | hal/sensors/2.0/Sensor.cpp | 4 | ||||
-rw-r--r-- | hal/sensors/2.0/iio_utils.cpp | 35 | ||||
-rw-r--r-- | hal/sensors/2.0/iio_utils.h | 1 |
3 files changed, 24 insertions, 16 deletions
diff --git a/hal/sensors/2.0/Sensor.cpp b/hal/sensors/2.0/Sensor.cpp index 3e3150e..476c4d1 100644 --- a/hal/sensors/2.0/Sensor.cpp +++ b/hal/sensors/2.0/Sensor.cpp @@ -166,7 +166,7 @@ void HWSensorBase::processScanData(uint8_t* data, Event* evt) { if (chanIdx == mIioData.channelInfo.size() - 1) { evt->timestamp = val; } else { - channelData[chanIdx] = static_cast<float>(val) * mIioData.resolution; + channelData[chanIdx] = static_cast<float>(val) * mIioData.scale; } } @@ -451,7 +451,7 @@ HWSensorBase::HWSensorBase(int32_t sensorHandle, ISensorsEventCallback* callback mSensorInfo.flags |= SensorFlagBits::CONTINUOUS_MODE; mSensorInfo.name = data.name; mSensorInfo.resolution = data.resolution; - mSensorInfo.maxRange = data.max_range * data.resolution; + mSensorInfo.maxRange = data.max_range * data.scale; mSensorInfo.power = (data.power_microwatts / 1000.f) / SENSOR_VOLTAGE_DEFAULT; // converting uW to mA mIioData = data; diff --git a/hal/sensors/2.0/iio_utils.cpp b/hal/sensors/2.0/iio_utils.cpp index 6e31e5f..abd5d3c 100644 --- a/hal/sensors/2.0/iio_utils.cpp +++ b/hal/sensors/2.0/iio_utils.cpp @@ -37,6 +37,7 @@ static const char* IIO_SAMPLING_FREQUENCY = "_sampling_frequency"; static const char* IIO_BUFFER_ENABLE = "buffer/enable"; static const char* IIO_POWER_FILENAME = "sensor_power"; static const char* IIO_MAX_RANGE_FILENAME = "sensor_max_range"; +static const char* IIO_RESOLUTION_FILENAME = "sensor_resolution"; namespace android { namespace hardware { @@ -170,9 +171,7 @@ static int get_sampling_frequency_available(const std::string& device_dir, char* rest; std::string line; - std::string filename = device_dir; - filename += "/"; - filename += IIO_SFA_FILENAME; + const std::string filename = device_dir + "/" + IIO_SFA_FILENAME; ret = sysfs_read_str(filename, &line); if (ret < 0) return ret; @@ -186,17 +185,13 @@ static int get_sampling_frequency_available(const std::string& device_dir, } static int get_sensor_power(const std::string& device_dir, unsigned int* power) { - std::string filename = device_dir; - filename += "/"; - filename += IIO_POWER_FILENAME; + const std::string filename = device_dir + "/" + IIO_POWER_FILENAME; return sysfs_read_uint(filename, power); } static int get_sensor_max_range(const std::string& device_dir, int64_t* max_range) { - std::string filename = device_dir; - filename += "/"; - filename += IIO_MAX_RANGE_FILENAME; + const std::string filename = device_dir + "/" + IIO_MAX_RANGE_FILENAME; return sysfs_read_int64(filename, max_range); } @@ -218,12 +213,12 @@ int set_sampling_frequency(const std::string& device_dir, const double frequency return ret; } -static int get_scale(const std::string& device_dir, float* resolution) { +static int get_sensor_scale(const std::string& device_dir, float* scale) { DirPtr dp(nullptr, closedir); const struct dirent* ent; int err; std::string filename; - if (resolution == nullptr) { + if (scale == nullptr) { return -EINVAL; } err = sysfs_opendir(device_dir, &dp); @@ -233,12 +228,18 @@ static int get_scale(const std::string& device_dir, float* resolution) { filename = device_dir; filename += "/"; filename += ent->d_name; - err = sysfs_read_float(filename, resolution); + err = sysfs_read_float(filename, scale); } } return err; } +static int get_sensor_resolution(const std::string& device_dir, float* resolution) { + const std::string filename = device_dir + "/" + IIO_RESOLUTION_FILENAME; + + return sysfs_read_float(filename, resolution); +} + static bool is_supported_sensor(const std::string& path, const std::vector<sensors_supported_hal>& supported_sensors, std::string* name, sensors_supported_hal* sensor) { @@ -290,9 +291,9 @@ int load_iio_devices(std::vector<iio_device_data>* iio_data, } std::sort(iio_dev_data.sampling_freq_avl.begin(), iio_dev_data.sampling_freq_avl.end()); - err = get_scale(iio_dev_data.sysfspath, &iio_dev_data.resolution); + err = get_sensor_scale(iio_dev_data.sysfspath, &iio_dev_data.scale); if (err) { - ALOGE("get_scale for %s returned error %d", path_device.c_str(), err); + ALOGE("get_sensor_scale for %s returned error %d", path_device.c_str(), err); continue; } err = get_sensor_power(iio_dev_data.sysfspath, &iio_dev_data.power_microwatts); @@ -305,6 +306,12 @@ int load_iio_devices(std::vector<iio_device_data>* iio_data, ALOGE("get_sensor_max_range for %s returned error %d", path_device.c_str(), err); continue; } + err = get_sensor_resolution(iio_dev_data.sysfspath, &iio_dev_data.resolution); + if (err) { + ALOGE("get_sensor_resolution for %s returned error %d", path_device.c_str(), err); + continue; + } + sscanf(ent->d_name + iio_base_len, "%hhu", &iio_dev_data.iio_dev_num); iio_data->push_back(iio_dev_data); diff --git a/hal/sensors/2.0/iio_utils.h b/hal/sensors/2.0/iio_utils.h index d818d2f..1beb5d4 100644 --- a/hal/sensors/2.0/iio_utils.h +++ b/hal/sensors/2.0/iio_utils.h @@ -55,6 +55,7 @@ struct iio_device_data { std::string name; std::string sysfspath; float resolution; + float scale; SensorType type; std::vector<iio_info_channel> channelInfo; std::vector<double> sampling_freq_avl; |