blob: f2b907bfd234478b1f6b5db2c5229589e64d8c6a [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
Mathias Agopian74cde2c2010-06-16 18:55:46 -070020/**
21 * Class representing a sensor. Use {@link SensorManager#getSensorList} to get
22 * the list of available Sensors.
Mathias Agopian0f791a72010-06-22 21:55:01 -070023 *
24 * @see SensorManager
25 * @see SensorEventListener
26 * @see SensorEvent
27 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028 */
29public class Sensor {
30
Mathias Agopian74cde2c2010-06-16 18:55:46 -070031 /**
32 * A constant describing an accelerometer sensor type. See
Mathias Agopian0f791a72010-06-22 21:55:01 -070033 * {@link android.hardware.SensorEvent#values SensorEvent.values} for more
34 * details.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035 */
Mathias Agopian74cde2c2010-06-16 18:55:46 -070036 public static final int TYPE_ACCELEROMETER = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
Mathias Agopian74cde2c2010-06-16 18:55:46 -070038 /**
39 * A constant describing a magnetic field sensor type. See
Mathias Agopian0f791a72010-06-22 21:55:01 -070040 * {@link android.hardware.SensorEvent#values SensorEvent.values} for more
41 * details.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 */
43 public static final int TYPE_MAGNETIC_FIELD = 2;
Mathias Agopian74cde2c2010-06-16 18:55:46 -070044
45 /**
46 * A constant describing an orientation sensor type. See
Mathias Agopian0f791a72010-06-22 21:55:01 -070047 * {@link android.hardware.SensorEvent#values SensorEvent.values} for more
48 * details.
Mathias Agopian74cde2c2010-06-16 18:55:46 -070049 *
Mathias Agopian61a44932010-02-26 18:06:26 -080050 * @deprecated use {@link android.hardware.SensorManager#getOrientation
Mathias Agopian74cde2c2010-06-16 18:55:46 -070051 * SensorManager.getOrientation()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 */
Mathias Agopian61a44932010-02-26 18:06:26 -080053 @Deprecated
Mathias Agopian74cde2c2010-06-16 18:55:46 -070054 public static final int TYPE_ORIENTATION = 3;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055
56 /** A constant describing a gyroscope sensor type */
Mathias Agopian74cde2c2010-06-16 18:55:46 -070057 public static final int TYPE_GYROSCOPE = 4;
58
Mike Lockwood4115c512009-11-03 10:35:43 -050059 /**
Mathias Agopian74cde2c2010-06-16 18:55:46 -070060 * A constant describing an light sensor type. See
Mathias Agopian0f791a72010-06-22 21:55:01 -070061 * {@link android.hardware.SensorEvent#values SensorEvent.values} for more
62 * details.
Mike Lockwood4115c512009-11-03 10:35:43 -050063 */
Mathias Agopian74cde2c2010-06-16 18:55:46 -070064 public static final int TYPE_LIGHT = 5;
Mathias Agopian210fc912010-02-26 13:51:39 -080065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 /** A constant describing a pressure sensor type */
Mathias Agopian74cde2c2010-06-16 18:55:46 -070067 public static final int TYPE_PRESSURE = 6;
Mathias Agopian210fc912010-02-26 13:51:39 -080068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 /** A constant describing a temperature sensor type */
Mathias Agopian74cde2c2010-06-16 18:55:46 -070070 public static final int TYPE_TEMPERATURE = 7;
Mathias Agopian210fc912010-02-26 13:51:39 -080071
Mike Lockwood4115c512009-11-03 10:35:43 -050072 /**
Mathias Agopian74cde2c2010-06-16 18:55:46 -070073 * A constant describing an proximity sensor type. See
Mathias Agopian0f791a72010-06-22 21:55:01 -070074 * {@link android.hardware.SensorEvent#values SensorEvent.values} for more
75 * details.
Mike Lockwood4115c512009-11-03 10:35:43 -050076 */
Mathias Agopian74cde2c2010-06-16 18:55:46 -070077 public static final int TYPE_PROXIMITY = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078
Mathias Agopian74cde2c2010-06-16 18:55:46 -070079 /**
Kevin Powellf35fd952010-07-19 19:10:40 -070080 * A constant describing a gravity sensor type.
81 * See {@link android.hardware.SensorEvent SensorEvent}
82 * for more details.
83 */
84 public static final int TYPE_GRAVITY = 9;
85
86 /**
87 * A constant describing a linear acceleration sensor type.
88 * See {@link android.hardware.SensorEvent SensorEvent}
89 * for more details.
90 */
91 public static final int TYPE_LINEAR_ACCELERATION = 10;
92
93 /**
94 * A constant describing a rotation vector sensor type.
95 * See {@link android.hardware.SensorEvent SensorEvent}
96 * for more details.
97 */
98 public static final int TYPE_ROTATION_VECTOR = 11;
99
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 /**
101 * A constant describing all sensor types.
102 */
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700103 public static final int TYPE_ALL = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700105 /* Some of these fields are set only by the native bindings in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 * SensorManager.
107 */
108 private String mName;
109 private String mVendor;
110 private int mVersion;
111 private int mHandle;
112 private int mType;
113 private float mMaxRange;
114 private float mResolution;
115 private float mPower;
Mathias Agopian050b5622010-07-29 16:51:38 -0700116 private int mMinDelay;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 private int mLegacyType;
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700118
119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 Sensor() {
121 }
122
123 /**
124 * @return name string of the sensor.
125 */
126 public String getName() {
127 return mName;
128 }
129
130 /**
131 * @return vendor string of this sensor.
132 */
133 public String getVendor() {
134 return mVendor;
135 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 /**
138 * @return generic type of this sensor.
139 */
140 public int getType() {
141 return mType;
142 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 /**
145 * @return version of the sensor's module.
146 */
147 public int getVersion() {
148 return mVersion;
149 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 /**
152 * @return maximum range of the sensor in the sensor's unit.
153 */
154 public float getMaximumRange() {
155 return mMaxRange;
156 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 /**
159 * @return resolution of the sensor in the sensor's unit.
160 */
161 public float getResolution() {
162 return mResolution;
163 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 /**
166 * @return the power in mA used by this sensor while in use
167 */
168 public float getPower() {
169 return mPower;
170 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700171
Mathias Agopian050b5622010-07-29 16:51:38 -0700172 /**
173 * @return the minimum delay allowed between two events in microsecond
174 * or zero if this sensor only returns a value when the data it's measuring
175 * changes.
176 */
177 public int getMinDelay() {
178 return mMinDelay;
179 }
180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 int getHandle() {
182 return mHandle;
183 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 void setRange(float max, float res) {
186 mMaxRange = max;
187 mResolution = res;
188 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 void setLegacyType(int legacyType) {
191 mLegacyType = legacyType;
192 }
193
194 int getLegacyType() {
195 return mLegacyType;
196 }
197}