Sensor.java revision 210fc914db37b3cf77ebb3bf75b0b509a1ecb07c
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 */ 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 /** 50 * A constant describing an light sensor type. 51 * See {@link android.hardware.SensorEvent SensorEvent} 52 * for more details. 53 */ 54 public static final int TYPE_LIGHT = 5; 55 56 /** A constant describing a pressure sensor type */ 57 public static final int TYPE_PRESSURE = 6; 58 59 /** A constant describing a temperature sensor type */ 60 public static final int TYPE_TEMPERATURE = 7; 61 62 /** 63 * A constant describing an proximity sensor type. 64 * See {@link android.hardware.SensorEvent SensorEvent} 65 * for more details. 66 */ 67 public static final int TYPE_PROXIMITY = 8; 68 69 70 /** 71 * A constant describing all sensor types. 72 */ 73 public static final int TYPE_ALL = -1; 74 75 /* Some of these fields are set only by the native bindings in 76 * SensorManager. 77 */ 78 private String mName; 79 private String mVendor; 80 private int mVersion; 81 private int mHandle; 82 private int mType; 83 private float mMaxRange; 84 private float mResolution; 85 private float mPower; 86 private int mLegacyType; 87 88 89 Sensor() { 90 } 91 92 /** 93 * @return name string of the sensor. 94 */ 95 public String getName() { 96 return mName; 97 } 98 99 /** 100 * @return vendor string of this sensor. 101 */ 102 public String getVendor() { 103 return mVendor; 104 } 105 106 /** 107 * @return generic type of this sensor. 108 */ 109 public int getType() { 110 return mType; 111 } 112 113 /** 114 * @return version of the sensor's module. 115 */ 116 public int getVersion() { 117 return mVersion; 118 } 119 120 /** 121 * @return maximum range of the sensor in the sensor's unit. 122 */ 123 public float getMaximumRange() { 124 return mMaxRange; 125 } 126 127 /** 128 * @return resolution of the sensor in the sensor's unit. 129 */ 130 public float getResolution() { 131 return mResolution; 132 } 133 134 /** 135 * @return the power in mA used by this sensor while in use 136 */ 137 public float getPower() { 138 return mPower; 139 } 140 141 int getHandle() { 142 return mHandle; 143 } 144 145 void setRange(float max, float res) { 146 mMaxRange = max; 147 mResolution = res; 148 } 149 150 void setLegacyType(int legacyType) { 151 mLegacyType = legacyType; 152 } 153 154 int getLegacyType() { 155 return mLegacyType; 156 } 157} 158