bool sensorsAutodetect(void) { // gyro must be initialised before accelerometer bool gyroDetected = gyroInit(); #ifdef USE_ACC if (gyroDetected) { accInit(gyro.targetLooptime); } #endif #ifdef USE_MAG compassInit(); #endif #ifdef USE_BARO baroDetect(&baro.dev, barometerConfig()->baro_hardware); #endif #ifdef USE_RANGEFINDER rangefinderInit(); #endif #ifdef USE_ADC_INTERNAL adcInternalInit(); #endif return gyroDetected; }
bool sensorsAutodetect(sensorAlignmentConfig_t *sensorAlignmentConfig, uint8_t gyroLpf, uint8_t accHardwareToUse, uint8_t magHardwareToUse, uint8_t baroHardwareToUse, int16_t magDeclinationFromConfig) { memset(&acc, 0, sizeof(acc)); memset(&gyro, 0, sizeof(gyro)); #if defined(USE_GYRO_MPU6050) || defined(USE_GYRO_MPU3050) || defined(USE_GYRO_MPU6500) || defined(USE_GYRO_SPI_MPU6500) || defined(USE_GYRO_SPI_MPU6000) || defined(USE_ACC_MPU6050) const extiConfig_t *mpuExtiConfig = selectMPUIntExtiConfig(); detectMpu(mpuExtiConfig); #endif if (!detectGyro()) { return false; } detectAcc(accHardwareToUse); detectBaro(baroHardwareToUse); // Now time to init things, acc first if (sensors(SENSOR_ACC)) { acc.init(&acc); } gyro.init(gyroLpf); detectMag(magHardwareToUse); reconfigureAlignment(sensorAlignmentConfig); // FIXME extract to a method to reduce dependencies, maybe move to sensors_compass.c if (sensors(SENSOR_MAG)) { // calculate magnetic declination const int deg = magDeclinationFromConfig / 100; const int min = magDeclinationFromConfig % 100; magneticDeclination = (deg + ((float)min * (1.0f / 60.0f))) * 10; // heading is in 0.1deg units } else { magneticDeclination = 0.0f; // TODO investigate if this is actually needed if there is no mag sensor or if the value stored in the config should be used. } #ifdef SONAR const rangefinderType_e rangefinderType = detectRangefinder(); rangefinderInit(rangefinderType); #endif return true; }