Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix disabling sensor configuration (when device needs battery power) #13177

Merged
merged 6 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/flight/imu.c
Expand Up @@ -262,6 +262,7 @@ STATIC_UNIT_TESTED void imuMahonyAHRSupdate(float dt, float gx, float gy, float
fpVector3_t mag_ef;
matrixVectorMul(&mag_ef, (const fpMat33_t*)&rMat, &mag_bf); // BF->EF true north

#ifdef USE_GPS_RESCUE
// Encapsulate additional operations in a block so that it is only executed when the according debug mode is used
// Only re-calculate magYaw when there is a new Mag data reading, to avoid spikes
if (debugMode == DEBUG_GPS_RESCUE_HEADING && mag.isNewMagADCFlag) {
Expand All @@ -279,6 +280,7 @@ STATIC_UNIT_TESTED void imuMahonyAHRSupdate(float dt, float gx, float gy, float
// note that if the debug doesn't run, this reset will not occur, and we won't waste cycles on the comparison
mag.isNewMagADCFlag = false;
}
#endif

if (useMag && magNormSquared > 0.01f) {
// Normalise magnetometer measurement
Expand Down
45 changes: 37 additions & 8 deletions src/main/msp/msp.c
Expand Up @@ -2049,24 +2049,21 @@ case MSP_NAME:
sbufWriteU8(dst, currentPidProfile->tpa_rate);
sbufWriteU16(dst, currentPidProfile->tpa_breakpoint); // was currentControlRateProfile->tpa_breakpoint
break;

case MSP_SENSOR_CONFIG:
// if sensor name is default setting, use name in runtime config
// use sensorIndex_e index: 0:GyroHardware, 1:AccHardware, 2:BaroHardware, 3:MagHardware, 4:RangefinderHardware
#if defined(USE_ACC)
// Changed with API 1.46
sbufWriteU8(dst, accelerometerConfig()->acc_hardware == ACC_DEFAULT ? detectedSensors[1] : accelerometerConfig()->acc_hardware);
sbufWriteU8(dst, accelerometerConfig()->acc_hardware);
#else
sbufWriteU8(dst, 0);
sbufWriteU8(dst, ACC_NONE);
#endif
#ifdef USE_BARO
// Changed with API 1.46
sbufWriteU8(dst, barometerConfig()->baro_hardware == BARO_DEFAULT ? detectedSensors[2] : barometerConfig()->baro_hardware);
sbufWriteU8(dst, barometerConfig()->baro_hardware);
#else
sbufWriteU8(dst, BARO_NONE);
#endif
#ifdef USE_MAG
// Changed with API 1.46
sbufWriteU8(dst, compassConfig()->mag_hardware == MAG_DEFAULT ? detectedSensors[3] : compassConfig()->mag_hardware);
sbufWriteU8(dst, compassConfig()->mag_hardware);
#else
sbufWriteU8(dst, MAG_NONE);
#endif
Expand All @@ -2078,6 +2075,38 @@ case MSP_NAME:
#endif
break;

// Added in MSP API 1.46
case MSP2_SENSOR_CONFIG_ACTIVE:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much better to me.
It may be possible to keep detectedSensors in format expected by configurator and just dump it. But it may cause problems on refactoring.


#define SENSOR_NOT_AVAILABLE 0xFF

#if defined(USE_GYRO)
sbufWriteU8(dst, detectedSensors[SENSOR_INDEX_GYRO]);
#else
sbufWriteU8(dst, SENSOR_NOT_AVAILABLE);
#endif
#if defined(USE_ACC)
sbufWriteU8(dst, detectedSensors[SENSOR_INDEX_ACC]);
#else
sbufWriteU8(dst, SENSOR_NOT_AVAILABLE);
#endif
#ifdef USE_BARO
sbufWriteU8(dst, detectedSensors[SENSOR_INDEX_BARO]);
#else
sbufWriteU8(dst, SENSOR_NOT_AVAILABLE);
#endif
#ifdef USE_MAG
sbufWriteU8(dst, detectedSensors[SENSOR_INDEX_MAG]);
#else
sbufWriteU8(dst, SENSOR_NOT_AVAILABLE);
#endif
#ifdef USE_RANGEFINDER
sbufWriteU8(dst, detectedSensors[SENSOR_INDEX_RANGEFINDER]);
#else
sbufWriteU8(dst, SENSOR_NOT_AVAILABLE);
#endif
break;

#if defined(USE_VTX_COMMON)
case MSP_VTX_CONFIG:
{
Expand Down
1 change: 1 addition & 0 deletions src/main/msp/msp_protocol_v2_betaflight.h
Expand Up @@ -28,6 +28,7 @@
#define MSP2_SET_TEXT 0x3007
#define MSP2_GET_LED_STRIP_CONFIG_VALUES 0x3008
#define MSP2_SET_LED_STRIP_CONFIG_VALUES 0x3009
#define MSP2_SENSOR_CONFIG_ACTIVE 0x300A

// MSP2_SET_TEXT and MSP2_GET_TEXT variable types
#define MSP2TEXT_PILOT_NAME 1
Expand Down
8 changes: 5 additions & 3 deletions src/main/sensors/barometer.c
Expand Up @@ -466,9 +466,11 @@ uint32_t baroUpdate(timeUs_t currentTimeUs)
}
}

DEBUG_SET(DEBUG_BARO, 1, lrintf(baro.pressure / 100.0f)); // hPa
DEBUG_SET(DEBUG_BARO, 2, baro.temperature); // c°C
DEBUG_SET(DEBUG_BARO, 3, lrintf(baro.altitude)); // cm
if (debugMode == DEBUG_BARO) {
DEBUG_SET(DEBUG_BARO, 1, lrintf(baro.pressure / 100.0f)); // hPa
DEBUG_SET(DEBUG_BARO, 2, baro.temperature); // c°C
DEBUG_SET(DEBUG_BARO, 3, lrintf(baro.altitude)); // cm
}

if (baro.dev.combined_read) {
state = BARO_STATE_PRESSURE_START;
Expand Down
8 changes: 4 additions & 4 deletions src/main/sensors/initialisation.c
Expand Up @@ -77,14 +77,14 @@ bool sensorsAutodetect(void)
}
#endif

#ifdef USE_MAG
compassInit();
#endif

#ifdef USE_BARO
baroInit();
#endif

#ifdef USE_MAG
compassInit();
#endif

#ifdef USE_RANGEFINDER
rangefinderInit();
#endif
Expand Down