AP_Baro_MPM258.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. #include "AP_Baro_Backend.h"
  3. #include <AP_HAL/AP_HAL.h>
  4. #include <AP_HAL/Semaphores.h>
  5. #include <AP_HAL/Device.h>
  6. #ifndef HAL_BARO_MPM258_I2C_ADDR
  7. #define HAL_BARO_MPM258_I2C_ADDR 0x6D
  8. #endif
  9. class AP_Baro_MPM258 : public AP_Baro_Backend
  10. {
  11. public:
  12. void update() override;
  13. static AP_Baro_Backend *probe(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev);
  14. private:
  15. /*
  16. * Update @accum and @count with the new sample in @val, taking into
  17. * account a maximum number of samples given by @max_count; in case
  18. * maximum number is reached, @accum and @count are updated appropriately
  19. */
  20. void _update_and_wrap_accumulator(int32_t pressure, int32_t temperature, uint8_t max_count);
  21. AP_Baro_MPM258(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev);
  22. bool _init();
  23. bool _read();
  24. void _timer();
  25. AP_HAL::OwnPtr<AP_HAL::Device> _dev;
  26. /* Shared values between thread sampling the HW and main thread */
  27. struct {
  28. int32_t sum_pressure;
  29. int32_t sum_temperature;
  30. uint8_t num_samples;
  31. } _accum;
  32. uint8_t _state;
  33. uint8_t _instance;
  34. };