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 final 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 a 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    /**
70     * A constant describing a temperature sensor type
71     *
72     * @deprecated use
73     *             {@link android.hardware.Sensor#TYPE_AMBIENT_TEMPERATURE
74     *             Sensor.TYPE_AMBIENT_TEMPERATURE} instead.
75     */
76    @Deprecated
77    public static final int TYPE_TEMPERATURE = 7;
78
79    /**
80     * A constant describing a proximity sensor type. See
81     * {@link android.hardware.SensorEvent#values SensorEvent.values} for more
82     * details.
83     */
84    public static final int TYPE_PROXIMITY = 8;
85
86    /**
87     * A constant describing a gravity sensor type.
88     * See {@link android.hardware.SensorEvent SensorEvent}
89     * for more details.
90     */
91    public static final int TYPE_GRAVITY = 9;
92
93    /**
94     * A constant describing a linear acceleration sensor type.
95     * See {@link android.hardware.SensorEvent SensorEvent}
96     * for more details.
97     */
98    public static final int TYPE_LINEAR_ACCELERATION = 10;
99
100    /**
101     * A constant describing a rotation vector sensor type.
102     * See {@link android.hardware.SensorEvent SensorEvent}
103     * for more details.
104     */
105    public static final int TYPE_ROTATION_VECTOR = 11;
106
107    /**
108     * A constant describing a relative humidity sensor type.
109     * See {@link android.hardware.SensorEvent SensorEvent}
110     * for more details.
111     */
112    public static final int TYPE_RELATIVE_HUMIDITY = 12;
113
114    /** A constant describing an ambient temperature sensor type */
115    public static final int TYPE_AMBIENT_TEMPERATURE = 13;
116
117    /**
118     * A constant describing all sensor types.
119     */
120    public static final int TYPE_ALL = -1;
121
122    /* Some of these fields are set only by the native bindings in
123     * SensorManager.
124     */
125    private String  mName;
126    private String  mVendor;
127    private int     mVersion;
128    private int     mHandle;
129    private int     mType;
130    private float   mMaxRange;
131    private float   mResolution;
132    private float   mPower;
133    private int     mMinDelay;
134
135
136    Sensor() {
137    }
138
139    /**
140     * @return name string of the sensor.
141     */
142    public String getName() {
143        return mName;
144    }
145
146    /**
147     * @return vendor string of this sensor.
148     */
149    public String getVendor() {
150        return mVendor;
151    }
152
153    /**
154     * @return generic type of this sensor.
155     */
156    public int getType() {
157        return mType;
158    }
159
160    /**
161     * @return version of the sensor's module.
162     */
163    public int getVersion() {
164        return mVersion;
165    }
166
167    /**
168     * @return maximum range of the sensor in the sensor's unit.
169     */
170    public float getMaximumRange() {
171        return mMaxRange;
172    }
173
174    /**
175     * @return resolution of the sensor in the sensor's unit.
176     */
177    public float getResolution() {
178        return mResolution;
179    }
180
181    /**
182     * @return the power in mA used by this sensor while in use
183     */
184    public float getPower() {
185        return mPower;
186    }
187
188    /**
189     * @return the minimum delay allowed between two events in microsecond
190     * or zero if this sensor only returns a value when the data it's measuring
191     * changes.
192     */
193    public int getMinDelay() {
194        return mMinDelay;
195    }
196
197    int getHandle() {
198        return mHandle;
199    }
200
201    void setRange(float max, float res) {
202        mMaxRange = max;
203        mResolution = res;
204    }
205
206    @Override
207    public String toString() {
208        return "{Sensor name=\"" + mName + "\", vendor=\"" + mVendor + "\", version=" + mVersion
209                + ", type=" + mType + ", maxRange=" + mMaxRange + ", resolution=" + mResolution
210                + ", power=" + mPower + ", minDelay=" + mMinDelay + "}";
211    }
212}
213