Merge pull request #11939 from blckmn/flash-fix
[betaflight.git] / src / main / drivers / barometer / barometer_fake.c
blob74147441ab1175db89ef4252c3ff652520c50594
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_FAKE_BARO
28 #include "common/utils.h"
30 #include "barometer.h"
31 #include "barometer_fake.h"
34 static int32_t fakePressure;
35 static int32_t fakeTemperature;
38 static void fakeBaroStart(baroDev_t *baro)
40 UNUSED(baro);
43 static bool fakeBaroReadGet(baroDev_t *baro)
45 UNUSED(baro);
47 return true;
50 static void fakeBaroCalculate(int32_t *pressure, int32_t *temperature)
52 if (pressure)
53 *pressure = fakePressure;
54 if (temperature)
55 *temperature = fakeTemperature;
58 void fakeBaroSet(int32_t pressure, int32_t temperature)
60 fakePressure = pressure;
61 fakeTemperature = temperature;
64 bool fakeBaroDetect(baroDev_t *baro)
66 fakePressure = 101325; // pressure in Pa (0m MSL)
67 fakeTemperature = 2500; // temperature in 0.01 C = 25 deg
69 // these are dummy as temperature is measured as part of pressure
70 baro->combined_read = true;
71 baro->ut_delay = 10000;
72 baro->get_ut = fakeBaroReadGet;
73 baro->read_ut = fakeBaroReadGet;
74 baro->start_ut = fakeBaroStart;
76 // only _up part is executed, and gets both temperature and pressure
77 baro->up_delay = 10000;
78 baro->start_up = fakeBaroStart;
79 baro->read_up = fakeBaroReadGet;
80 baro->get_up = fakeBaroReadGet;
81 baro->calculate = fakeBaroCalculate;
83 return true;
85 #endif // USE_FAKE_BARO