Sensor.h 3.5 KB

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