SensorInterface.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_SENSOR_INTERFACE_H
  17. #define ANDROID_SENSOR_INTERFACE_H
  18. #include <stdint.h>
  19. #include <sys/types.h>
  20. #include <gui/Sensor.h>
  21. #include "SensorDevice.h"
  22. // ---------------------------------------------------------------------------
  23. namespace android {
  24. // ---------------------------------------------------------------------------
  25. class SensorInterface {
  26. public:
  27. virtual ~SensorInterface();
  28. virtual bool process(sensors_event_t* outEvent,
  29. const sensors_event_t& event) = 0;
  30. virtual status_t activate(void* ident, bool enabled) = 0;
  31. virtual status_t setDelay(void* ident, int handle, int64_t ns) = 0;
  32. // Not all sensors need to support batching.
  33. virtual status_t batch(void* ident, int handle, int /*flags*/, int64_t samplingPeriodNs,
  34. int64_t maxBatchReportLatencyNs) {
  35. if (maxBatchReportLatencyNs == 0) {
  36. return setDelay(ident, handle, samplingPeriodNs);
  37. }
  38. return -EINVAL;
  39. }
  40. virtual status_t flush(void* /*ident*/, int /*handle*/) {
  41. return -EINVAL;
  42. }
  43. virtual Sensor getSensor() const = 0;
  44. virtual bool isVirtual() const = 0;
  45. virtual void autoDisable(void* /*ident*/, int /*handle*/) { }
  46. };
  47. // ---------------------------------------------------------------------------
  48. class HardwareSensor : public SensorInterface
  49. {
  50. SensorDevice& mSensorDevice;
  51. Sensor mSensor;
  52. public:
  53. HardwareSensor(const sensor_t& sensor);
  54. virtual ~HardwareSensor();
  55. virtual bool process(sensors_event_t* outEvent,
  56. const sensors_event_t& event);
  57. virtual status_t activate(void* ident, bool enabled);
  58. virtual status_t batch(void* ident, int handle, int flags, int64_t samplingPeriodNs,
  59. int64_t maxBatchReportLatencyNs);
  60. virtual status_t setDelay(void* ident, int handle, int64_t ns);
  61. virtual status_t flush(void* ident, int handle);
  62. virtual Sensor getSensor() const;
  63. virtual bool isVirtual() const { return false; }
  64. virtual void autoDisable(void *ident, int handle);
  65. };
  66. // ---------------------------------------------------------------------------
  67. }; // namespace android
  68. #endif // ANDROID_SENSOR_INTERFACE_H