Added checks for ESC_SENSOR feature being enabled when reading ESC sensor data. (#5663)

This commit is contained in:
Michael Keller 2018-04-11 23:31:14 +12:00 committed by GitHub
parent 6cfec6fc53
commit e0dcea4d48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 5 deletions

View File

@ -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.

View File

@ -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 {

View File

@ -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) {

View File

@ -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
}

View File

@ -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