SensorFusion.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2011 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_FUSION_H
  17. #define ANDROID_SENSOR_FUSION_H
  18. #include <stdint.h>
  19. #include <sys/types.h>
  20. #include <utils/SortedVector.h>
  21. #include <utils/Singleton.h>
  22. #include <utils/String8.h>
  23. #include <gui/Sensor.h>
  24. #include "Fusion.h"
  25. // ---------------------------------------------------------------------------
  26. namespace android {
  27. // ---------------------------------------------------------------------------
  28. class SensorDevice;
  29. class SensorFusion : public Singleton<SensorFusion> {
  30. friend class Singleton<SensorFusion>;
  31. SensorDevice& mSensorDevice;
  32. Sensor mAcc;
  33. Sensor mMag;
  34. Sensor mGyro;
  35. Fusion mFusion;
  36. bool mEnabled;
  37. float mEstimatedGyroRate;
  38. nsecs_t mTargetDelayNs;
  39. nsecs_t mGyroTime;
  40. vec4_t mAttitude;
  41. SortedVector<void*> mClients;
  42. SensorFusion();
  43. public:
  44. void process(const sensors_event_t& event);
  45. bool isEnabled() const { return mEnabled; }
  46. bool hasEstimate() const { return mFusion.hasEstimate(); }
  47. mat33_t getRotationMatrix() const { return mFusion.getRotationMatrix(); }
  48. vec4_t getAttitude() const { return mAttitude; }
  49. vec3_t getGyroBias() const { return mFusion.getBias(); }
  50. float getEstimatedRate() const { return mEstimatedGyroRate; }
  51. status_t activate(void* ident, bool enabled);
  52. status_t setDelay(void* ident, int64_t ns);
  53. float getPowerUsage() const;
  54. int32_t getMinDelay() const;
  55. void dump(String8& result);
  56. };
  57. // ---------------------------------------------------------------------------
  58. }; // namespace android
  59. #endif // ANDROID_SENSOR_FUSION_H