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); getMinDelay()52 virtual int64_t getMinDelay() { return mMinDelay; } 53 54 // unnecessary for MPL readEvents(sensors_event_t * data,int count)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); providesCalibration()59 int providesCalibration() { return 0; } 60 void getOrientationMatrix(signed char *orient); 61 long getSensitivity(); getAccuracy()62 int getAccuracy() { return 0; } 63 void fillList(struct sensor_t *list); isIntegrated()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 *buffer_length; 78 79 char *compass_enable; 80 char *compass_x_fifo_enable; 81 char *compass_y_fifo_enable; 82 char *compass_z_fifo_enable; 83 char *compass_rate; 84 char *compass_scale; 85 char *compass_orient; 86 char *compass_attr_1; 87 } compassSysFs; 88 89 char dev_full_name[20]; 90 91 // implementation specific 92 signed char mCompassOrientation[9]; 93 long mCachedCompassData[3]; 94 int64_t mCompassTimestamp; 95 InputEventCircularReader mCompassInputReader; 96 int compass_fd; 97 int64_t mDelay; 98 int64_t mMinDelay; 99 int mEnable; 100 char *pathP; 101 102 char mIIOBuffer[(8 + 8) * IIO_BUFFER_LENGTH]; 103 104 int masterEnable(int en); 105 void enable_iio_sysfs(void); 106 void processCompassEvent(const input_event *event); 107 int inv_init_sysfs_attributes(void); 108 FILE *mCoilsResetFd; 109 bool mYasCompass; 110 }; 111 112 /*****************************************************************************/ 113 114 #endif // COMPASS_SENSOR_H 115