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 38class CompassSensor : public SensorBase { 39 40public: 41 CompassSensor(); 42 virtual ~CompassSensor(); 43 44 virtual int getFd() const; 45 virtual int enable(int32_t handle, int enabled); 46 virtual int setDelay(int32_t handle, int64_t ns); 47 virtual int getEnable(int32_t handle); 48 virtual int64_t getDelay(int32_t handle); 49 virtual int64_t getMinDelay() { return -1; } // stub 50 51 // unnecessary for MPL 52 virtual int readEvents(sensors_event_t *data, int count) { return 0; } 53 54 int readSample(long *data, int64_t *timestamp); 55 int providesCalibration() { return 0; } 56 void getOrientationMatrix(signed char *orient); 57 long getSensitivity(); 58 int getAccuracy() { return 0; } 59 void fillList(struct sensor_t *list); 60 int isIntegrated() { return (1); } 61 int isYasCompass(void) { return (0); } 62 int checkCoilsReset(void) { return(-1); } 63 64private: 65 char sensor_name[200]; 66 enum CompassBus { 67 COMPASS_BUS_PRIMARY = 0, 68 COMPASS_BUS_SECONDARY = 1 69 } mI2CBus; 70 71 struct sysfs_attrbs { 72 char *compass_enable; 73 char *compass_x_fifo_enable; 74 char *compass_y_fifo_enable; 75 char *compass_z_fifo_enable; 76 char *compass_rate; 77 char *compass_scale; 78 char *compass_orient; 79 } compassSysFs; 80 81 // implementation specific 82 signed char mCompassOrientation[9]; 83 long mCachedCompassData[3]; 84 int compass_fd; 85 int64_t mCompassTimestamp; 86 InputEventCircularReader mCompassInputReader; 87 int64_t mDelay; 88 int mEnable; 89 char *pathP; 90 91 void processCompassEvent(const input_event *event); 92 int inv_init_sysfs_attributes(void); 93}; 94 95/*****************************************************************************/ 96 97#endif // COMPASS_SENSOR_H 98