OSDN Git Service

Enable Gauss-2-uT conversion for interrupt mode magneto
[android-x86/hardware-intel-libsensors.git] / control.c
index 24ed7ae..cceb3c0 100644 (file)
--- a/control.c
+++ b/control.c
@@ -21,7 +21,7 @@
 #include "calibration.h"
 #include "description.h"
 #include "filtering.h"
-
+#include <linux/iio/events.h>
 /* Currently active sensors count, per device */
 static int poll_sensors_per_dev[MAX_DEVICES];          /* poll-mode sensors                            */
 static int trig_sensors_per_dev[MAX_DEVICES];          /* trigger, event based                         */
@@ -439,6 +439,7 @@ int adjust_counters (int s, int enabled, int from_virtual)
 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  */
@@ -447,6 +448,8 @@ static int get_field_count (int s, size_t *field_size)
                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          */
@@ -533,7 +536,7 @@ static void* acquisition_routine (void* param)
        /* Initialize data fields that will be shared by all sensor reports */
        data.version    = sizeof(sensors_event_t);
        data.sensor     = s;
-       data.type       = sensor[s].type;
+       data.type       = sensor_desc[s].type;
 
        num_fields = get_field_count(s, &field_size);
 
@@ -743,6 +746,7 @@ static int sensor_set_rate (int s, float requested_rate)
        float group_max_sampling_rate;
        float cur_sampling_rate; /* Currently used sampling rate              */
        float arb_sampling_rate; /* Granted sampling rate after arbitration   */
+       char hrtimer_sampling_path[PATH_MAX];
 
        ALOGV("Sampling rate %g requested on sensor %d (%s)\n", requested_rate, s, sensor[s].friendly_name);
 
@@ -874,6 +878,11 @@ static int sensor_set_rate (int s, float requested_rate)
 
        ALOGI("Sensor %d (%s) sampling rate set to %g\n", s, sensor[s].friendly_name, arb_sampling_rate);
 
+       if (sensor[s].hrtimer_trigger_name[0] != '\0') {
+               snprintf (hrtimer_sampling_path, PATH_MAX, "%s%s/%s", CONFIGFS_TRIGGER_PATH, sensor[s].hrtimer_trigger_name, "sampling_frequency");
+               sysfs_write_float(hrtimer_sampling_path, arb_sampling_rate);
+       }
+
        if (trig_sensors_per_dev[dev_num])
                enable_buffer(dev_num, 0);
 
@@ -988,7 +997,11 @@ int sensor_activate (int s, int enabled, int from_virtual)
                if (trig_sensors_per_dev[dev_num]) {
 
                        /* Start sampling */
-                       setup_trigger(s, sensor[s].init_trigger_name);
+                       if (sensor[s].hrtimer_trigger_name[0] != '\0')
+                               setup_trigger(s, sensor[s].hrtimer_trigger_name);
+                       else
+                               setup_trigger(s, sensor[s].init_trigger_name);
+
                        enable_buffer(dev_num, 1);
                }
        } else if (sensor[s].mode == MODE_POLL) {
@@ -1341,7 +1354,7 @@ static int propagate_vsensor_report (int s, sensors_event_t *data)
        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;
 }
 
@@ -1377,7 +1390,7 @@ static int propagate_sensor_report (int s, sensors_event_t *data)
 
        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) {