AP_Compass_LIS3MDL.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_LIS3MDL_I2C_ADDR
  23. # define HAL_COMPASS_LIS3MDL_I2C_ADDR 0x1c
  24. #endif
  25. #ifndef HAL_COMPASS_LIS3MDL_I2C_ADDR2
  26. # define HAL_COMPASS_LIS3MDL_I2C_ADDR2 0x1e
  27. #endif
  28. class AP_Compass_LIS3MDL : public AP_Compass_Backend
  29. {
  30. public:
  31. static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::Device> dev,
  32. bool force_external,
  33. enum Rotation rotation);
  34. void read() override;
  35. static constexpr const char *name = "LIS3MDL";
  36. private:
  37. AP_Compass_LIS3MDL(AP_HAL::OwnPtr<AP_HAL::Device> dev,
  38. bool force_external,
  39. enum Rotation rotation);
  40. AP_HAL::OwnPtr<AP_HAL::Device> dev;
  41. /**
  42. * Device periodic callback to read data from the sensor.
  43. */
  44. bool init();
  45. void timer();
  46. uint8_t compass_instance;
  47. bool force_external;
  48. enum Rotation rotation;
  49. };