Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / drivers / pitotmeter / pitotmeter_msp.c
blobf0a8e82768acdef63735ed14211b263632196827
1 /*
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/.
25 #include <stdbool.h>
26 #include <stdint.h>
28 #include "platform.h"
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)
52 UNUSED(pitot);
53 return true;
56 static bool mspPitotRead(pitotDev_t *pitot)
58 UNUSED(pitot);
59 return true;
62 static void mspPitotCalculate(pitotDev_t *pitot, float *pressure, float *temperature)
64 UNUSED(pitot);
66 if (pressure) {
67 *pressure = mspPitotPressure;
70 if (temperature) {
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)
86 mspPitotPressure = 0;
87 mspPitotTemperature = 27315; // 0 deg/c
89 pitot->delay = 10000;
90 pitot->calibThreshold = 0.00001f;
91 pitot->start = mspPitotStart;
92 pitot->get = mspPitotRead;
93 pitot->calculate = mspPitotCalculate;
95 return true;
98 #endif