AP_Airspeed_SDP3X.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include "AP_Airspeed.h"
  24. /*
  25. * Thanks to PX4 for registers definitions
  26. */
  27. class AP_Airspeed_SDP3X : public AP_Airspeed_Backend
  28. {
  29. public:
  30. AP_Airspeed_SDP3X(AP_Airspeed &frontend, uint8_t _instance);
  31. ~AP_Airspeed_SDP3X(void) {}
  32. // probe and initialise the sensor
  33. bool init() override;
  34. // return the current differential_pressure in Pascal
  35. bool get_differential_pressure(float &pressure) override;
  36. // return the current temperature in degrees C, if available
  37. bool get_temperature(float &temperature) override;
  38. private:
  39. void _timer();
  40. bool _send_command(uint16_t cmd);
  41. bool _crc(const uint8_t data[], unsigned size, uint8_t checksum);
  42. float _correct_pressure(float press);
  43. float _temp;
  44. float _press;
  45. uint16_t _temp_count;
  46. uint16_t _press_count;
  47. float _temp_sum;
  48. float _press_sum;
  49. uint32_t _last_sample_time_ms;
  50. uint16_t _scale;
  51. AP_HAL::OwnPtr<AP_HAL::I2CDevice> _dev;
  52. };