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