Home | History | Annotate | Download | only in sensor_hub
      1 /*
      2  * Copyright (C) 2008-2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef SENSORS_H_
     18 
     19 #include <poll.h>
     20 
     21 #include <hardware/hardware.h>
     22 #include <hardware/sensors.h>
     23 
     24 /*
     25  * cros_ec_sensors_poll_context_t:
     26  *
     27  * Responsible for implementing the pool functions.
     28  * We are currently polling on 2 files:
     29  * - the IIO ring buffer (via CrosECSensor object)
     30  * - a pipe to sleep on. a call to activate() will wake up
     31  *   the context poll() is running in.
     32  *
     33  * This code could accomodate more than one ring buffer.
     34  * If we implement wake up/non wake up sensors, we would lister to
     35  * iio buffer woken up by sysfs triggers.
     36  */
     37 struct cros_ec_sensors_poll_context_t {
     38     sensors_poll_device_1_t device; // must be first
     39 
     40     cros_ec_sensors_poll_context_t(
     41             const struct hw_module_t *module,
     42             const char *ring_device_name,
     43             const char *ring_trigger_name);
     44 
     45     private:
     46     enum {
     47         crosEcRingFd           = 0,
     48         crosEcWakeFd,
     49         numFds,
     50     };
     51 
     52     static const char WAKE_MESSAGE = 'W';
     53     struct pollfd mPollFds[numFds];
     54     int mWritePipeFd;
     55     CrosECSensor *mSensor;
     56 
     57     ~cros_ec_sensors_poll_context_t();
     58 
     59     int activate(int handle, int enabled);
     60     int setDelay(int handle, int64_t ns);
     61     int pollEvents(sensors_event_t* data, int count);
     62     int batch(int handle, int flags, int64_t period_ns, int64_t timeout);
     63     int flush(int handle);
     64 
     65     static int wrapper_close(struct hw_device_t *dev);
     66     static int wrapper_activate(struct sensors_poll_device_t *dev,
     67             int handle, int enabled);
     68     static int wrapper_setDelay(struct sensors_poll_device_t *dev,
     69             int handle, int64_t ns);
     70     static int wrapper_poll(struct sensors_poll_device_t *dev,
     71             sensors_event_t* data, int count);
     72     static int wrapper_batch(struct sensors_poll_device_1 *dev,
     73             int handle, int flags, int64_t period_ns, int64_t timeout);
     74     static int wrapper_flush(struct sensors_poll_device_1 *dev,
     75             int handle);
     76 
     77 };
     78 
     79 
     80 
     81 #define SENSORS_H_
     82 #endif  /* SENSORS_H_ */
     83