Baro and Mag driver check for I2C bus being busy (#13509)
[betaflight.git] / src / main / drivers / barometer / barometer_virtual.c
blobb4b142e822ea72eabcade84ebfa0d1cc1d0cfaf3
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdbool.h>
22 #include <stdint.h>
24 #include "platform.h"
26 #ifdef USE_VIRTUAL_BARO
28 #include "common/utils.h"
30 #include "barometer.h"
31 #include "barometer_virtual.h"
34 static int32_t virtualPressure;
35 static int32_t virtualTemperature;
38 static bool virtualBaroStart(baroDev_t *baro)
40 UNUSED(baro);
42 return true;
45 static bool virtualBaroReadGet(baroDev_t *baro)
47 UNUSED(baro);
49 return true;
52 static void virtualBaroCalculate(int32_t *pressure, int32_t *temperature)
54 if (pressure)
55 *pressure = virtualPressure;
56 if (temperature)
57 *temperature = virtualTemperature;
60 void virtualBaroSet(int32_t pressure, int32_t temperature)
62 virtualPressure = pressure;
63 virtualTemperature = temperature;
66 bool virtualBaroDetect(baroDev_t *baro)
68 virtualPressure = 101325; // pressure in Pa (0m MSL)
69 virtualTemperature = 2500; // temperature in 0.01 C = 25 deg
71 // these are dummy as temperature is measured as part of pressure
72 baro->combined_read = true;
73 baro->ut_delay = 10000;
74 baro->get_ut = virtualBaroReadGet;
75 baro->read_ut = virtualBaroReadGet;
76 baro->start_ut = virtualBaroStart;
78 // only _up part is executed, and gets both temperature and pressure
79 baro->up_delay = 10000;
80 baro->start_up = virtualBaroStart;
81 baro->read_up = virtualBaroReadGet;
82 baro->get_up = virtualBaroReadGet;
83 baro->calculate = virtualBaroCalculate;
85 return true;
87 #endif // USE_VIRTUAL_BARO