#include <cerrno>
#include <cstdlib>
#include <cstring>
+#include <cinttypes>
#include <fcntl.h>
#include <dirent.h>
#include <cutils/log.h>
static float scale_y = (*nodes)[1] ? read_sysfs_float((*nodes)[1]) : scale_x;
static float scale_z = (*nodes)[2] ? read_sysfs_float((*nodes)[2]) : scale_x;
int ret = SensorBase::readEvents(data, cnt);
+ char cm[PROPERTY_VALUE_MAX];
+ float m[9];
+ int v[3];
+
+ property_get("hal.sensors.iio.magn.matrix", cm, "1,0,0,0,1,0,0,0,1" );
+ sscanf(cm, "%f,%f,%f,%f,%f,%f,%f,%f,%f", &m[0], &m[1], &m[2], &m[3], &m[4], &m[5], &m[6], &m[7], &m[8]);
+
for (int i = 0; i < ret; ++i) {
- data[i].magnetic.x = scale_x * read_sysfs_int("in_magn_x_raw");
- data[i].magnetic.y = scale_y * read_sysfs_int("in_magn_y_raw");
- data[i].magnetic.z = scale_z * read_sysfs_int("in_magn_z_raw");
+ v[0] = read_sysfs_int("in_magn_x_raw");
+ v[1] = read_sysfs_int("in_magn_y_raw");
+ v[2] = read_sysfs_int("in_magn_z_raw");
+ // create matrix * vector product
+ data[i].magnetic.x = scale_x * (m[0] * v[0] + m[1] * v[1] + m[2] * v[2]);
+ data[i].magnetic.y = scale_y * (m[3] * v[0] + m[4] * v[1] + m[5] * v[2]);
+ data[i].magnetic.z = scale_z * (m[6] * v[0] + m[7] * v[1] + m[8] * v[2]);
data[i].magnetic.status = SENSOR_STATUS_ACCURACY_HIGH;
}
return ret;
{
static float scale = read_sysfs_float((*nodes)[0]);
int ret = SensorBase::readEvents(data, cnt);
- // TODO: read orientation from the properties
+ char cm[PROPERTY_VALUE_MAX];
+ float m[9];
+ int v[3];
+
+ property_get("hal.sensors.iio.anglvel.matrix", cm, "1,0,0,0,1,0,0,0,1" );
+ sscanf(cm, "%f,%f,%f,%f,%f,%f,%f,%f,%f", &m[0], &m[1], &m[2], &m[3], &m[4], &m[5], &m[6], &m[7], &m[8]);
+
for (int i = 0; i < ret; ++i) {
- data[i].gyro.x = scale * read_sysfs_int("in_anglvel_x_raw");
- data[i].gyro.y = scale * read_sysfs_int("in_anglvel_y_raw");
- data[i].gyro.z = scale * read_sysfs_int("in_anglvel_z_raw");
+ v[0] = read_sysfs_int("in_anglvel_x_raw");
+ v[1] = read_sysfs_int("in_anglvel_y_raw");
+ v[2] = read_sysfs_int("in_anglvel_z_raw");
+ // create matrix * vector product
+ data[i].gyro.x = scale * (m[0] * v[0] + m[1] * v[1] + m[2] * v[2]);
+ data[i].gyro.y = scale * (m[3] * v[0] + m[4] * v[1] + m[5] * v[2]);
+ data[i].gyro.z = scale * (m[6] * v[0] + m[7] * v[1] + m[8] * v[2]);
data[i].gyro.status = SENSOR_STATUS_ACCURACY_HIGH;
}
return ret;
Sensor<ID_GYROSCOPE>::probe,
};
-class SensorPollContext : sensors_poll_device_t {
+class SensorPollContext : sensors_poll_device_1 {
public:
SensorPollContext(const struct hw_module_t *module, struct hw_device_t **device);
~SensorPollContext();
static int poll_activate(struct sensors_poll_device_t *dev, int handle, int enabled);
static int poll_setDelay(struct sensors_poll_device_t *dev, int handle, int64_t ns);
static int poll_poll(struct sensors_poll_device_t *dev, sensors_event_t *data, int count);
+ static int poll_batch(struct sensors_poll_device_1* dev, int sensor_handle, int flags, int64_t sampling_period_ns, int64_t max_report_latency_ns);
+ static int poll_flush(struct sensors_poll_device_1* dev, int sensor_handle);
int doPoll(sensors_event_t *data, int count);
memset(this, 0, sizeof(*this));
common.tag = HARDWARE_DEVICE_TAG;
+ common.version = SENSORS_DEVICE_API_VERSION_1_3;
common.module = const_cast<struct hw_module_t *>(module);
common.close = poll_close;
activate = poll_activate;
setDelay = poll_setDelay;
poll = poll_poll;
+ batch = poll_batch;
+ flush = poll_flush;
*device = &common;
char path[PATH_MAX];
if (SensorBase *s = probeSensors[i](path)) {
sensors[i] = s;
sensors_list[count++] = *s;
- ALOGD("found %s", __FUNCTION__, s->name);
+ ALOGD("found %s", s->name);
}
}
}
}
+ closedir(dir);
}
ALOGD("%s: module=%p sensors: %d", __FUNCTION__, module, count);
}
int SensorPollContext::poll_setDelay(struct sensors_poll_device_t *dev, int handle, int64_t ns)
{
- ALOGD("%s: handle=%d delay-ns=%lld", __FUNCTION__, handle, ns);
SensorPollContext *ctx = reinterpret_cast<SensorPollContext *>(dev);
if (handle >= 0 && handle < MAX_SENSORS && ctx->sensors[handle])
return ctx->sensors[handle]->setDelay(ns);
return ctx->doPoll(data, count);
}
+int SensorPollContext::poll_batch(struct sensors_poll_device_1* dev, int sensor_handle, int flags, int64_t sampling_period_ns, int64_t max_report_latency_ns)
+{
+ ALOGD("%s: dev=%p sensor_handle=%d flags=%d sampling_period_ns=%" PRId64 " max_report_latency_ns=%" PRId64,
+ __FUNCTION__, dev, sensor_handle, flags, sampling_period_ns, max_report_latency_ns);
+ return poll_setDelay(&dev->v0, sensor_handle, sampling_period_ns);
+}
+
+int SensorPollContext::poll_flush(struct sensors_poll_device_1* dev, int sensor_handle)
+{
+ ALOGD("%s: dev=%p sensor_handle=%d", __FUNCTION__, dev, sensor_handle);
+ return EXIT_SUCCESS;
+}
+
int SensorPollContext::doPoll(sensors_event_t *data, int cnt)
{
if (!isValid())
}
static struct hw_module_methods_t sensors_methods = {
- open: open_iio_sensors
+ .open = open_iio_sensors
};
struct sensors_module_t HAL_MODULE_INFO_SYM = {
- common: {
- tag: HARDWARE_MODULE_TAG,
- version_major: 1,
- version_minor: 0,
- id: SENSORS_HARDWARE_MODULE_ID,
- name: "IIO Sensors",
- author: "Chih-Wei Huang",
- methods: &sensors_methods,
- dso: 0,
- reserved: { }
+ .common = {
+ .tag = HARDWARE_MODULE_TAG,
+ .module_api_version = 1,
+ .hal_api_version = 0,
+ .id = SENSORS_HARDWARE_MODULE_ID,
+ .name = "IIO Sensors",
+ .author = "Chih-Wei Huang",
+ .methods = &sensors_methods,
+ .dso = 0,
+ .reserved = { }
},
- get_sensors_list: sensors_get_sensors_list,
- set_operation_mode: 0
+ .get_sensors_list = sensors_get_sensors_list,
+ .set_operation_mode = 0
};