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