From 2b4c6acbb25c73b844e2bacbadee3336d67b244f Mon Sep 17 00:00:00 2001 From: Michel Pastor Date: Tue, 3 Jul 2018 15:58:36 +0200 Subject: [PATCH] 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 --- src/main/fc/fc_tasks.c | 6 +++--- src/main/fc/stats.c | 2 +- src/main/sensors/battery.c | 4 ++-- src/main/telemetry/ibus_shared.c | 4 ++-- src/main/telemetry/mavlink.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index 2bebfb1a05d..653bd6f468d 100755 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -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 diff --git a/src/main/fc/stats.c b/src/main/fc/stats.c index 6ce2c0cb8e6..43534a62a00 100644 --- a/src/main/fc/stats.c +++ b/src/main/fc/stats.c @@ -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; diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index b7183b97c6a..60b2da84751 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -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 diff --git a/src/main/telemetry/ibus_shared.c b/src/main/telemetry/ibus_shared.c index 1492a6977ed..c2525fd0faf 100644 --- a/src/main/telemetry/ibus_shared.c +++ b/src/main/telemetry/ibus_shared.c @@ -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))); // diff --git a/src/main/telemetry/mavlink.c b/src/main/telemetry/mavlink.c index 73b39c3bf38..17e23c8e0ae 100755 --- a/src/main/telemetry/mavlink.c +++ b/src/main/telemetry/mavlink.c @@ -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)