float (*transform)(int s, int c, unsigned char* sample_data);
/* Function called once per sample */
- void (*finalize)(int s, struct sensors_event_t* data);
+ int (*finalize)(int s, struct sensors_event_t* data);
};
struct sensor_info_t
int calibrated;
void* cal_data;
+
+ float prev_val; /* Previously reported value, for on-change sensors */
+
/* Note: we may have to explicitely serialize access to some fields */
};
}
-static void propagate_sensor_report(int s, struct sensors_event_t* data)
+static int propagate_sensor_report(int s, struct sensors_event_t* data)
{
/* There's a sensor report pending for this sensor ; transmit it */
ALOGV("\tfield %d: %f\n", c, data->data[c]);
}
- sensor_info[s].ops.finalize(s, data);
- return;
+ return sensor_info[s].ops.finalize(s, data);
}
/* Convert the data into the expected Android-level format */
current_sample += sensor_info[s].channel[c].size;
}
- sensor_info[s].ops.finalize(s, data);
+ return sensor_info[s].ops.finalize(s, data);
}
for (s=0; s<sensor_count; s++)
if (sensor_info[s].report_pending) {
- /* Return that up */
- propagate_sensor_report(s, data);
+ /* Lower flag */
sensor_info[s].report_pending = 0;
- ALOGV("Report on sensor %d\n", s);
- return 1;
+
+ if (propagate_sensor_report(s, data)) {
+ /* Return that up */
+ ALOGV("Report on sensor %d\n", s);
+ return 1;
+ }
+
+ /*
+ * If the sample was deemed invalid or unreportable,
+ * e.g. had the same value as the previously reported
+ * value for a 'on change' sensor, silently drop it
+ */
}
await_event:
}
-static void finalize_sample_default(int s, struct sensors_event_t* data)
+static int finalize_sample_default(int s, struct sensors_event_t* data)
{
int i = sensor_info[s].catalog_index;
int sensor_type = sensor_catalog[i].type;
calibrate_gyro(data, &sensor_info[s]);
break;
+ case SENSOR_TYPE_LIGHT:
case SENSOR_TYPE_AMBIENT_TEMPERATURE:
case SENSOR_TYPE_TEMPERATURE:
- /* Only keep two decimals for temperature readings */
+ /* Only keep two decimals for these readings */
data->data[0] = 0.01 * ((int) (data->data[0] * 100));
- break;
+ /*
+ * These are on change sensors ; drop the sample if it
+ * has the same value as the previously reported one.
+ */
+ if (data->data[0] == sensor_info[s].prev_val)
+ return 0;
+
+ sensor_info[s].prev_val = data->data[0];
+ break;
}
+
+ return 1; /* Return sample to Android */
}
}
-static void finalize_sample_ISH(int s, struct sensors_event_t* data)
+static int finalize_sample_ISH(int s, struct sensors_event_t* data)
{
int i = sensor_info[s].catalog_index;
int sensor_type = sensor_catalog[i].type;
data->data[1] = -pitch;
data->data[2] = -roll;
}
+
+ return 1; /* Return sample to Android */
}