2013-09-28 05:40:29 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-02-17 21:25:14 -04:00
|
|
|
#pragma once
|
2013-09-28 05:40:29 -03:00
|
|
|
|
2023-06-09 02:58:29 -03:00
|
|
|
#include "AP_Airspeed_config.h"
|
2022-05-04 05:13:29 -03:00
|
|
|
|
|
|
|
#if AP_AIRSPEED_MS4525_ENABLED
|
|
|
|
|
2013-09-28 05:40:29 -03:00
|
|
|
/*
|
|
|
|
backend driver for airspeed from I2C
|
|
|
|
*/
|
|
|
|
|
2015-08-11 03:28:42 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2016-06-08 21:10:54 -03:00
|
|
|
#include <AP_HAL/utility/OwnPtr.h>
|
|
|
|
#include <AP_HAL/I2CDevice.h>
|
|
|
|
#include <utility>
|
2016-01-29 07:38:33 -04:00
|
|
|
|
2015-08-11 03:28:42 -03:00
|
|
|
#include "AP_Airspeed_Backend.h"
|
2013-09-28 05:40:29 -03:00
|
|
|
|
2016-11-30 00:59:20 -04:00
|
|
|
class AP_Airspeed_MS4525 : public AP_Airspeed_Backend
|
2013-09-28 05:40:29 -03:00
|
|
|
{
|
|
|
|
public:
|
2017-11-03 03:17:34 -03:00
|
|
|
AP_Airspeed_MS4525(AP_Airspeed &frontend, uint8_t _instance);
|
2016-11-30 00:59:20 -04:00
|
|
|
~AP_Airspeed_MS4525(void) {}
|
2016-06-08 21:10:54 -03:00
|
|
|
|
2013-09-28 05:40:29 -03:00
|
|
|
// probe and initialise the sensor
|
2016-11-30 00:49:19 -04:00
|
|
|
bool init() override;
|
2013-09-28 05:40:29 -03:00
|
|
|
|
|
|
|
// return the current differential_pressure in Pascal
|
2016-11-30 00:49:19 -04:00
|
|
|
bool get_differential_pressure(float &pressure) override;
|
2013-09-28 05:40:29 -03:00
|
|
|
|
|
|
|
// return the current temperature in degrees C, if available
|
2016-11-30 00:49:19 -04:00
|
|
|
bool get_temperature(float &temperature) override;
|
2013-09-28 05:40:29 -03:00
|
|
|
|
|
|
|
private:
|
2016-01-29 07:38:33 -04:00
|
|
|
void _measure();
|
|
|
|
void _collect();
|
2017-01-13 15:26:14 -04:00
|
|
|
void _timer();
|
2016-10-31 06:48:22 -03:00
|
|
|
void _voltage_correction(float &diff_press_pa, float &temperature);
|
2017-04-01 21:53:45 -03:00
|
|
|
float _get_pressure(int16_t dp_raw) const;
|
|
|
|
float _get_temperature(int16_t dT_raw) const;
|
2016-11-30 02:21:48 -04:00
|
|
|
|
|
|
|
float _temp_sum;
|
|
|
|
float _press_sum;
|
|
|
|
uint32_t _temp_count;
|
|
|
|
uint32_t _press_count;
|
2013-09-28 05:40:29 -03:00
|
|
|
float _temperature;
|
|
|
|
float _pressure;
|
|
|
|
uint32_t _last_sample_time_ms;
|
|
|
|
uint32_t _measurement_started_ms;
|
2016-04-19 14:16:19 -03:00
|
|
|
AP_HAL::OwnPtr<AP_HAL::I2CDevice> _dev;
|
2021-06-29 23:00:08 -03:00
|
|
|
|
|
|
|
bool probe(uint8_t bus, uint8_t address);
|
2013-09-28 05:40:29 -03:00
|
|
|
};
|
2022-05-04 05:13:29 -03:00
|
|
|
|
|
|
|
#endif // AP_AIRSPEED_MS4525_ENABLED
|