mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-24 00:35:34 +03:00
Add back sensor autodetection; Autodetection is used to update and save config
This commit is contained in:
parent
00a58e0450
commit
8909cd8374
11 changed files with 183 additions and 52 deletions
|
@ -505,9 +505,24 @@ static void resetConf(void)
|
|||
gyroConfig()->gyroMovementCalibrationThreshold = 32;
|
||||
|
||||
accelerometerConfig()->acc_hardware = ACC_AUTODETECT; // default/autodetect
|
||||
|
||||
#ifdef MAG
|
||||
compassConfig()->mag_hardware = MAG_AUTODETECT;
|
||||
#else
|
||||
compassConfig()->mag_hardware = MAG_NONE;
|
||||
#endif
|
||||
|
||||
#ifdef BARO
|
||||
barometerConfig()->baro_hardware = BARO_AUTODETECT;
|
||||
#else
|
||||
barometerConfig()->baro_hardware = BARO_NONE;
|
||||
#endif
|
||||
|
||||
#ifdef PITOT
|
||||
pitotmeterConfig()->pitot_hardware = PITOT_AUTODETECT;
|
||||
#else
|
||||
pitotmeterConfig()->pitot_hardware = PITOT_NONE;
|
||||
#endif
|
||||
|
||||
resetBatteryConfig(&masterConfig.batteryConfig);
|
||||
|
||||
|
|
|
@ -234,13 +234,13 @@ static const char * const gyroNames[] = { "NONE", "AUTO", "MPU6050", "L3G4200D",
|
|||
// sync with accelerationSensor_e
|
||||
static const char * const accNames[] = { "NONE", "AUTO", "ADXL345", "MPU6050", "MMA845x", "BMA280", "LSM303DLHC", "MPU6000", "MPU6500", "MPU9250", "FAKE"};
|
||||
// sync with baroSensor_e
|
||||
static const char * const baroNames[] = { "NONE", "BMP085", "MS5611", "BMP280", "FAKE"};
|
||||
static const char * const baroNames[] = { "NONE", "AUTO", "BMP085", "MS5611", "BMP280", "FAKE"};
|
||||
// sync with magSensor_e
|
||||
static const char * const magNames[] = { "NONE", "HMC5883", "AK8975", "GPSMAG", "MAG3110", "AK8963", "IST8310", "FAKE"};
|
||||
static const char * const magNames[] = { "NONE", "AUTO", "HMC5883", "AK8975", "GPSMAG", "MAG3110", "AK8963", "IST8310", "FAKE"};
|
||||
// sycn with rangefinderType_e
|
||||
static const char * const rangefinderNames[] = { "NONE", "HCSR04", "SRF10"};
|
||||
// sync with pitotSensor_e
|
||||
static const char * const pitotmeterNames[] = { "NONE", "MS4525", "FAKE"};
|
||||
static const char * const pitotmeterNames[] = { "NONE", "AUTO", "MS4525", "FAKE"};
|
||||
|
||||
#if (FLASH_SIZE > 64)
|
||||
// sync this with sensors_e
|
||||
|
|
|
@ -102,7 +102,11 @@ retry:
|
|||
break;
|
||||
}
|
||||
#endif
|
||||
; // fallthrough
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (accHardwareToUse != ACC_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case ACC_LSM303DLHC:
|
||||
#ifdef USE_ACC_LSM303DLHC
|
||||
if (lsm303dlhcAccDetect(dev)) {
|
||||
|
@ -113,7 +117,11 @@ retry:
|
|||
break;
|
||||
}
|
||||
#endif
|
||||
; // fallthrough
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (accHardwareToUse != ACC_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case ACC_MPU6050: // MPU6050
|
||||
#ifdef USE_ACC_MPU6050
|
||||
if (mpu6050AccDetect(dev)) {
|
||||
|
@ -124,7 +132,11 @@ retry:
|
|||
break;
|
||||
}
|
||||
#endif
|
||||
; // fallthrough
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (accHardwareToUse != ACC_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case ACC_MMA8452: // MMA8452
|
||||
#ifdef USE_ACC_MMA8452
|
||||
#ifdef NAZE
|
||||
|
@ -140,7 +152,11 @@ retry:
|
|||
break;
|
||||
}
|
||||
#endif
|
||||
; // fallthrough
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (accHardwareToUse != ACC_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case ACC_BMA280: // BMA280
|
||||
#ifdef USE_ACC_BMA280
|
||||
if (bma280Detect(dev)) {
|
||||
|
@ -151,7 +167,11 @@ retry:
|
|||
break;
|
||||
}
|
||||
#endif
|
||||
; // fallthrough
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (accHardwareToUse != ACC_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case ACC_MPU6000:
|
||||
#ifdef USE_ACC_SPI_MPU6000
|
||||
if (mpu6000SpiAccDetect(dev)) {
|
||||
|
@ -162,7 +182,11 @@ retry:
|
|||
break;
|
||||
}
|
||||
#endif
|
||||
; // fallthrough
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (accHardwareToUse != ACC_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case ACC_MPU6500:
|
||||
#if defined(USE_ACC_MPU6500) || defined(USE_ACC_SPI_MPU6500)
|
||||
#ifdef USE_ACC_SPI_MPU6500
|
||||
|
@ -177,6 +201,11 @@ retry:
|
|||
break;
|
||||
}
|
||||
#endif
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (accHardwareToUse != ACC_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case ACC_MPU9250:
|
||||
#ifdef USE_ACC_SPI_MPU9250
|
||||
if (mpu9250SpiAccDetect(dev)) {
|
||||
|
@ -187,7 +216,11 @@ retry:
|
|||
break;
|
||||
}
|
||||
#endif
|
||||
; // fallthrough
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (accHardwareToUse != ACC_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case ACC_FAKE:
|
||||
#ifdef USE_FAKE_ACC
|
||||
if (fakeAccDetect(dev)) {
|
||||
|
@ -195,17 +228,14 @@ retry:
|
|||
break;
|
||||
}
|
||||
#endif
|
||||
; // fallthrough
|
||||
case ACC_NONE: // disable ACC
|
||||
accHardware = ACC_NONE;
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (accHardwareToUse != ACC_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Found anything? Check if error or ACC is really missing.
|
||||
if (accHardware == ACC_NONE && accHardwareToUse != ACC_AUTODETECT && accHardwareToUse != ACC_NONE) {
|
||||
// Nothing was found and we have a forced sensor that isn't present.
|
||||
accHardwareToUse = ACC_AUTODETECT;
|
||||
goto retry;
|
||||
case ACC_NONE: // disable ACC
|
||||
accHardware = ACC_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
addBootlogEvent6(BOOT_EVENT_ACC_DETECTION, BOOT_EVENT_FLAGS_NONE, accHardware, 0, 0, 0);
|
||||
|
|
|
@ -79,37 +79,54 @@ bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse)
|
|||
#endif
|
||||
|
||||
switch (baroHardwareToUse) {
|
||||
case BARO_AUTODETECT:
|
||||
case BARO_BMP085:
|
||||
#ifdef USE_BARO_BMP085
|
||||
if (bmp085Detect(bmp085Config, dev)) {
|
||||
baroHardware = BARO_BMP085;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (baroHardwareToUse != BARO_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case BARO_MS5611:
|
||||
#ifdef USE_BARO_MS5611
|
||||
if (ms5611Detect(dev)) {
|
||||
baroHardware = BARO_MS5611;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (baroHardwareToUse != BARO_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case BARO_BMP280:
|
||||
#if defined(USE_BARO_BMP280) || defined(USE_BARO_SPI_BMP280)
|
||||
if (bmp280Detect(dev)) {
|
||||
baroHardware = BARO_BMP280;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (baroHardwareToUse != BARO_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case BARO_FAKE:
|
||||
#ifdef USE_FAKE_BARO
|
||||
if (fakeBaroDetect(dev)) {
|
||||
baroHardware = BARO_FAKE;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (baroHardwareToUse != BARO_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case BARO_NONE:
|
||||
baroHardware = BARO_NONE;
|
||||
|
|
|
@ -21,10 +21,11 @@
|
|||
|
||||
typedef enum {
|
||||
BARO_NONE = 0,
|
||||
BARO_BMP085 = 1,
|
||||
BARO_MS5611 = 2,
|
||||
BARO_BMP280 = 3,
|
||||
BARO_FAKE = 4,
|
||||
BARO_AUTODETECT = 1,
|
||||
BARO_BMP085 = 2,
|
||||
BARO_MS5611 = 3,
|
||||
BARO_BMP280 = 4,
|
||||
BARO_FAKE = 5,
|
||||
BARO_MAX = BARO_FAKE
|
||||
} baroSensor_e;
|
||||
|
||||
|
|
|
@ -94,6 +94,7 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
|
|||
dev->magAlign = ALIGN_DEFAULT;
|
||||
|
||||
switch(magHardwareToUse) {
|
||||
case MAG_AUTODETECT:
|
||||
case MAG_HMC5883:
|
||||
#ifdef USE_MAG_HMC5883
|
||||
if (hmc5883lDetect(dev, hmc5883Config)) {
|
||||
|
@ -101,9 +102,13 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
|
|||
dev->magAlign = MAG_HMC5883_ALIGN;
|
||||
#endif
|
||||
magHardware = MAG_HMC5883;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (magHardwareToUse != MAG_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case MAG_AK8975:
|
||||
#ifdef USE_MAG_AK8975
|
||||
|
@ -112,9 +117,13 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
|
|||
dev->magAlign = MAG_AK8975_ALIGN;
|
||||
#endif
|
||||
magHardware = MAG_AK8975;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (magHardwareToUse != MAG_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case MAG_AK8963:
|
||||
#ifdef USE_MAG_AK8963
|
||||
|
@ -123,9 +132,13 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
|
|||
dev->magAlign = MAG_AK8963_ALIGN;
|
||||
#endif
|
||||
magHardware = MAG_AK8963;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (magHardwareToUse != MAG_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case MAG_GPS:
|
||||
#ifdef GPS
|
||||
|
@ -134,9 +147,13 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
|
|||
dev->magAlign = MAG_GPS_ALIGN;
|
||||
#endif
|
||||
magHardware = MAG_GPS;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (magHardwareToUse != MAG_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case MAG_MAG3110:
|
||||
#ifdef USE_MAG_MAG3110
|
||||
|
@ -145,9 +162,13 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
|
|||
dev->magAlign = MAG_MAG3110_ALIGN;
|
||||
#endif
|
||||
magHardware = MAG_MAG3110;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (magHardwareToUse != MAG_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case MAG_IST8310:
|
||||
#ifdef USE_MAG_IST8310
|
||||
|
@ -156,17 +177,25 @@ bool compassDetect(magDev_t *dev, magSensor_e magHardwareToUse)
|
|||
dev->magAlign = MAG_IST8310_ALIGN;
|
||||
#endif
|
||||
magHardware = MAG_IST8310;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (magHardwareToUse != MAG_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case MAG_FAKE:
|
||||
#ifdef USE_FAKE_MAG
|
||||
if (fakeMagDetect(dev)) {
|
||||
magHardware = MAG_FAKE;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (magHardwareToUse != MAG_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case MAG_NONE:
|
||||
magHardware = MAG_NONE;
|
||||
|
|
|
@ -26,13 +26,14 @@
|
|||
// Type of magnetometer used/detected
|
||||
typedef enum {
|
||||
MAG_NONE = 0,
|
||||
MAG_HMC5883 = 1,
|
||||
MAG_AK8975 = 2,
|
||||
MAG_GPS = 3,
|
||||
MAG_MAG3110 = 4,
|
||||
MAG_AK8963 = 5,
|
||||
MAG_IST8310 = 6,
|
||||
MAG_FAKE = 7,
|
||||
MAG_AUTODETECT = 1,
|
||||
MAG_HMC5883 = 2,
|
||||
MAG_AK8975 = 3,
|
||||
MAG_GPS = 4,
|
||||
MAG_MAG3110 = 5,
|
||||
MAG_AK8963 = 6,
|
||||
MAG_IST8310 = 7,
|
||||
MAG_FAKE = 8,
|
||||
MAG_MAX = MAG_FAKE
|
||||
} magSensor_e;
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "common/utils.h"
|
||||
|
||||
#include "config/config.h"
|
||||
#include "config/config_eeprom.h"
|
||||
|
||||
#include "drivers/logging.h"
|
||||
|
||||
|
@ -42,11 +43,13 @@ uint8_t detectedSensors[SENSOR_INDEX_COUNT] = { GYRO_NONE, ACC_NONE, BARO_NONE,
|
|||
|
||||
|
||||
bool sensorsAutodetect(const gyroConfig_t *gyroConfig,
|
||||
const accelerometerConfig_t *accConfig,
|
||||
const compassConfig_t *compassConfig,
|
||||
const barometerConfig_t *baroConfig,
|
||||
const pitotmeterConfig_t *pitotConfig)
|
||||
accelerometerConfig_t *accConfig,
|
||||
compassConfig_t *compassConfig,
|
||||
barometerConfig_t *baroConfig,
|
||||
pitotmeterConfig_t *pitotConfig)
|
||||
{
|
||||
bool eepromUpdatePending = false;
|
||||
|
||||
if (!gyroInit(gyroConfig)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -99,5 +102,30 @@ bool sensorsAutodetect(const gyroConfig_t *gyroConfig,
|
|||
mag.dev.magAlign = compassConfig->mag_align;
|
||||
}
|
||||
|
||||
/* Check if sensor autodetection was requested for some sensors and */
|
||||
if (accConfig->acc_hardware == ACC_AUTODETECT) {
|
||||
accConfig->acc_hardware = detectedSensors[SENSOR_INDEX_ACC];
|
||||
eepromUpdatePending = true;
|
||||
}
|
||||
|
||||
if (baroConfig->baro_hardware == BARO_AUTODETECT) {
|
||||
baroConfig->baro_hardware = detectedSensors[SENSOR_INDEX_BARO];
|
||||
eepromUpdatePending = true;
|
||||
}
|
||||
|
||||
if (compassConfig->mag_hardware == MAG_AUTODETECT) {
|
||||
compassConfig->mag_hardware = detectedSensors[SENSOR_INDEX_MAG];
|
||||
eepromUpdatePending = true;
|
||||
}
|
||||
|
||||
if (pitotConfig->pitot_hardware == PITOT_AUTODETECT) {
|
||||
pitotConfig->pitot_hardware = detectedSensors[SENSOR_INDEX_PITOT];
|
||||
eepromUpdatePending = true;
|
||||
}
|
||||
|
||||
if (eepromUpdatePending) {
|
||||
writeEEPROM();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#pragma once
|
||||
|
||||
bool sensorsAutodetect(const gyroConfig_t *gyroConfig,
|
||||
const accelerometerConfig_t *accConfig,
|
||||
const compassConfig_t *compassConfig,
|
||||
const barometerConfig_t *baroConfig,
|
||||
const pitotmeterConfig_t *pitotConfig);
|
||||
accelerometerConfig_t *accConfig,
|
||||
compassConfig_t *compassConfig,
|
||||
barometerConfig_t *baroConfig,
|
||||
pitotmeterConfig_t *pitotConfig);
|
||||
|
|
|
@ -54,21 +54,30 @@ bool pitotDetect(pitotDev_t *dev, uint8_t pitotHardwareToUse)
|
|||
requestedSensors[SENSOR_INDEX_PITOT] = pitotHardwareToUse;
|
||||
|
||||
switch (pitotHardwareToUse) {
|
||||
case PITOT_AUTODETECT:
|
||||
case PITOT_MS4525:
|
||||
#ifdef USE_PITOT_MS4525
|
||||
if (ms4525Detect(dev)) {
|
||||
pitotHardware = PITOT_MS4525;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (pitotHardwareToUse != PITOT_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case PITOT_FAKE:
|
||||
#ifdef USE_PITOT_FAKE
|
||||
if (fakePitotDetect(&pitot)) {
|
||||
pitotHardware = PITOT_FAKE;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
/* If we are asked for a specific sensor - break out, otherwise - fall through and continue */
|
||||
if (pitotHardwareToUse != PITOT_AUTODETECT) {
|
||||
break;
|
||||
}
|
||||
|
||||
case PITOT_NONE:
|
||||
pitotHardware = PITOT_NONE;
|
||||
|
|
|
@ -21,8 +21,9 @@
|
|||
|
||||
typedef enum {
|
||||
PITOT_NONE = 0,
|
||||
PITOT_MS4525 = 1,
|
||||
PITOT_FAKE = 2,
|
||||
PITOT_AUTODETECT = 1,
|
||||
PITOT_MS4525 = 2,
|
||||
PITOT_FAKE = 3,
|
||||
} pitotSensor_e;
|
||||
|
||||
#define PITOT_MAX PITOT_FAKE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue