#include <sys/socket.h>
#include <utils/Log.h>
#include <hardware/sensors.h>
-#include <linux/iio/events.h>
+#include <linux/ioctl.h>
#include "control.h"
#include "enumeration.h"
#include "utils.h"
ALOGI("Enabling sensor %d (iio device %d: %s)\n", s, dev_num, sensor[s].friendly_name);
switch (sensor[s].type) {
+ case SENSOR_TYPE_ACCELEROMETER:
+ accel_cal_init(s);
+ break;
+
case SENSOR_TYPE_MAGNETIC_FIELD:
- compass_read_data(&sensor[s]);
+ compass_read_data(s);
break;
case SENSOR_TYPE_GYROSCOPE:
- gyro_cal_init(&sensor[s]);
+ gyro_cal_init(s);
break;
}
} else {
/* Sensor disabled, lower report available flag */
sensor[s].report_pending = 0;
- if (sensor[s].type == SENSOR_TYPE_MAGNETIC_FIELD)
- compass_store_data(&sensor[s]);
+ /* Save calibration data to persistent storage */
+ switch (sensor[s].type) {
+ case SENSOR_TYPE_ACCELEROMETER:
+ accel_cal_store(s);
+ break;
+
+ case SENSOR_TYPE_MAGNETIC_FIELD:
+ compass_store_data(s);
+ break;
- if (sensor[s].type == SENSOR_TYPE_GYROSCOPE)
- gyro_store_data(&sensor[s]);
+ case SENSOR_TYPE_GYROSCOPE:
+ gyro_store_data(s);
+ break;
+ }
}
/* We changed the state of a sensor: adjust device ref counts */
arb_sampling_rate = sensor[s].max_supported_rate;
}
+ /* Record the rate that was agreed upon with the sensor taken in isolation ; this avoid uncontrolled ripple effects between colocated sensor rates */
+ sensor[s].semi_arbitrated_rate = arb_sampling_rate;
+
/* Coordinate with others active sensors on the same device, if any */
if (per_device_sampling_rate)
for (n=0; n<sensor_count; n++)
- if (n != s && sensor[n].dev_num == dev_num && sensor[n].num_channels && is_enabled(n) && sensor[n].sampling_rate > arb_sampling_rate) {
+ if (n != s && sensor[n].dev_num == dev_num && sensor[n].num_channels && is_enabled(n) &&
+ sensor[n].semi_arbitrated_rate > arb_sampling_rate) {
ALOGV("Sampling rate shared between %s and %s, using %g instead of %g\n", sensor[s].friendly_name, sensor[n].friendly_name,
- sensor[n].sampling_rate, arb_sampling_rate);
- arb_sampling_rate = sensor[n].sampling_rate;
+ sensor[n].semi_arbitrated_rate, arb_sampling_rate);
+ arb_sampling_rate = sensor[n].semi_arbitrated_rate;
}
sensor[s].sampling_rate = arb_sampling_rate;
int s;
for (s=0; s<MAX_SENSORS; s++)
- if (sensor[s].dev_num == dev_num && is_enabled(s) && sensor[s].mode != MODE_POLL)
- set_report_ts(s, ts);
+ if (sensor[s].dev_num == dev_num && is_enabled(s) && sensor[s].mode != MODE_POLL) {
+ if (sensor[s].quirks & QUIRK_SPOTTY)
+ set_report_ts(s, ts);
+ else
+ sensor[s].report_ts = ts;
+ }
}
ts = event.timestamp;
- ALOGV("Read event %ld from fd %d of iio device %d\n", event.id, fd, dev_num);
+ ALOGV("Read event %lld from fd %d of iio device %d\n", event.id, fd, dev_num);
/* Map device report to sensor reports */
for (s = 0; s < MAX_SENSORS; s++)