AP_Compass_RM3100.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * This file is free software: you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation, either version 3 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This file is distributed in the hope that it will be useful, but
  8. * WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. * See the GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License along
  13. * with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #pragma once
  16. #include <AP_Common/AP_Common.h>
  17. #include <AP_HAL/AP_HAL.h>
  18. #include <AP_HAL/Device.h>
  19. #include <AP_Math/AP_Math.h>
  20. #include "AP_Compass.h"
  21. #include "AP_Compass_Backend.h"
  22. #ifndef HAL_COMPASS_RM3100_I2C_ADDR
  23. # define HAL_COMPASS_RM3100_I2C_ADDR 0x20
  24. #endif
  25. class AP_Compass_RM3100 : public AP_Compass_Backend
  26. {
  27. public:
  28. static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::Device> dev,
  29. bool force_external,
  30. enum Rotation rotation);
  31. void read() override;
  32. static constexpr const char *name = "RM3100";
  33. private:
  34. AP_Compass_RM3100(AP_HAL::OwnPtr<AP_HAL::Device> dev,
  35. bool force_external,
  36. enum Rotation rotation);
  37. AP_HAL::OwnPtr<AP_HAL::Device> dev;
  38. /**
  39. * Device periodic callback to read data from the sensor.
  40. */
  41. bool init();
  42. void timer();
  43. uint8_t compass_instance;
  44. bool force_external;
  45. enum Rotation rotation;
  46. float _scaler = 1.0;
  47. };