#include "transform.h"
#include "utils.h"
#include "filtering.h"
-
+#include "enumeration.h"
#define GYRO_MIN_SAMPLES 5 /* Drop first few gyro samples after enable */
#define BIT(x) (1 << (x))
+#define PROXIMITY_THRESHOLD 1
+
inline unsigned int set_bit_range (int start, int end)
{
int i;
data[i] = temp[i];
}
+static void mount_correction (float* data, float mm[9])
+{
+ int i;
+ float temp[3];
+
+ for (i=0; i<3; i++)
+ temp[i] = data[0] * mm[i * 3] + data[1] * mm[i * 3 + 1] + data[2] * mm[i * 3 + 2];
+
+ for (i=0; i<3; i++)
+ data[i] = temp[i];
+}
static void clamp_gyro_readings_to_zero (int s, sensors_event_t* data)
{
/* Swap fields if we have a custom channel ordering on this sensor */
if (sensor[s].quirks & QUIRK_FIELD_ORDERING)
reorder_fields(data->data, sensor[s].order);
+ if (sensor[s].quirks & QUIRK_MOUNTING_MATRIX)
+ mount_correction(data->data, sensor[s].mounting_matrix);
sensor[s].event_count++;
+
switch (sensor[s].type) {
case SENSOR_TYPE_ACCELEROMETER:
/* Always consider the accelerometer accurate */
clamp_gyro_readings_to_zero(s, data);
break;
+ case SENSOR_TYPE_PROXIMITY:
+ /*
+ * See iio spec for in_proximity* - depending on the device
+ * this value is either in meters either unit-less and cannot
+ * be translated to SI units. Where the translation is not possible
+ * lower values indicate something is close and higher ones indicate distance.
+ */
+ if (data->data[0] > PROXIMITY_THRESHOLD)
+ data->data[0] = PROXIMITY_THRESHOLD;
+
+ /* ... fall through ... */
case SENSOR_TYPE_LIGHT:
case SENSOR_TYPE_AMBIENT_TEMPERATURE:
case SENSOR_TYPE_TEMPERATURE:
+ case SENSOR_TYPE_INTERNAL_ILLUMINANCE:
+ case SENSOR_TYPE_INTERNAL_INTENSITY:
/* Only keep two decimals for these readings */
data->data[0] = 0.01 * ((int) (data->data[0] * 100));
- /* ... fall through ... */
-
- case SENSOR_TYPE_PROXIMITY:
/* These are on change sensors ; drop the sample if it has the same value as the previously reported one. */
if (data->data[0] == sensor[s].prev_val.data)
return 0;
return 0;
sensor[s].prev_val.data64 = data->u64.data[0];
break;
+
}
/* If there are active virtual sensors depending on this one - process the event */
float scale = sensor[s].scale ? sensor[s].scale : sensor[s].channel[c].scale;
/* In case correction has been requested using properties, apply it */
- scale *= sensor[s].channel[c].opt_scale;
+ float correction = sensor[s].channel[c].opt_scale;
+
+ /* Correlated with "acquire_immediate_value" method */
+ if (sensor[s].type == SENSOR_TYPE_MAGNETIC_FIELD)
+ return CONVERT_GAUSS_TO_MICROTESLA((sensor[s].offset + s64) * scale) * correction;
/* Apply default scaling rules */
- return (sensor[s].offset + s64) * scale;
+ return (sensor[s].offset + s64) * scale * correction;
}
/* 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:
const char* input_path = sensor_catalog[i].channel[c].input_path;
float scale = sensor[s].scale ? sensor[s].scale : sensor[s].channel[c].scale;
float offset = sensor[s].offset;
- int sensor_type = sensor_catalog[i].type;
float correction;
/* In case correction has been requested using properties, apply it */
* There is no transform ops defined yet for raw sysfs values.
* Use this function to perform transformation as well.
*/
- if (sensor_type == SENSOR_TYPE_MAGNETIC_FIELD)
+ if (sensor[s].type == SENSOR_TYPE_MAGNETIC_FIELD)
return CONVERT_GAUSS_TO_MICROTESLA ((val + offset) * scale) * correction;
return (val + offset) * scale * correction;