1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-18 22:05:17 +03:00

Merge pull request #2193 from mikeller/disable_current_sensing_without_battery

Disabled battery current sensing if no battery is connected.
This commit is contained in:
Michael Keller 2017-01-25 12:56:32 +13:00 committed by GitHub
commit 1fe48b913a

View file

@ -266,56 +266,61 @@ void updateConsumptionWarning(void)
void updateCurrentMeter(int32_t lastUpdateAt, rxConfig_t *rxConfig, uint16_t deadband3d_throttle) void updateCurrentMeter(int32_t lastUpdateAt, rxConfig_t *rxConfig, uint16_t deadband3d_throttle)
{ {
switch(batteryConfig->currentMeterType) { if (getBatteryState() != BATTERY_NOT_PRESENT) {
case CURRENT_SENSOR_ADC: switch(batteryConfig->currentMeterType) {
updateBatteryCurrent(); case CURRENT_SENSOR_ADC:
updateBatteryCurrent();
updateCurrentDrawn(lastUpdateAt); updateCurrentDrawn(lastUpdateAt);
updateConsumptionWarning(); updateConsumptionWarning();
break; break;
case CURRENT_SENSOR_VIRTUAL: case CURRENT_SENSOR_VIRTUAL:
amperageLatest = (int32_t)batteryConfig->currentMeterOffset; amperageLatest = (int32_t)batteryConfig->currentMeterOffset;
if (ARMING_FLAG(ARMED)) { if (ARMING_FLAG(ARMED)) {
throttleStatus_e throttleStatus = calculateThrottleStatus(rxConfig, deadband3d_throttle); throttleStatus_e throttleStatus = calculateThrottleStatus(rxConfig, deadband3d_throttle);
int throttleOffset = (int32_t)rcCommand[THROTTLE] - 1000; int throttleOffset = (int32_t)rcCommand[THROTTLE] - 1000;
if (throttleStatus == THROTTLE_LOW && feature(FEATURE_MOTOR_STOP)) { if (throttleStatus == THROTTLE_LOW && feature(FEATURE_MOTOR_STOP)) {
throttleOffset = 0; throttleOffset = 0;
} }
int throttleFactor = throttleOffset + (throttleOffset * throttleOffset / 50); int throttleFactor = throttleOffset + (throttleOffset * throttleOffset / 50);
amperageLatest += throttleFactor * (int32_t)batteryConfig->currentMeterScale / 1000; amperageLatest += throttleFactor * (int32_t)batteryConfig->currentMeterScale / 1000;
}
amperage = amperageLatest;
updateCurrentDrawn(lastUpdateAt);
updateConsumptionWarning();
break;
case CURRENT_SENSOR_ESC:
#ifdef USE_ESC_SENSOR
if (feature(FEATURE_ESC_SENSOR)) {
escSensorData_t *escData = getEscSensorData(ESC_SENSOR_COMBINED);
if (escData->dataAge <= MAX_ESC_BATTERY_AGE) {
amperageLatest = escData->current;
mAhDrawn = escData->consumption;
} else {
amperageLatest = 0;
mAhDrawn = 0;
} }
amperage = amperageLatest; amperage = amperageLatest;
updateCurrentDrawn(lastUpdateAt);
updateConsumptionWarning(); updateConsumptionWarning();
}
break; break;
#endif case CURRENT_SENSOR_ESC:
case CURRENT_SENSOR_NONE: #ifdef USE_ESC_SENSOR
amperage = 0; if (feature(FEATURE_ESC_SENSOR)) {
amperageLatest = 0; escSensorData_t *escData = getEscSensorData(ESC_SENSOR_COMBINED);
if (escData->dataAge <= MAX_ESC_BATTERY_AGE) {
amperageLatest = escData->current;
mAhDrawn = escData->consumption;
} else {
amperageLatest = 0;
mAhDrawn = 0;
}
amperage = amperageLatest;
break; updateConsumptionWarning();
}
break;
#endif
case CURRENT_SENSOR_NONE:
amperage = 0;
amperageLatest = 0;
break;
}
} else {
amperage = 0;
amperageLatest = 0;
} }
} }