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