Sensor.h revision d9441e4c27bb7d0b1dfe2a8b5c1ee1714442648d
1589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian/*
2589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * Copyright (C) 2010 The Android Open Source Project
3589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian *
4589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * you may not use this file except in compliance with the License.
6589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * You may obtain a copy of the License at
7589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian *
8589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian *
10589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * Unless required by applicable law or agreed to in writing, software
11589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * See the License for the specific language governing permissions and
14589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian * limitations under the License.
15589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian */
16589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
17589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#ifndef ANDROID_GUI_SENSOR_H
18589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#define ANDROID_GUI_SENSOR_H
19589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
20589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <stdint.h>
21589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <sys/types.h>
22589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
23589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <utils/Errors.h>
24589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <utils/Flattenable.h>
25b62013f6aafee08cfad25a2712dc32264e44f783Mathias Agopian#include <utils/String8.h>
26b62013f6aafee08cfad25a2712dc32264e44f783Mathias Agopian#include <utils/Timers.h>
27589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
28589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <hardware/sensors.h>
29589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
30589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#include <android/sensor.h>
31589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
32589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
33589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// Concrete types for the NDK
34589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianstruct ASensor { };
35589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
36589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
37589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopiannamespace android {
38589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
39589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
40589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianclass Parcel;
41589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
42589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
43589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
448683fca395d01734ec7946e9f0595ec5d7b754c6Mathias Agopianclass Sensor : public ASensor, public LightFlattenable<Sensor>
45589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian{
46589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianpublic:
47589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    enum {
48589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        TYPE_ACCELEROMETER  = ASENSOR_TYPE_ACCELEROMETER,
49589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        TYPE_MAGNETIC_FIELD = ASENSOR_TYPE_MAGNETIC_FIELD,
50589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        TYPE_GYROSCOPE      = ASENSOR_TYPE_GYROSCOPE,
51589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        TYPE_LIGHT          = ASENSOR_TYPE_LIGHT,
52589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian        TYPE_PROXIMITY      = ASENSOR_TYPE_PROXIMITY
53589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    };
54589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
55a7352c9f4a6e642c29782b19db5bc0bd98feddc8Mathias Agopian            Sensor();
56724d91d778e71c8186399f4955de14b54812b3edAravind Akella            Sensor(struct sensor_t const* hwSensor, int halVersion = 0);
578683fca395d01734ec7946e9f0595ec5d7b754c6Mathias Agopian            ~Sensor();
58589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
59589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    const String8& getName() const;
60589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    const String8& getVendor() const;
61589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    int32_t getHandle() const;
62589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    int32_t getType() const;
63589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float getMinValue() const;
64589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float getMaxValue() const;
65589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float getResolution() const;
66589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float getPowerUsage() const;
67a48bcf62b6a26f24a0bdd2b44bb39fadce499e92Mathias Agopian    int32_t getMinDelay() const;
68b62013f6aafee08cfad25a2712dc32264e44f783Mathias Agopian    nsecs_t getMinDelayNs() const;
69b62013f6aafee08cfad25a2712dc32264e44f783Mathias Agopian    int32_t getVersion() const;
70724d91d778e71c8186399f4955de14b54812b3edAravind Akella    int32_t getFifoReservedEventCount() const;
71724d91d778e71c8186399f4955de14b54812b3edAravind Akella    int32_t getFifoMaxEventCount() const;
72700180487ffec09d9df1657b018a7caadac24b75Aravind Akella    const String8& getStringType() const;
73700180487ffec09d9df1657b018a7caadac24b75Aravind Akella    const String8& getRequiredPermission() const;
74d9441e4c27bb7d0b1dfe2a8b5c1ee1714442648dAravind Akella    int32_t getMaxDelay() const;
759a844cf78f09953145200b4074d47589257a408cAravind Akella    bool isWakeUpSensor() const;
76589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
778683fca395d01734ec7946e9f0595ec5d7b754c6Mathias Agopian    // LightFlattenable protocol
788683fca395d01734ec7946e9f0595ec5d7b754c6Mathias Agopian    inline bool isFixedSize() const { return false; }
79e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian    size_t getFlattenedSize() const;
80e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian    status_t flatten(void* buffer, size_t size) const;
818683fca395d01734ec7946e9f0595ec5d7b754c6Mathias Agopian    status_t unflatten(void const* buffer, size_t size);
82589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
83589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopianprivate:
84589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    String8 mName;
85589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    String8 mVendor;
86589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    int32_t mHandle;
87589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    int32_t mType;
88589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float   mMinValue;
89589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float   mMaxValue;
90589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float   mResolution;
91589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian    float   mPower;
92a48bcf62b6a26f24a0bdd2b44bb39fadce499e92Mathias Agopian    int32_t mMinDelay;
93b62013f6aafee08cfad25a2712dc32264e44f783Mathias Agopian    int32_t mVersion;
94724d91d778e71c8186399f4955de14b54812b3edAravind Akella    int32_t mFifoReservedEventCount;
95724d91d778e71c8186399f4955de14b54812b3edAravind Akella    int32_t mFifoMaxEventCount;
96700180487ffec09d9df1657b018a7caadac24b75Aravind Akella    String8 mStringType;
97700180487ffec09d9df1657b018a7caadac24b75Aravind Akella    String8 mRequiredPermission;
98d9441e4c27bb7d0b1dfe2a8b5c1ee1714442648dAravind Akella    int32_t mMaxDelay;
999a844cf78f09953145200b4074d47589257a408cAravind Akella    bool    mWakeUpSensor;
100700180487ffec09d9df1657b018a7caadac24b75Aravind Akella    static void flattenString8(void*& buffer, size_t& size, const String8& string8);
101700180487ffec09d9df1657b018a7caadac24b75Aravind Akella    static bool unflattenString8(void const*& buffer, size_t& size, String8& outputString8);
102589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian};
103589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
104589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian// ----------------------------------------------------------------------------
105589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian}; // namespace android
106589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian
107589ce85ee4174829cfedce91b6b2509d2a4002ebMathias Agopian#endif // ANDROID_GUI_SENSOR_H
108