mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 00:35:39 +03:00
Added checks for ESC_SENSOR feature being enabled when reading ESC sensor data. (#5663)
This commit is contained in:
parent
6cfec6fc53
commit
e0dcea4d48
5 changed files with 21 additions and 5 deletions
|
@ -276,6 +276,12 @@ static void validateAndFixConfig(void)
|
||||||
}
|
}
|
||||||
#endif // USE_OSD_SLAVE
|
#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.
|
// clear features that are not supported.
|
||||||
// I have kept them all here in one place, some could be moved to sections of code above.
|
// I have kept them all here in one place, some could be moved to sections of code above.
|
||||||
|
|
||||||
|
|
|
@ -218,7 +218,7 @@ void currentMeterESCRefresh(int32_t lastUpdateAt)
|
||||||
UNUSED(lastUpdateAt);
|
UNUSED(lastUpdateAt);
|
||||||
|
|
||||||
escSensorData_t *escData = getEscSensorData(ESC_SENSOR_COMBINED);
|
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.amperage = escData->current;
|
||||||
currentMeterESCState.mAhDrawn = escData->consumption;
|
currentMeterESCState.mAhDrawn = escData->consumption;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -145,6 +145,10 @@ bool isEscSensorActive(void)
|
||||||
|
|
||||||
escSensorData_t *getEscSensorData(uint8_t motorNumber)
|
escSensorData_t *getEscSensorData(uint8_t motorNumber)
|
||||||
{
|
{
|
||||||
|
if (!feature(FEATURE_ESC_SENSOR)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (motorNumber < getMotorCount()) {
|
if (motorNumber < getMotorCount()) {
|
||||||
return &escSensorData[motorNumber];
|
return &escSensorData[motorNumber];
|
||||||
} else if (motorNumber == ESC_SENSOR_COMBINED) {
|
} else if (motorNumber == ESC_SENSOR_COMBINED) {
|
||||||
|
|
|
@ -220,8 +220,10 @@ void voltageMeterESCRefresh(void)
|
||||||
{
|
{
|
||||||
#ifdef USE_ESC_SENSOR
|
#ifdef USE_ESC_SENSOR
|
||||||
escSensorData_t *escData = getEscSensorData(ESC_SENSOR_COMBINED);
|
escSensorData_t *escData = getEscSensorData(ESC_SENSOR_COMBINED);
|
||||||
voltageMeterESCState.voltageUnfiltered = escData->dataAge <= ESC_BATTERY_AGE_MAX ? escData->voltage / 10 : 0;
|
if (escData) {
|
||||||
voltageMeterESCState.voltageFiltered = biquadFilterApply(&voltageMeterESCState.filter, voltageMeterESCState.voltageUnfiltered);
|
voltageMeterESCState.voltageUnfiltered = escData->dataAge <= ESC_BATTERY_AGE_MAX ? escData->voltage / 10 : 0;
|
||||||
|
voltageMeterESCState.voltageFiltered = biquadFilterApply(&voltageMeterESCState.filter, voltageMeterESCState.voltageUnfiltered);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,7 +182,9 @@ static void sendThrottleOrBatterySizeAsRpm(void)
|
||||||
int16_t data;
|
int16_t data;
|
||||||
#if defined(USE_ESC_SENSOR)
|
#if defined(USE_ESC_SENSOR)
|
||||||
escSensorData_t *escData = getEscSensorData(ESC_SENSOR_COMBINED);
|
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
|
#else
|
||||||
if (ARMING_FLAG(ARMED)) {
|
if (ARMING_FLAG(ARMED)) {
|
||||||
const throttleStatus_e throttleStatus = calculateThrottleStatus();
|
const throttleStatus_e throttleStatus = calculateThrottleStatus();
|
||||||
|
@ -204,7 +206,9 @@ static void sendTemperature1(void)
|
||||||
int16_t data;
|
int16_t data;
|
||||||
#if defined(USE_ESC_SENSOR)
|
#if defined(USE_ESC_SENSOR)
|
||||||
escSensorData_t *escData = getEscSensorData(ESC_SENSOR_COMBINED);
|
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)
|
#elif defined(USE_BARO)
|
||||||
data = (baro.baroTemperature + 50)/ 100; // Airmamaf
|
data = (baro.baroTemperature + 50)/ 100; // Airmamaf
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue