AP_Airspeed_MS4525.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #pragma once
  14. /*
  15. backend driver for airspeed from I2C
  16. */
  17. #include <AP_HAL/AP_HAL.h>
  18. #include <AP_Param/AP_Param.h>
  19. #include <AP_HAL/utility/OwnPtr.h>
  20. #include <AP_HAL/I2CDevice.h>
  21. #include <utility>
  22. #include "AP_Airspeed_Backend.h"
  23. class AP_Airspeed_MS4525 : public AP_Airspeed_Backend
  24. {
  25. public:
  26. AP_Airspeed_MS4525(AP_Airspeed &frontend, uint8_t _instance);
  27. ~AP_Airspeed_MS4525(void) {}
  28. // probe and initialise the sensor
  29. bool init() override;
  30. // return the current differential_pressure in Pascal
  31. bool get_differential_pressure(float &pressure) override;
  32. // return the current temperature in degrees C, if available
  33. bool get_temperature(float &temperature) override;
  34. private:
  35. void _measure();
  36. void _collect();
  37. void _timer();
  38. void _voltage_correction(float &diff_press_pa, float &temperature);
  39. float _get_pressure(int16_t dp_raw) const;
  40. float _get_temperature(int16_t dT_raw) const;
  41. float _temp_sum;
  42. float _press_sum;
  43. uint32_t _temp_count;
  44. uint32_t _press_count;
  45. float _temperature;
  46. float _pressure;
  47. uint32_t _last_sample_time_ms;
  48. uint32_t _measurement_started_ms;
  49. AP_HAL::OwnPtr<AP_HAL::I2CDevice> _dev;
  50. };