summaryrefslogtreecommitdiffstats
path: root/hal/sensors/2.0
diff options
context:
space:
mode:
authorJyoti Bhayana <jbhayana@google.com>2020-06-12 13:54:16 -0700
committerJyoti Bhayana <jbhayana@google.com>2020-06-12 13:57:00 -0700
commite2f392587d910c7149a95f4f79ab2207f7741aff (patch)
tree232accf2ded1a781d1a6330b4fb71019bf3939ce /hal/sensors/2.0
parent166c8c47fdc85048fa43742273a88c1db8707fc5 (diff)
downloaddevice_google_trout-e2f392587d910c7149a95f4f79ab2207f7741aff.tar.gz
device_google_trout-e2f392587d910c7149a95f4f79ab2207f7741aff.tar.bz2
device_google_trout-e2f392587d910c7149a95f4f79ab2207f7741aff.zip
Adding support for reading sensor max range from scmi iio driver
Bug: 155129166 Test: Build, and test with KitchenSink Change-Id: I7ac8343b13d214ecc0e761f28ff5ba2972c814fb
Diffstat (limited to 'hal/sensors/2.0')
-rw-r--r--hal/sensors/2.0/Sensor.cpp3
-rw-r--r--hal/sensors/2.0/iio_utils.cpp19
-rw-r--r--hal/sensors/2.0/iio_utils.h1
3 files changed, 20 insertions, 3 deletions
diff --git a/hal/sensors/2.0/Sensor.cpp b/hal/sensors/2.0/Sensor.cpp
index a738ae7..a525754 100644
--- a/hal/sensors/2.0/Sensor.cpp
+++ b/hal/sensors/2.0/Sensor.cpp
@@ -228,6 +228,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.power =
(data.power_microwatts / 1000.f) / SENSOR_VOLTAGE_DEFAULT; // converting uW to mA
miio_data = data;
@@ -256,13 +257,11 @@ HWSensorBase::HWSensorBase(int32_t sensorHandle, ISensorsEventCallback* callback
Accelerometer::Accelerometer(int32_t sensorHandle, ISensorsEventCallback* callback,
const struct iio_device_data& data)
: HWSensorBase(sensorHandle, callback, SensorType::ACCELEROMETER, data) {
- mSensorInfo.maxRange = 78.4f; // +/- 8g
}
Gyroscope::Gyroscope(int32_t sensorHandle, ISensorsEventCallback* callback,
const struct iio_device_data& data)
: HWSensorBase(sensorHandle, callback, SensorType::GYROSCOPE, data) {
- mSensorInfo.maxRange = 1000.0f * M_PI / 180.0f;
}
} // namespace implementation
diff --git a/hal/sensors/2.0/iio_utils.cpp b/hal/sensors/2.0/iio_utils.cpp
index a5cb282..c6ff53a 100644
--- a/hal/sensors/2.0/iio_utils.cpp
+++ b/hal/sensors/2.0/iio_utils.cpp
@@ -35,6 +35,7 @@ static const char* IIO_SCALE_FILENAME = "_scale";
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";
namespace android {
namespace hardware {
@@ -131,6 +132,10 @@ static int sysfs_read_float(const std::string& file, float* val) {
return sysfs_read_val(file, "%f\n", val);
}
+static int sysfs_read_int64(const std::string& file, int64_t* val) {
+ return sysfs_read_val(file, "%lld\n", val);
+}
+
static int sysfs_read_str(const std::string& file, std::string* str) {
std::ifstream infile(file);
if (!infile.is_open()) return -EINVAL;
@@ -187,6 +192,14 @@ static int get_sensor_power(const std::string& device_dir, unsigned int* power)
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;
+
+ return sysfs_read_int64(filename, max_range);
+}
+
int set_sampling_frequency(const std::string& device_dir, const double frequency) {
DirPtr dp(nullptr, closedir);
const struct dirent* ent;
@@ -286,7 +299,11 @@ int load_iio_devices(std::vector<iio_device_data>* iio_data,
ALOGE("get_sensor_power for %s returned error %d", path_device.c_str(), err);
continue;
}
-
+ err = get_sensor_max_range(iio_dev_data.sysfspath, &iio_dev_data.max_range);
+ if (err) {
+ ALOGE("get_sensor_max_range 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 bc1afa8..d818d2f 100644
--- a/hal/sensors/2.0/iio_utils.h
+++ b/hal/sensors/2.0/iio_utils.h
@@ -60,6 +60,7 @@ struct iio_device_data {
std::vector<double> sampling_freq_avl;
uint8_t iio_dev_num;
unsigned int power_microwatts;
+ int64_t max_range;
};
int load_iio_devices(std::vector<iio_device_data>* iio_data,