2 * This file is part of INAV Project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
6 * You can obtain one at http://mozilla.org/MPL/2.0/.
8 * Alternatively, the contents of this file may be used under the terms
9 * of the GNU General Public License Version 3, as described below:
11 * This file is free software: you may copy, redistribute and/or modify
12 * it under the terms of the GNU General Public License as published by the
13 * Free Software Foundation, either version 3 of the License, or (at your
14 * option) any later version.
16 * This file is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
19 * Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see http://www.gnu.org/licenses/.
30 #if defined(USE_PITOT_MSP)
32 #include "build/build_config.h"
33 #include "build/debug.h"
35 #include "common/utils.h"
36 #include "common/time.h"
38 #include "drivers/time.h"
39 #include "drivers/pitotmeter/pitotmeter.h"
40 #include "drivers/pitotmeter/pitotmeter_msp.h"
42 #include "msp/msp_protocol_v2_sensor_msg.h"
44 #define MSP_PITOT_TIMEOUT_MS 500 // Less than 2Hz updates is considered a failure
46 static int32_t mspPitotPressure
;
47 static int32_t mspPitotTemperature
;
48 static timeMs_t mspPitotLastUpdateMs
;
50 static bool mspPitotStart(pitotDev_t
*pitot
)
56 static bool mspPitotRead(pitotDev_t
*pitot
)
62 static void mspPitotCalculate(pitotDev_t
*pitot
, float *pressure
, float *temperature
)
67 *pressure
= mspPitotPressure
;
71 *temperature
= (mspPitotTemperature
- 27315) / 100.0f
; // Pitot expects temp in Kelvin
75 void mspPitotmeterReceiveNewData(uint8_t * bufferPtr
)
77 const mspSensorAirspeedDataMessage_t
* pkt
= (const mspSensorAirspeedDataMessage_t
*)bufferPtr
;
79 mspPitotPressure
= pkt
->diffPressurePa
;
80 mspPitotTemperature
= pkt
->temp
;
81 mspPitotLastUpdateMs
= millis();
84 bool mspPitotmeterDetect(pitotDev_t
*pitot
)
87 mspPitotTemperature
= 27315; // 0 deg/c
90 pitot
->calibThreshold
= 0.00001f
;
91 pitot
->start
= mspPitotStart
;
92 pitot
->get
= mspPitotRead
;
93 pitot
->calculate
= mspPitotCalculate
;