static int get_field_count (int s, size_t *field_size)
{
*field_size = sizeof(float);
+
switch (sensor[s].type) {
case SENSOR_TYPE_ACCELEROMETER: /* m/s^2 */
case SENSOR_TYPE_MAGNETIC_FIELD: /* micro-tesla */
case SENSOR_TYPE_GYROSCOPE: /* radians/s */
return 3;
+ case SENSOR_TYPE_INTERNAL_INTENSITY:
+ case SENSOR_TYPE_INTERNAL_ILLUMINANCE:
case SENSOR_TYPE_LIGHT: /* SI lux units */
case SENSOR_TYPE_AMBIENT_TEMPERATURE: /* °C */
case SENSOR_TYPE_TEMPERATURE: /* °C */
memcpy(data, &sensor[s].sample, sizeof(sensors_event_t));
data->sensor = s;
- data->type = sensor[s].type;
+ data->type = sensor_desc[s].type; /* sensor_desc[s].type can differ from sensor[s].type ; internal types are remapped */
return 1;
}
data->version = sizeof(sensors_event_t);
data->sensor = s;
- data->type = sensor[s].type;
+ data->type = sensor_desc[s].type; /* sensor_desc[s].type can differ from sensor[s].type ; internal types are remapped */
data->timestamp = sensor[s].report_ts;
if (sensor[s].mode == MODE_EVENT) {
/* We should cap returned samples accordingly... */
- switch (sensor[s].type) {
+ switch (sensor_desc[s].type) {
case SENSOR_TYPE_ACCELEROMETER: /* m/s^2 */
return 50;
char* sensor_get_string_type (int s)
{
- switch (sensor[s].type) {
+ switch (sensor_desc[s].type) {
case SENSOR_TYPE_ACCELEROMETER:
return SENSOR_STRING_TYPE_ACCELEROMETER;
{
flag_t flags = 0;
- switch (sensor[s].type) {
+ switch (sensor_desc[s].type) {
case SENSOR_TYPE_LIGHT:
case SENSOR_TYPE_AMBIENT_TEMPERATURE:
case SENSOR_TYPE_TEMPERATURE:
static int get_cdd_freq (int s, int must)
{
- switch (sensor[s].type) {
+ switch (sensor_desc[s].type) {
case SENSOR_TYPE_ACCELEROMETER:
return (must ? 100 : 200); /* must 100 Hz, should 200 Hz, CDD compliant */
},
{
.tag = "intensity",
- .type = SENSOR_TYPE_LIGHT,
+ .type = SENSOR_TYPE_INTERNAL_INTENSITY,
.num_channels = 1,
.is_virtual = 0,
.channel = {
},
{
.tag = "illuminance",
- .type = SENSOR_TYPE_LIGHT,
+ .type = SENSOR_TYPE_INTERNAL_ILLUMINANCE,
.num_channels = 1,
.is_virtual = 0,
.channel = {
}
+static int map_internal_to_external_type (int sensor_type)
+{
+ /* Most sensors are internally identified using the Android type, but for some we use a different type specification internally */
+
+ switch (sensor_type) {
+ case SENSOR_TYPE_INTERNAL_ILLUMINANCE:
+ case SENSOR_TYPE_INTERNAL_INTENSITY:
+ return SENSOR_TYPE_LIGHT;
+
+ default:
+ return sensor_type;
+ }
+}
+
static void populate_descriptors (int s, int sensor_type)
{
int32_t min_delay_us;
sensor_desc[s].vendor = sensor_get_vendor(s);
sensor_desc[s].version = sensor_get_version(s);
sensor_desc[s].handle = s;
- sensor_desc[s].type = sensor_type;
+ sensor_desc[s].type = map_internal_to_external_type(sensor_type);
sensor_desc[s].maxRange = sensor_get_max_range(s);
sensor_desc[s].resolution = sensor_get_resolution(s);
* receiving the illumination sensor calibration inputs from
* the Android properties and setting it within sysfs
*/
- if (sensor_type == SENSOR_TYPE_LIGHT) {
+ if (sensor_type == SENSOR_TYPE_INTERNAL_ILLUMINANCE) {
retval = sensor_get_illumincalib(s);
if (retval > 0) {
sprintf(sysfs_path, ILLUMINATION_CALIBPATH, dev_num);
void enumerate_sensors (void);
void delete_enumeration_data (void);
+/*
+ * These are fine-grained type definitions that are used internally, in the sensor array, but mapped to an Android sensor type in the processing pipeline.
+ * The sensor array uses these, not the desc array.
+ */
+#define SENSOR_TYPE_INTERNAL_ILLUMINANCE -1 /* Global illuminance, in lux */
+#define SENSOR_TYPE_INTERNAL_INTENSITY -2 /* Global intensity, in sensor specific units */
+
#endif
#include "transform.h"
#include "utils.h"
#include "filtering.h"
-
+#include "enumeration.h"
#define GYRO_MIN_SAMPLES 5 /* Drop first few gyro samples after enable */
/* In case correction has been requested using properties, apply it */
correction = sensor[s].channel[c].opt_scale;
- switch (sensor[s].type) {
+ switch (sensor_desc[s].type) {
case SENSOR_TYPE_ACCELEROMETER:
switch (c) {
case 0: