* from the same iio device as the base one.
*/
-struct sensor_catalog_entry_t sensor_catalog[] = {
+sensor_catalog_entry_t sensor_catalog[] = {
DECLARE_SENSOR3("accel", SENSOR_TYPE_ACCELEROMETER, "x", "y", "z")
DECLARE_SENSOR3("anglvel", SENSOR_TYPE_GYROSCOPE, "x", "y", "z")
DECLARE_SENSOR3("magn", SENSOR_TYPE_MAGNETIC_FIELD, "x", "y", "z")
"quat_x", "quat_y", "quat_z", "quat_w")
DECLARE_SENSOR0("temp", SENSOR_TYPE_AMBIENT_TEMPERATURE )
DECLARE_SENSOR0("proximity", SENSOR_TYPE_PROXIMITY )
- DECLARE_VIRTUAL(SENSOR_TYPE_GYROSCOPE_UNCALIBRATED)
+ DECLARE_VIRTUAL(SENSOR_TYPE_GYROSCOPE_UNCALIBRATED )
};
#define CATALOG_SIZE ARRAY_SIZE(sensor_catalog)
/* We equate sensor handles to indices in these tables */
-struct sensor_t sensor_desc[MAX_SENSORS]; /* Android-level descriptors */
-struct sensor_info_t sensor[MAX_SENSORS]; /* Internal descriptors */
-int sensor_count; /* Detected sensors */
+struct sensor_t sensor_desc[MAX_SENSORS]; /* Android-level descriptors */
+sensor_info_t sensor[MAX_SENSORS]; /* Internal descriptors */
+int sensor_count; /* Detected sensors */
-static void setup_properties_from_pld(int s, int panel, int rotation,
- int num_channels)
+
+static void setup_properties_from_pld (int s, int panel, int rotation,
+ int num_channels)
{
/*
* Generate suitable order and opt_scale directives from the PLD panel
setup_properties_from_pld(s, panel, rotation, num_channels);
}
-static void populate_descriptors(int s, int sensor_type)
+
+static void populate_descriptors (int s, int sensor_type)
{
+ int32_t min_delay_us;
+ max_delay_t max_delay_us;
+
/* Initialize Android-visible descriptor */
sensor_desc[s].name = sensor_get_name(s);
sensor_desc[s].vendor = sensor_get_vendor(s);
sensor_desc[s].maxRange = sensor_get_max_range(s);
sensor_desc[s].resolution = sensor_get_resolution(s);
sensor_desc[s].power = sensor_get_power(s);
- sensor_desc[s].stringType = sensor_get_string_type(s);
+ sensor_desc[s].stringType = sensor_get_string_type(s);
- /* None of our supported sensors requires a special permission.
- * If this will be the case we should implement a sensor_get_perm
- */
+ /* None of our supported sensors requires a special permission */
sensor_desc[s].requiredPermission = "";
+
sensor_desc[s].flags = sensor_get_flags(s);
sensor_desc[s].minDelay = sensor_get_min_delay(s);
sensor_desc[s].maxDelay = sensor_get_max_delay(s);
- ALOGI("Sensor %d (%s) type(%d) minD(%d) maxD(%d) flags(%2.2x)\n",
+ ALOGV("Sensor %d (%s) type(%d) minD(%d) maxD(%d) flags(%2.2x)\n",
s, sensor[s].friendly_name, sensor_desc[s].type,
- sensor_desc[s].minDelay, sensor_desc[s].maxDelay, sensor_desc[s].flags);
+ sensor_desc[s].minDelay, sensor_desc[s].maxDelay,
+ sensor_desc[s].flags);
- /* We currently do not implement batching when we'll so
- * these should be overriden appropriately
- */
+ /* We currently do not implement batching */
sensor_desc[s].fifoReservedEventCount = 0;
sensor_desc[s].fifoMaxEventCount = 0;
+
+ min_delay_us = sensor_desc[s].minDelay;
+ max_delay_us = sensor_desc[s].maxDelay;
+
+ sensor[s].min_supported_rate = max_delay_us ? 1000000.0 / max_delay_us : 1;
+ sensor[s].max_supported_rate = min_delay_us && min_delay_us != -1 ? 1000000.0 / min_delay_us : 0;
}
+
static void add_virtual_sensor (int catalog_index)
{
int s;
sensor_count++;
}
+
static void add_sensor (int dev_num, int catalog_index, int use_polling)
{
int s;
* so try to store it in sensor's scale file
*/
if (sysfs_write_float(sysfs_path, scale) == -1 && errno == ENOENT) {
- ALOGE("Failed to store scale[%f] into %s - file is missing", scale, sysfs_path);
+ ALOGE("Failed to store scale[%g] into %s - file is missing", scale, sysfs_path);
/* Store failed, try to store the scale into channel specific file */
for (c = 0; c < num_channels; c++)
{
sprintf(sysfs_path, BASE_PATH "%s", dev_num,
sensor_catalog[catalog_index].channel[c].scale_path);
if (sysfs_write_float(sysfs_path, scale) == -1)
- ALOGE("Failed to store scale[%f] into %s", scale, sysfs_path);
+ ALOGE("Failed to store scale[%g] into %s", scale, sysfs_path);
}
}
}
sprintf(sysfs_path, SENSOR_SCALE_PATH, dev_num, prefix);
if (!sysfs_read_float(sysfs_path, &scale)) {
sensor[s].scale = scale;
- ALOGI("Scale path:%s scale:%f dev_num:%d\n",
+ ALOGV("Scale path:%s scale:%g dev_num:%d\n",
sysfs_path, scale, dev_num);
} else {
sensor[s].scale = 1;
sensor[s].channel[c].scale = scale;
sensor[s].scale = 0;
- ALOGI( "Scale path:%s "
- "channel scale:%f dev_num:%d\n",
+ ALOGV( "Scale path:%s "
+ "channel scale:%g dev_num:%d\n",
sysfs_path, scale, dev_num);
}
}
switch (sensor_type) {
case SENSOR_TYPE_GYROSCOPE:
- sensor[s].cal_data = malloc(sizeof(struct gyro_cal_t));
+ sensor[s].cal_data = malloc(sizeof(gyro_cal_t));
break;
case SENSOR_TYPE_MAGNETIC_FIELD:
- sensor[s].cal_data = malloc(sizeof(struct compass_cal_t));
+ sensor[s].cal_data = malloc(sizeof(compass_cal_t));
break;
}
sensor[s].max_cal_level = sensor_get_cal_steps(s);
+
/* Select one of the available sensor sample processing styles */
select_transform(s);
}
-static void orientation_sensor_check(void)
+static void orientation_sensor_check (void)
{
/*
* If we have accel + gyro + magn but no rotation vector sensor,
}
}
+
static void propose_new_trigger (int s, char trigger_name[MAX_NAME_SIZE],
int sensor_name_len)
{
}
}
+
static void uncalibrated_gyro_check (void)
{
unsigned int has_gyr = 0;
if (has_gyr) {
uncal_idx = sensor_count;
sensor[uncal_idx].base_count = 1;
- sensor[uncal_idx].base_idx[0] = cal_idx;
+ sensor[uncal_idx].base[0] = cal_idx;
for (i=0; i<catalog_size; i++)
if (sensor_catalog[i].type == SENSOR_TYPE_GYROSCOPE_UNCALIBRATED) {
}
}
+
void enumerate_sensors (void)
{
/*
{
int i;
for (i = 0; i < sensor_count; i++)
- switch (sensor[i].type) {
- case SENSOR_TYPE_MAGNETIC_FIELD:
- if (sensor[i].cal_data != NULL) {
- free(sensor[i].cal_data);
- sensor[i].cal_data = NULL;
- sensor[i].cal_level = 0;
- }
- break;
-
- case SENSOR_TYPE_GYROSCOPE:
- if (sensor[i].cal_data != NULL) {
- free(sensor[i].cal_data);
- sensor[i].cal_data = NULL;
- sensor[i].cal_level = 0;
- }
- break;
+ if (sensor[i].cal_data) {
+ free(sensor[i].cal_data);
+ sensor[i].cal_data = NULL;
+ sensor[i].cal_level = 0;
+ }
- default:
- break;
- }
/* Reset sensor count */
sensor_count = 0;
}