diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 96871cc7e..c1a569008 100644 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -276,6 +276,12 @@ static void validateAndFixConfig(void) } #endif // USE_OSD_SLAVE +#if defined(USE_ESC_SENSOR) + if (!findSerialPortConfig(FUNCTION_ESC_SENSOR)) { + featureClear(FEATURE_ESC_SENSOR); + } +#endif + // clear features that are not supported. // I have kept them all here in one place, some could be moved to sections of code above. diff --git a/src/main/sensors/current.c b/src/main/sensors/current.c index 38b37147a..cb65cb766 100644 --- a/src/main/sensors/current.c +++ b/src/main/sensors/current.c @@ -218,7 +218,7 @@ void currentMeterESCRefresh(int32_t lastUpdateAt) UNUSED(lastUpdateAt); escSensorData_t *escData = getEscSensorData(ESC_SENSOR_COMBINED); - if (escData->dataAge <= ESC_BATTERY_AGE_MAX) { + if (escData && escData->dataAge <= ESC_BATTERY_AGE_MAX) { currentMeterESCState.amperage = escData->current; currentMeterESCState.mAhDrawn = escData->consumption; } else { diff --git a/src/main/sensors/esc_sensor.c b/src/main/sensors/esc_sensor.c index f025d34e7..eb588689b 100644 --- a/src/main/sensors/esc_sensor.c +++ b/src/main/sensors/esc_sensor.c @@ -145,6 +145,10 @@ bool isEscSensorActive(void) escSensorData_t *getEscSensorData(uint8_t motorNumber) { + if (!feature(FEATURE_ESC_SENSOR)) { + return NULL; + } + if (motorNumber < getMotorCount()) { return &escSensorData[motorNumber]; } else if (motorNumber == ESC_SENSOR_COMBINED) { diff --git a/src/main/sensors/voltage.c b/src/main/sensors/voltage.c index a8e59389f..45477c69b 100644 --- a/src/main/sensors/voltage.c +++ b/src/main/sensors/voltage.c @@ -220,8 +220,10 @@ void voltageMeterESCRefresh(void) { #ifdef USE_ESC_SENSOR escSensorData_t *escData = getEscSensorData(ESC_SENSOR_COMBINED); - voltageMeterESCState.voltageUnfiltered = escData->dataAge <= ESC_BATTERY_AGE_MAX ? escData->voltage / 10 : 0; - voltageMeterESCState.voltageFiltered = biquadFilterApply(&voltageMeterESCState.filter, voltageMeterESCState.voltageUnfiltered); + if (escData) { + voltageMeterESCState.voltageUnfiltered = escData->dataAge <= ESC_BATTERY_AGE_MAX ? escData->voltage / 10 : 0; + voltageMeterESCState.voltageFiltered = biquadFilterApply(&voltageMeterESCState.filter, voltageMeterESCState.voltageUnfiltered); + } #endif } diff --git a/src/main/telemetry/frsky_hub.c b/src/main/telemetry/frsky_hub.c index 844638ea3..7785426dc 100644 --- a/src/main/telemetry/frsky_hub.c +++ b/src/main/telemetry/frsky_hub.c @@ -182,7 +182,9 @@ static void sendThrottleOrBatterySizeAsRpm(void) int16_t data; #if defined(USE_ESC_SENSOR) escSensorData_t *escData = getEscSensorData(ESC_SENSOR_COMBINED); - data = escData->dataAge < ESC_DATA_INVALID ? escData->rpm : 0; + if (escData) { + data = escData->dataAge < ESC_DATA_INVALID ? escData->rpm : 0; + } #else if (ARMING_FLAG(ARMED)) { const throttleStatus_e throttleStatus = calculateThrottleStatus(); @@ -204,7 +206,9 @@ static void sendTemperature1(void) int16_t data; #if defined(USE_ESC_SENSOR) escSensorData_t *escData = getEscSensorData(ESC_SENSOR_COMBINED); - data = escData->dataAge < ESC_DATA_INVALID ? escData->temperature : 0; + if (escData) { + data = escData->dataAge < ESC_DATA_INVALID ? escData->temperature : 0; + } #elif defined(USE_BARO) data = (baro.baroTemperature + 50)/ 100; // Airmamaf #else