Sensor.h revision c57a019e117117c5a76c772970b26cd0f5db8c6a
1/* 2 * Copyright (C) 2010 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#ifndef ANDROID_GUI_SENSOR_H 18#define ANDROID_GUI_SENSOR_H 19 20#include <stdint.h> 21#include <sys/types.h> 22 23#include <utils/Errors.h> 24#include <utils/Flattenable.h> 25#include <utils/String8.h> 26#include <utils/Timers.h> 27 28#include <hardware/sensors.h> 29 30#include <android/sensor.h> 31 32// ---------------------------------------------------------------------------- 33// Concrete types for the NDK 34struct ASensor { }; 35 36// ---------------------------------------------------------------------------- 37namespace android { 38// ---------------------------------------------------------------------------- 39 40class Parcel; 41 42// ---------------------------------------------------------------------------- 43 44class Sensor : public ASensor, public LightFlattenable<Sensor> 45{ 46public: 47 enum { 48 TYPE_ACCELEROMETER = ASENSOR_TYPE_ACCELEROMETER, 49 TYPE_MAGNETIC_FIELD = ASENSOR_TYPE_MAGNETIC_FIELD, 50 TYPE_GYROSCOPE = ASENSOR_TYPE_GYROSCOPE, 51 TYPE_LIGHT = ASENSOR_TYPE_LIGHT, 52 TYPE_PROXIMITY = ASENSOR_TYPE_PROXIMITY 53 }; 54 55 Sensor(); 56 Sensor(struct sensor_t const* hwSensor, int halVersion = 0); 57 ~Sensor(); 58 59 const String8& getName() const; 60 const String8& getVendor() const; 61 int32_t getHandle() const; 62 int32_t getType() const; 63 float getMinValue() const; 64 float getMaxValue() const; 65 float getResolution() const; 66 float getPowerUsage() const; 67 int32_t getMinDelay() const; 68 nsecs_t getMinDelayNs() const; 69 int32_t getVersion() const; 70 int32_t getFifoReservedEventCount() const; 71 int32_t getFifoMaxEventCount() const; 72 const String8& getStringType() const; 73 const String8& getRequiredPermission() const; 74 75 // LightFlattenable protocol 76 inline bool isFixedSize() const { return false; } 77 size_t getFlattenedSize() const; 78 status_t flatten(void* buffer, size_t size) const; 79 status_t unflatten(void const* buffer, size_t size); 80 81private: 82 String8 mName; 83 String8 mVendor; 84 int32_t mHandle; 85 int32_t mType; 86 float mMinValue; 87 float mMaxValue; 88 float mResolution; 89 float mPower; 90 int32_t mMinDelay; 91 int32_t mVersion; 92 int32_t mFifoReservedEventCount; 93 int32_t mFifoMaxEventCount; 94 String8 mStringType; 95 String8 mRequiredPermission; 96 static void flattenString8(void*& buffer, size_t& size, const String8& string8); 97 static bool unflattenString8(void const*& buffer, size_t& size, String8& outputString8); 98}; 99 100// ---------------------------------------------------------------------------- 101}; // namespace android 102 103#endif // ANDROID_GUI_SENSOR_H 104