OSDN Git Service

Winter cleanup: comment harmonization, space shuffling, etc.
[android-x86/hardware-intel-libsensors.git] / common.h
index 1de6af2..3a2da16 100644 (file)
--- a/common.h
+++ b/common.h
 
 #define MAX_TYPE_SPEC_LEN 32   /* Channel type spec len; ex: "le:u10/16>>0" */
 #define MAX_SENSOR_REPORT_SIZE 32      /* Sensor report buffer size */
+#define MAX_DEVICE_REPORT_SIZE 32      /* iio device scan buffer size */
 
 #define MAX_NAME_SIZE          32
 
-#define MIN_SAMPLES 5
+#define MAX_REAL_DEP 3 /* Max number of base sensors a sensor can depend on */
 
 #define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
 #define REPORTING_MODE(x)      ((x) & 0x06)
@@ -65,6 +66,7 @@ struct sensor_catalog_entry_t
        const char *tag; /* Prefix such as "accel", "gyro", "temp"... */
        const int type;  /* Sensor type ; ex: SENSOR_TYPE_ACCELEROMETER */
        const int num_channels; /* Expected iio channels for this sensor */
+       const int is_virtual;  /* Is the sensor virtual or not */
        struct channel_descriptor_t channel[MAX_CHANNELS];
 };
 
@@ -102,7 +104,7 @@ struct sample_ops_t
 
 /*
  * Whenever we have sensor data recorded for a sensor in the associated
- * sensor_info cell, its report_pending field is set to a non-zero value
+ * sensor cell, its report_pending field is set to a non-zero value
  * indicating how we got this data.
  */
 #define DATA_TRIGGER   1       /* From /dev/iio:device fd              */
@@ -131,13 +133,13 @@ struct sensor_info_t
        const char* selected_trigger;
 
        float offset;   /* (cooked = raw + offset) * scale */
-       float scale;    /*default: 1. when set to 0, use channel specific value*/
+       float scale;    /*default:1. when set to 0, use channel specific value*/
        float illumincalib;     /* to set the calibration for the ALS */
 
-       float sampling_rate;    /* requested events / second */
+       float requested_rate;   /* requested events / second */
+       float sampling_rate;    /* setup events / second */
 
        int dev_num;    /* Associated iio dev num, ex: 3 for /dev/iio:device3 */
-       int enable_count;
 
        int catalog_index;/* Associated entry within the sensor_catalog array */
        int type;         /* Sensor type, such as SENSOR_TYPE_GYROSCOPE       */
@@ -165,7 +167,7 @@ struct sensor_info_t
        /*
         * This flag is set if we have a meta data event pending
         */
-       volatile int meta_data_pending;
+       int meta_data_pending;
 
        /*
         * Timestamp closely matching the date of sampling, preferably retrieved
@@ -181,10 +183,18 @@ struct sensor_info_t
        /* Whether or not the above buffer contains data from a device report */
        int report_initialized;
 
+       /* Channel and sample finalization callbacks for this sensor */
        struct sample_ops_t ops;
 
        int cal_level; /* 0 means not calibrated */
-       void* cal_data;
+
+       /*
+        * Depending on the sensor, calibration may take too much time at
+        * higher levels. Allow optional capping to a certain level.
+        */
+       int max_cal_level;
+
+       void *cal_data; /* Sensor calibration data, e.g. for magnetometer */
 
        /* Filtering data for noisy sensors */
        void* filter;
@@ -201,13 +211,32 @@ struct sensor_info_t
        int thread_data_fd[2];
        pthread_t acquisition_thread;
 
-       /* For cal-uncal sensor pairs - index to the pair sensor in sensor_info */
-       int pair_idx;
+       /* How many base sensors is the sensor depending on */
+       int base_count;
+       int base_idx[MAX_REAL_DEP];
 
        uint32_t quirks; /* Bit mask expressing the need for special tweaks */
 
        /* Note: we may have to explicitely serialize access to some fields */
 
+       int is_virtual;
+       /*
+       * Dependency count - for a real sensor how many active virtual sensors are
+       * depending on it
+       */
+       uint32_t ref_count;
+
+       /*
+        * Flag showing if a sensor was enabled directly by Android
+        */
+       uint32_t directly_enabled;
+
+       /*
+        * Current sample for a virtual sensor - when a report is ready we'll
+        * keep the data here until it's finally processed. Can be modified for
+        * more than one at a later time.
+        */
+       struct sensors_event_t sample;
 
        /*
         * If the QUIRK_FIELD_ORDERING bit is set in quirks, the contents of
@@ -236,10 +265,7 @@ struct sensor_info_t
 /* Reference a few commonly used variables... */
 extern int                             sensor_count;
 extern struct sensor_t      sensor_desc[MAX_SENSORS];
-extern struct sensor_info_t            sensor_info[MAX_SENSORS];
+extern struct sensor_info_t            sensor[MAX_SENSORS];
 extern struct sensor_catalog_entry_t   sensor_catalog[];
 
-/* We are required to be in sync with SystemClock.getNanos */
-extern int64_t ts_delta;
-
 #endif