Sensor.java revision f35fd959fe499c61ee0d97d5b0c8feb469397a42
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 * A constant describing a gravity sensor type. 74 * See {@link android.hardware.SensorEvent SensorEvent} 75 * for more details. 76 */ 77 public static final int TYPE_GRAVITY = 9; 78 79 /** 80 * A constant describing a linear acceleration sensor type. 81 * See {@link android.hardware.SensorEvent SensorEvent} 82 * for more details. 83 */ 84 public static final int TYPE_LINEAR_ACCELERATION = 10; 85 86 /** 87 * A constant describing a rotation vector sensor type. 88 * See {@link android.hardware.SensorEvent SensorEvent} 89 * for more details. 90 */ 91 public static final int TYPE_ROTATION_VECTOR = 11; 92 93 /** 94 * A constant describing all sensor types. 95 */ 96 public static final int TYPE_ALL = -1; 97 98 /* Some of these fields are set only by the native bindings in 99 * SensorManager. 100 */ 101 private String mName; 102 private String mVendor; 103 private int mVersion; 104 private int mHandle; 105 private int mType; 106 private float mMaxRange; 107 private float mResolution; 108 private float mPower; 109 private int mLegacyType; 110 111 112 Sensor() { 113 } 114 115 /** 116 * @return name string of the sensor. 117 */ 118 public String getName() { 119 return mName; 120 } 121 122 /** 123 * @return vendor string of this sensor. 124 */ 125 public String getVendor() { 126 return mVendor; 127 } 128 129 /** 130 * @return generic type of this sensor. 131 */ 132 public int getType() { 133 return mType; 134 } 135 136 /** 137 * @return version of the sensor's module. 138 */ 139 public int getVersion() { 140 return mVersion; 141 } 142 143 /** 144 * @return maximum range of the sensor in the sensor's unit. 145 */ 146 public float getMaximumRange() { 147 return mMaxRange; 148 } 149 150 /** 151 * @return resolution of the sensor in the sensor's unit. 152 */ 153 public float getResolution() { 154 return mResolution; 155 } 156 157 /** 158 * @return the power in mA used by this sensor while in use 159 */ 160 public float getPower() { 161 return mPower; 162 } 163 164 int getHandle() { 165 return mHandle; 166 } 167 168 void setRange(float max, float res) { 169 mMaxRange = max; 170 mResolution = res; 171 } 172 173 void setLegacyType(int legacyType) { 174 mLegacyType = legacyType; 175 } 176 177 int getLegacyType() { 178 return mLegacyType; 179 } 180} 181