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 // TODO fixme, need input_event
     26 #include <stdint.h>
     27 #include <errno.h>
     28 #include <sys/cdefs.h>
     29 #include <sys/types.h>
     30 #include <poll.h>
     31 #include <utils/Vector.h>
     32 #include <utils/KeyedVector.h>
     33 
     34 #include "sensors.h"
     35 #include "SensorBase.h"
     36 #include "InputEventReader.h"
     37 
     38 #define MAX_CHIP_ID_LEN (20)
     39 #define COMPASS_ON_PRIMARY "in_magn_x_raw"
     40 
     41 class CompassSensor : public SensorBase {
     42 
     43 public:
     44     CompassSensor();
     45     virtual ~CompassSensor();
     46 
     47     virtual int getFd() const;
     48     virtual int enable(int32_t handle, int enabled);
     49     virtual int setDelay(int32_t handle, int64_t ns);
     50     virtual int getEnable(int32_t handle);
     51     virtual int64_t getDelay(int32_t handle);
     52     virtual int64_t getMinDelay() { return mMinDelay; }
     53 
     54     // unnecessary for MPL
     55     virtual int readEvents(sensors_event_t *data, int count) { return 0; }
     56 
     57     int readSample(long *data, int64_t *timestamp);
     58     int readRawSample(float *data, int64_t *timestamp);
     59     int providesCalibration() { return 0; }
     60     void getOrientationMatrix(signed char *orient);
     61     long getSensitivity();
     62     int getAccuracy() { return 0; }
     63     void fillList(struct sensor_t *list);
     64     int isIntegrated() { return (0); }
     65     int checkCoilsReset(void);
     66     int isYasCompass(void);
     67 
     68 private:
     69     enum CompassBus {
     70         COMPASS_BUS_PRIMARY = 0,
     71         COMPASS_BUS_SECONDARY = 1
     72     } mI2CBus;
     73 
     74     struct sysfs_attrbs {
     75        char *chip_enable;
     76        char *in_timestamp_en;
     77        char *trigger_name;
     78        char *current_trigger;
     79        char *buffer_length;
     80 
     81        char *compass_enable;
     82        char *compass_x_fifo_enable;
     83        char *compass_y_fifo_enable;
     84        char *compass_z_fifo_enable;
     85        char *compass_rate;
     86        char *compass_scale;
     87        char *compass_orient;
     88        char *compass_attr_1;
     89     } compassSysFs;
     90 
     91     char dev_full_name[20];
     92 
     93     // implementation specific
     94     signed char mCompassOrientation[9];
     95     long mCachedCompassData[3];
     96     int64_t mCompassTimestamp;
     97     InputEventCircularReader mCompassInputReader;
     98     int compass_fd;
     99     int64_t mDelay;
    100     int64_t mMinDelay;
    101     int mEnable;
    102     char *pathP;
    103 
    104     char mIIOBuffer[(8 + 8) * IIO_BUFFER_LENGTH];
    105 
    106     int masterEnable(int en);
    107     void enable_iio_sysfs(void);
    108     void processCompassEvent(const input_event *event);
    109     int inv_init_sysfs_attributes(void);
    110     FILE *mCoilsResetFd;
    111     bool mYasCompass;
    112 };
    113 
    114 /*****************************************************************************/
    115 
    116 #endif  // COMPASS_SENSOR_H
    117