Home | History | Annotate | Download | only in libsensors_iio
      1 /*
      2  * Copyright (C) 2012 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 COMPASS_SENSOR_H
     18 #define COMPASS_SENSOR_H
     19 
     20 #include <stdint.h>
     21 #include <errno.h>
     22 #include <sys/cdefs.h>
     23 #include <sys/types.h>
     24 
     25 #include "SensorBase.h"
     26 
     27 // TODO: include 3rd-party compass vendor's header file
     28 //       p.s.: before using unified HAL, make sure 3rd-party compass
     29 //       solution's driver/HAL work well by themselves
     30 #include "AkmSensor.h"
     31 
     32 /*****************************************************************************/
     33 
     34 class CompassSensor : public SensorBase {
     35 
     36 protected:
     37 
     38 public:
     39             CompassSensor();
     40     virtual ~CompassSensor();
     41 
     42     // TODO: make sure either 3rd-party compass solution has following virtual
     43     //       functions, or SensorBase.cpp could provide equal functionalities
     44     virtual int getFd() const;
     45     virtual int getRawFd() {return 0;};
     46     virtual int enable(int32_t handle, int enabled);
     47     virtual int setDelay(int32_t handle, int64_t ns);
     48     virtual int getEnable(int32_t handle);
     49     virtual int64_t getDelay(int32_t handle);
     50     virtual int64_t getMinDelay() { return -1; } // stub
     51 
     52     // TODO: unnecessary for MPL solution (override 3rd-party solution)
     53     virtual int readEvents(sensors_event_t *data, int count) { return 0; }
     54 
     55     // TODO: following four APIs need further implementation for MPL's
     56     //       reference (look into .cpp for detailed information, also refer to
     57     //       3rd-party's readEvents() for relevant APIs)
     58     int readSample(long *data, int64_t *timestamp);
     59     int readRawSample(float *data, int64_t *timestamp);
     60     void fillList(struct sensor_t *list);
     61     void getOrientationMatrix(signed char *orient);
     62     int getAccuracy();
     63     virtual void getCompassBias(long *bias) {return;};
     64 
     65     // TODO: if 3rd-party provides calibrated compass data, just return 1
     66     int providesCalibration() { return 1; }
     67 
     68     // TODO: hard-coded for 3rd-party's sensitivity transformation
     69     long getSensitivity() { return (1L << 30); }
     70 
     71     /* all 3rd pary solution have compasses on the primary bus, hence they
     72        have no dependency on the MPU */
     73     int isIntegrated() { return 0; }
     74 
     75     int checkCoilsReset(void) { return 0; };
     76     int isYasCompass(void) { return 0; };
     77 
     78 private:
     79     AkmSensor *mCompassSensor;
     80 };
     81 
     82 /*****************************************************************************/
     83 
     84 #endif  // COMPASS_SENSOR_H
     85