Sensor.java revision 61a449393cf29f3960b4e03ec3fad652dac51b88
1/*
2 * Copyright (C) 2008 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
18package android.hardware;
19
20/**
21 * Class representing a sensor. Use {@link SensorManager#getSensorList}
22 * to get the list of available Sensors.
23 */
24public class Sensor {
25
26    /**
27     * A constant describing an accelerometer sensor type.
28     * See {@link android.hardware.SensorEvent SensorEvent}
29     * for more details.
30     */
31    public static final int TYPE_ACCELEROMETER  = 1;
32
33    /**
34     * A constant describing a magnetic field sensor type.
35     * See {@link android.hardware.SensorEvent SensorEvent}
36     * for more details.
37     */
38    public static final int TYPE_MAGNETIC_FIELD = 2;
39
40    /**
41     * A constant describing an orientation sensor type.
42     * See {@link android.hardware.SensorEvent SensorEvent}
43     * for more details.
44     * @deprecated use {@link android.hardware.SensorManager#getOrientation
45     *  SensorManager.getOrientation()} instead.
46     */
47    @Deprecated
48    public static final int TYPE_ORIENTATION    = 3;
49
50    /** A constant describing a gyroscope sensor type */
51    public static final int TYPE_GYROSCOPE      = 4;
52    /**
53     * A constant describing an light sensor type.
54     * See {@link android.hardware.SensorEvent SensorEvent}
55     * for more details.
56     */
57    public static final int TYPE_LIGHT          = 5;
58
59    /** A constant describing a pressure sensor type */
60    public static final int TYPE_PRESSURE       = 6;
61
62    /** A constant describing a temperature sensor type */
63    public static final int TYPE_TEMPERATURE    = 7;
64
65    /**
66     * A constant describing an proximity sensor type.
67     * See {@link android.hardware.SensorEvent SensorEvent}
68     * for more details.
69     */
70    public static final int TYPE_PROXIMITY      = 8;
71
72
73    /**
74     * A constant describing all sensor types.
75     */
76    public static final int TYPE_ALL             = -1;
77
78    /* Some of these fields are set only by the native bindings in
79     * SensorManager.
80     */
81    private String  mName;
82    private String  mVendor;
83    private int     mVersion;
84    private int     mHandle;
85    private int     mType;
86    private float   mMaxRange;
87    private float   mResolution;
88    private float   mPower;
89    private int     mLegacyType;
90
91
92    Sensor() {
93    }
94
95    /**
96     * @return name string of the sensor.
97     */
98    public String getName() {
99        return mName;
100    }
101
102    /**
103     * @return vendor string of this sensor.
104     */
105    public String getVendor() {
106        return mVendor;
107    }
108
109    /**
110     * @return generic type of this sensor.
111     */
112    public int getType() {
113        return mType;
114    }
115
116    /**
117     * @return version of the sensor's module.
118     */
119    public int getVersion() {
120        return mVersion;
121    }
122
123    /**
124     * @return maximum range of the sensor in the sensor's unit.
125     */
126    public float getMaximumRange() {
127        return mMaxRange;
128    }
129
130    /**
131     * @return resolution of the sensor in the sensor's unit.
132     */
133    public float getResolution() {
134        return mResolution;
135    }
136
137    /**
138     * @return the power in mA used by this sensor while in use
139     */
140    public float getPower() {
141        return mPower;
142    }
143
144    int getHandle() {
145        return mHandle;
146    }
147
148    void setRange(float max, float res) {
149        mMaxRange = max;
150        mResolution = res;
151    }
152
153    void setLegacyType(int legacyType) {
154        mLegacyType = legacyType;
155    }
156
157    int getLegacyType() {
158        return mLegacyType;
159    }
160}
161