Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / sensors / initialisation.c
blob047c9e80b15630c4e9f44ac0c15a9c810349d7a9
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
17 #include <stdbool.h>
18 #include <stdint.h>
19 #include <string.h>
21 #include "platform.h"
23 #include "common/utils.h"
25 #include "config/config_eeprom.h"
27 #include "fc/config.h"
28 #include "fc/runtime_config.h"
30 #include "sensors/acceleration.h"
31 #include "sensors/barometer.h"
32 #include "sensors/compass.h"
33 #include "sensors/gyro.h"
34 #include "sensors/initialisation.h"
35 #include "sensors/irlock.h"
36 #include "sensors/opflow.h"
37 #include "sensors/pitotmeter.h"
38 #include "sensors/rangefinder.h"
39 #include "sensors/sensors.h"
40 #include "sensors/temperature.h"
41 #include "sensors/temperature.h"
42 #include "rx/rx.h"
44 uint8_t requestedSensors[SENSOR_INDEX_COUNT] = { GYRO_AUTODETECT, ACC_NONE, BARO_NONE, MAG_NONE, RANGEFINDER_NONE, PITOT_NONE, OPFLOW_NONE };
45 uint8_t detectedSensors[SENSOR_INDEX_COUNT] = { GYRO_NONE, ACC_NONE, BARO_NONE, MAG_NONE, RANGEFINDER_NONE, PITOT_NONE, OPFLOW_NONE };
47 bool sensorsAutodetect(void)
49 bool eepromUpdatePending = false;
51 if (!gyroInit()) {
52 return false;
55 accInit(getLooptime());
57 #ifdef USE_BARO
58 baroInit();
59 #endif
61 #ifdef USE_PITOT
62 pitotInit();
63 #endif
65 #ifdef USE_MAG
66 compassInit();
67 #endif
69 #ifdef USE_TEMPERATURE_SENSOR
70 temperatureInit();
71 #endif
73 #ifdef USE_RANGEFINDER
74 rangefinderInit();
75 #endif
77 #ifdef USE_OPFLOW
78 opflowInit();
79 #endif
81 if (accelerometerConfig()->acc_hardware == ACC_AUTODETECT) {
82 accelerometerConfigMutable()->acc_hardware = detectedSensors[SENSOR_INDEX_ACC];
83 eepromUpdatePending = true;
86 #ifdef USE_BARO
87 if (barometerConfig()->baro_hardware == BARO_AUTODETECT) {
88 barometerConfigMutable()->baro_hardware = detectedSensors[SENSOR_INDEX_BARO];
89 eepromUpdatePending = true;
91 #endif
93 #ifdef USE_MAG
94 if (compassConfig()->mag_hardware == MAG_AUTODETECT) {
95 compassConfigMutable()->mag_hardware = detectedSensors[SENSOR_INDEX_MAG];
96 eepromUpdatePending = true;
98 #endif
100 #ifdef USE_PITOT
101 if (pitotmeterConfig()->pitot_hardware == PITOT_AUTODETECT) {
102 pitotmeterConfigMutable()->pitot_hardware = detectedSensors[SENSOR_INDEX_PITOT];
103 eepromUpdatePending = true;
105 #endif
107 #ifdef USE_IRLOCK
108 irlockInit();
109 #endif
111 if (eepromUpdatePending) {
112 suspendRxSignal();
113 writeEEPROM();
114 resumeRxSignal();
117 return true;