The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame^] | 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 | |
| 18 | package android.hardware; |
| 19 | |
| 20 | /** |
| 21 | * Class representing a sensor. Use {@link SensorManager#getSensorList} |
| 22 | * to get the list of available Sensors. |
| 23 | */ |
| 24 | public 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 | */ |
| 45 | public static final int TYPE_ORIENTATION = 3; |
| 46 | |
| 47 | /** A constant describing a gyroscope sensor type */ |
| 48 | public static final int TYPE_GYROSCOPE = 4; |
| 49 | /** A constant describing a light sensor type */ |
| 50 | public static final int TYPE_LIGHT = 5; |
| 51 | /** A constant describing a pressure sensor type */ |
| 52 | public static final int TYPE_PRESSURE = 6; |
| 53 | /** A constant describing a temperature sensor type */ |
| 54 | public static final int TYPE_TEMPERATURE = 7; |
| 55 | /** A constant describing a proximity sensor type */ |
| 56 | public static final int TYPE_PROXIMITY = 8; |
| 57 | |
| 58 | |
| 59 | /** |
| 60 | * A constant describing all sensor types. |
| 61 | */ |
| 62 | public static final int TYPE_ALL = -1; |
| 63 | |
| 64 | /* Some of these fields are set only by the native bindings in |
| 65 | * SensorManager. |
| 66 | */ |
| 67 | private String mName; |
| 68 | private String mVendor; |
| 69 | private int mVersion; |
| 70 | private int mHandle; |
| 71 | private int mType; |
| 72 | private float mMaxRange; |
| 73 | private float mResolution; |
| 74 | private float mPower; |
| 75 | private int mLegacyType; |
| 76 | |
| 77 | |
| 78 | Sensor() { |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @return name string of the sensor. |
| 83 | */ |
| 84 | public String getName() { |
| 85 | return mName; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @return vendor string of this sensor. |
| 90 | */ |
| 91 | public String getVendor() { |
| 92 | return mVendor; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @return generic type of this sensor. |
| 97 | */ |
| 98 | public int getType() { |
| 99 | return mType; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @return version of the sensor's module. |
| 104 | */ |
| 105 | public int getVersion() { |
| 106 | return mVersion; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * @return maximum range of the sensor in the sensor's unit. |
| 111 | */ |
| 112 | public float getMaximumRange() { |
| 113 | return mMaxRange; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * @return resolution of the sensor in the sensor's unit. |
| 118 | */ |
| 119 | public float getResolution() { |
| 120 | return mResolution; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @return the power in mA used by this sensor while in use |
| 125 | */ |
| 126 | public float getPower() { |
| 127 | return mPower; |
| 128 | } |
| 129 | |
| 130 | int getHandle() { |
| 131 | return mHandle; |
| 132 | } |
| 133 | |
| 134 | void setRange(float max, float res) { |
| 135 | mMaxRange = max; |
| 136 | mResolution = res; |
| 137 | } |
| 138 | |
| 139 | void setLegacyType(int legacyType) { |
| 140 | mLegacyType = legacyType; |
| 141 | } |
| 142 | |
| 143 | int getLegacyType() { |
| 144 | return mLegacyType; |
| 145 | } |
| 146 | } |