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 turnOffCompassFifo(void);
55    int turnOnCompassFifo(void);
56    int readSample(long *data, int64_t *timestamp);
57    int providesCalibration() { return 0; }
58    void getOrientationMatrix(signed char *orient);
59    long getSensitivity();
60    int getAccuracy() { return 0; }
61    void fillList(struct sensor_t *list);
62    int isIntegrated() { return (1); }
63    int isYasCompass(void) { return (0); }
64    int checkCoilsReset(void) { return(-1); }
65
66private:
67    char sensor_name[200];
68    enum CompassBus {
69        COMPASS_BUS_PRIMARY = 0,
70        COMPASS_BUS_SECONDARY = 1
71    } mI2CBus;
72
73    struct sysfs_attrbs {
74       char *compass_enable;
75       char *compass_fifo_enable;
76       char *compass_x_fifo_enable;
77       char *compass_y_fifo_enable;
78       char *compass_z_fifo_enable;
79       char *compass_rate;
80       char *compass_scale;
81       char *compass_orient;
82    } compassSysFs;
83
84    // implementation specific
85    signed char mCompassOrientation[9];
86    long mCachedCompassData[3];
87    int compass_fd;
88    int64_t mCompassTimestamp;
89    InputEventCircularReader mCompassInputReader;
90    int64_t mDelay;
91    int mEnable;
92    char *pathP;
93
94    void processCompassEvent(const input_event *event);
95    int inv_init_sysfs_attributes(void);
96};
97
98/*****************************************************************************/
99
100#endif  // COMPASS_SENSOR_H
101