mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-25 17:25:18 +03:00
Replace feature(FEATURE_CURRENT_METER) by isAmperageConfigured() where it makes sense
The `CURRENT_METER` feature can be enableb but the current meter type could have been set to none
This commit is contained in:
parent
6a0a25a7d8
commit
2b4c6acbb2
5 changed files with 9 additions and 9 deletions
|
@ -101,12 +101,12 @@ void taskUpdateBattery(timeUs_t currentTimeUs)
|
|||
static timeUs_t batMonitoringLastServiced = 0;
|
||||
timeUs_t BatMonitoringTimeSinceLastServiced = cmpTimeUs(currentTimeUs, batMonitoringLastServiced);
|
||||
|
||||
if (feature(FEATURE_CURRENT_METER))
|
||||
if (isAmperageConfigured())
|
||||
currentMeterUpdate(BatMonitoringTimeSinceLastServiced);
|
||||
#ifdef USE_ADC
|
||||
if (feature(FEATURE_VBAT))
|
||||
batteryUpdate(BatMonitoringTimeSinceLastServiced);
|
||||
if (feature(FEATURE_VBAT) && feature(FEATURE_CURRENT_METER)) {
|
||||
if (feature(FEATURE_VBAT) && isAmperageConfigured()) {
|
||||
powerMeterUpdate(BatMonitoringTimeSinceLastServiced);
|
||||
sagCompensatedVBatUpdate(currentTimeUs, BatMonitoringTimeSinceLastServiced);
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ void fcTasksInit(void)
|
|||
#ifdef USE_LIGHTS
|
||||
setTaskEnabled(TASK_LIGHTS, true);
|
||||
#endif
|
||||
setTaskEnabled(TASK_BATTERY, feature(FEATURE_VBAT) || feature(FEATURE_CURRENT_METER));
|
||||
setTaskEnabled(TASK_BATTERY, feature(FEATURE_VBAT) || isAmperageConfigured());
|
||||
setTaskEnabled(TASK_TEMPERATURE, true);
|
||||
setTaskEnabled(TASK_RX, true);
|
||||
#ifdef USE_GPS
|
||||
|
|
|
@ -57,7 +57,7 @@ void statsOnDisarm(void)
|
|||
statsConfigMutable()->stats_total_time += dt; //[s]
|
||||
statsConfigMutable()->stats_total_dist += (getTotalTravelDistance() - arm_distance_cm) / 100; //[m]
|
||||
#ifdef USE_ADC
|
||||
if (feature(FEATURE_VBAT) && feature(FEATURE_CURRENT_METER)) {
|
||||
if (feature(FEATURE_VBAT) && isAmperageConfigured()) {
|
||||
const uint32_t energy = getMWhDrawn() - arm_mWhDrawn;
|
||||
statsConfigMutable()->stats_total_energy += energy;
|
||||
flyingEnergy += energy;
|
||||
|
|
|
@ -253,7 +253,7 @@ void batteryUpdate(timeUs_t timeDelta)
|
|||
batteryCriticalVoltage = batteryCellCount * currentBatteryProfile->voltage.cellMin;
|
||||
|
||||
batteryFullWhenPluggedIn = batteryAdcToVoltage(vbatLatestADC) >= (batteryFullVoltage - batteryCellCount * VBATT_CELL_FULL_MAX_DIFF);
|
||||
batteryUseCapacityThresholds = feature(FEATURE_CURRENT_METER) && batteryFullWhenPluggedIn && (currentBatteryProfile->capacity.value > 0) &&
|
||||
batteryUseCapacityThresholds = isAmperageConfigured() && batteryFullWhenPluggedIn && (currentBatteryProfile->capacity.value > 0) &&
|
||||
(currentBatteryProfile->capacity.warning > 0) && (currentBatteryProfile->capacity.critical > 0);
|
||||
|
||||
}
|
||||
|
@ -559,7 +559,7 @@ uint8_t calculateBatteryPercentage(void)
|
|||
if (batteryState == BATTERY_NOT_PRESENT)
|
||||
return 0;
|
||||
|
||||
if (batteryFullWhenPluggedIn && feature(FEATURE_CURRENT_METER) && (currentBatteryProfile->capacity.value > 0) && (currentBatteryProfile->capacity.critical > 0)) {
|
||||
if (batteryFullWhenPluggedIn && isAmperageConfigured() && (currentBatteryProfile->capacity.value > 0) && (currentBatteryProfile->capacity.critical > 0)) {
|
||||
uint32_t capacityDiffBetweenFullAndEmpty = currentBatteryProfile->capacity.value - currentBatteryProfile->capacity.critical;
|
||||
return constrain(batteryRemainingCapacity * 100 / capacityDiffBetweenFullAndEmpty, 0, 100);
|
||||
} else
|
||||
|
|
|
@ -158,10 +158,10 @@ static uint8_t dispatchMeasurementRequest(ibusAddress_t address) {
|
|||
return sendIbusMeasurement2(address, getBatteryVoltage());
|
||||
}
|
||||
} else if (SENSOR_ADDRESS_TYPE_LOOKUP[address].value == IBUS_MEAS_VALUE_CURRENT) { //CURR in 10*mA, 1 = 10 mA
|
||||
if (feature(FEATURE_CURRENT_METER)) return sendIbusMeasurement2(address, (uint16_t) getAmperage()); //int32_t
|
||||
if (isAmperageConfigured()) return sendIbusMeasurement2(address, (uint16_t) getAmperage()); //int32_t
|
||||
else return sendIbusMeasurement2(address, 0);
|
||||
} else if (SENSOR_ADDRESS_TYPE_LOOKUP[address].value == IBUS_MEAS_VALUE_FUEL) { //capacity in mAh
|
||||
if (feature(FEATURE_CURRENT_METER)) return sendIbusMeasurement2(address, (uint16_t) getMAhDrawn()); //int32_t
|
||||
if (isAmperageConfigured()) return sendIbusMeasurement2(address, (uint16_t) getMAhDrawn()); //int32_t
|
||||
else return sendIbusMeasurement2(address, 0);
|
||||
} else if (SENSOR_ADDRESS_TYPE_LOOKUP[address].value == IBUS_MEAS_VALUE_CLIMB) {
|
||||
return sendIbusMeasurement2(address, (int16_t) (getEstimatedActualVelocity(Z))); //
|
||||
|
|
|
@ -226,7 +226,7 @@ void mavlinkSendSystemStatus(void)
|
|||
// voltage_battery Battery voltage, in millivolts (1 = 1 millivolt)
|
||||
feature(FEATURE_VBAT) ? getBatteryVoltage() * 10 : 0,
|
||||
// current_battery Battery current, in 10*milliamperes (1 = 10 milliampere), -1: autopilot does not measure the current
|
||||
feature(FEATURE_CURRENT_METER) ? getAmperage() : -1,
|
||||
isAmperageConfigured() ? getAmperage() : -1,
|
||||
// battery_remaining Remaining battery energy: (0%: 0, 100%: 100), -1: autopilot estimate the remaining battery
|
||||
feature(FEATURE_VBAT) ? calculateBatteryPercentage() : 100,
|
||||
// drop_rate_comm Communication drops in percent, (0%: 0, 100%: 10'000), (UART, I2C, SPI, CAN), dropped packets on all links (packets that were corrupted on reception on the MAV)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue