Sensor.h revision a7352c9f4a6e642c29782b19db5bc0bd98feddc8
1/*
2 * Copyright (C) 2010 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 ANDROID_GUI_SENSOR_H
18#define ANDROID_GUI_SENSOR_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/Errors.h>
24#include <utils/String8.h>
25#include <utils/Flattenable.h>
26
27#include <hardware/sensors.h>
28
29#include <android/sensor.h>
30
31// ----------------------------------------------------------------------------
32// Concrete types for the NDK
33struct ASensor { };
34
35// ----------------------------------------------------------------------------
36namespace android {
37// ----------------------------------------------------------------------------
38
39class Parcel;
40
41// ----------------------------------------------------------------------------
42
43class Sensor : public ASensor, public Flattenable
44{
45public:
46    enum {
47        TYPE_ACCELEROMETER  = ASENSOR_TYPE_ACCELEROMETER,
48        TYPE_MAGNETIC_FIELD = ASENSOR_TYPE_MAGNETIC_FIELD,
49        TYPE_GYROSCOPE      = ASENSOR_TYPE_GYROSCOPE,
50        TYPE_LIGHT          = ASENSOR_TYPE_LIGHT,
51        TYPE_PROXIMITY      = ASENSOR_TYPE_PROXIMITY
52    };
53
54            Sensor();
55            Sensor(struct sensor_t const* hwSensor);
56    virtual ~Sensor();
57
58    const String8& getName() const;
59    const String8& getVendor() const;
60    int32_t getHandle() const;
61    int32_t getType() const;
62    float getMinValue() const;
63    float getMaxValue() const;
64    float getResolution() const;
65    float getPowerUsage() const;
66
67    // Flattenable interface
68    virtual size_t getFlattenedSize() const;
69    virtual size_t getFdCount() const;
70    virtual status_t flatten(void* buffer, size_t size,
71            int fds[], size_t count) const;
72    virtual status_t unflatten(void const* buffer, size_t size,
73            int fds[], size_t count);
74
75private:
76    String8 mName;
77    String8 mVendor;
78    int32_t mHandle;
79    int32_t mType;
80    float   mMinValue;
81    float   mMaxValue;
82    float   mResolution;
83    float   mPower;
84};
85
86// ----------------------------------------------------------------------------
87}; // namespace android
88
89#endif // ANDROID_GUI_SENSOR_H
90