mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 07:15:18 +03:00
CF/BF - reduce code size by changing dependencies in battery.c and removing two
functions from fc_tasks.c I don't like the dependency changes, but I'm not overly concerned by them.
This commit is contained in:
parent
486b5a1b9a
commit
709cd9f8df
3 changed files with 16 additions and 20 deletions
|
@ -109,19 +109,6 @@ static void taskHandleSerial(timeUs_t currentTimeUs)
|
||||||
mspSerialProcess(ARMING_FLAG(ARMED) ? MSP_SKIP_NON_MSP_DATA : MSP_EVALUATE_NON_MSP_DATA, mspFcProcessCommand);
|
mspSerialProcess(ARMING_FLAG(ARMED) ? MSP_SKIP_NON_MSP_DATA : MSP_EVALUATE_NON_MSP_DATA, mspFcProcessCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void taskBatteryVoltage(timeUs_t currentTimeUs)
|
|
||||||
{
|
|
||||||
UNUSED(currentTimeUs);
|
|
||||||
batteryUpdateVoltage();
|
|
||||||
}
|
|
||||||
|
|
||||||
void taskBatteryCurrent(timeUs_t currentTimeUs)
|
|
||||||
{
|
|
||||||
UNUSED(currentTimeUs);
|
|
||||||
batteryUpdateCurrentMeter(getTaskDeltaTime(TASK_SELF), ARMING_FLAG(ARMED));
|
|
||||||
}
|
|
||||||
|
|
||||||
void taskBatteryAlerts(timeUs_t currentTimeUs)
|
void taskBatteryAlerts(timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
UNUSED(currentTimeUs);
|
UNUSED(currentTimeUs);
|
||||||
|
@ -381,13 +368,13 @@ cfTask_t cfTasks[TASK_COUNT] = {
|
||||||
|
|
||||||
[TASK_BATTERY_VOLTAGE] = {
|
[TASK_BATTERY_VOLTAGE] = {
|
||||||
.taskName = "BATTERY_VOLTAGE",
|
.taskName = "BATTERY_VOLTAGE",
|
||||||
.taskFunc = taskBatteryVoltage,
|
.taskFunc = batteryUpdateVoltage,
|
||||||
.desiredPeriod = TASK_PERIOD_HZ(50),
|
.desiredPeriod = TASK_PERIOD_HZ(50),
|
||||||
.staticPriority = TASK_PRIORITY_MEDIUM,
|
.staticPriority = TASK_PRIORITY_MEDIUM,
|
||||||
},
|
},
|
||||||
[TASK_BATTERY_CURRENT] = {
|
[TASK_BATTERY_CURRENT] = {
|
||||||
.taskName = "BATTERY_CURRENT",
|
.taskName = "BATTERY_CURRENT",
|
||||||
.taskFunc = taskBatteryCurrent,
|
.taskFunc = batteryUpdateCurrentMeter,
|
||||||
.desiredPeriod = TASK_PERIOD_HZ(50),
|
.desiredPeriod = TASK_PERIOD_HZ(50),
|
||||||
.staticPriority = TASK_PRIORITY_MEDIUM,
|
.staticPriority = TASK_PRIORITY_MEDIUM,
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
#include "common/maths.h"
|
#include "common/maths.h"
|
||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
|
|
||||||
|
#include "scheduler/scheduler.h"
|
||||||
|
|
||||||
#include "config/feature.h"
|
#include "config/feature.h"
|
||||||
#include "config/parameter_group.h"
|
#include "config/parameter_group.h"
|
||||||
#include "config/parameter_group_ids.h"
|
#include "config/parameter_group_ids.h"
|
||||||
|
@ -33,6 +35,7 @@
|
||||||
#include "drivers/adc.h"
|
#include "drivers/adc.h"
|
||||||
#include "drivers/system.h"
|
#include "drivers/system.h"
|
||||||
|
|
||||||
|
#include "fc/runtime_config.h"
|
||||||
#include "fc/config.h"
|
#include "fc/config.h"
|
||||||
#include "fc/rc_controls.h"
|
#include "fc/rc_controls.h"
|
||||||
|
|
||||||
|
@ -102,8 +105,10 @@ PG_RESET_TEMPLATE(batteryConfig_t, batteryConfig,
|
||||||
.vbathysteresis = 1
|
.vbathysteresis = 1
|
||||||
);
|
);
|
||||||
|
|
||||||
void batteryUpdateVoltage(void)
|
void batteryUpdateVoltage(timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
|
UNUSED(currentTimeUs);
|
||||||
|
|
||||||
switch(batteryConfig()->voltageMeterSource) {
|
switch(batteryConfig()->voltageMeterSource) {
|
||||||
#ifdef USE_ESC_SENSOR
|
#ifdef USE_ESC_SENSOR
|
||||||
case VOLTAGE_METER_ESC:
|
case VOLTAGE_METER_ESC:
|
||||||
|
@ -315,13 +320,16 @@ static void batteryUpdateConsumptionState(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void batteryUpdateCurrentMeter(int32_t lastUpdateAt, bool armed)
|
void batteryUpdateCurrentMeter(timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
|
UNUSED(currentTimeUs);
|
||||||
if (batteryCellCount == 0) {
|
if (batteryCellCount == 0) {
|
||||||
currentMeterReset(¤tMeter);
|
currentMeterReset(¤tMeter);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t lastUpdateAt = getTaskDeltaTime(TASK_SELF);
|
||||||
|
|
||||||
switch(batteryConfig()->currentMeterSource) {
|
switch(batteryConfig()->currentMeterSource) {
|
||||||
case CURRENT_METER_ADC:
|
case CURRENT_METER_ADC:
|
||||||
currentMeterADCRefresh(lastUpdateAt);
|
currentMeterADCRefresh(lastUpdateAt);
|
||||||
|
@ -333,7 +341,7 @@ void batteryUpdateCurrentMeter(int32_t lastUpdateAt, bool armed)
|
||||||
bool throttleLowAndMotorStop = (throttleStatus == THROTTLE_LOW && feature(FEATURE_MOTOR_STOP));
|
bool throttleLowAndMotorStop = (throttleStatus == THROTTLE_LOW && feature(FEATURE_MOTOR_STOP));
|
||||||
int32_t throttleOffset = (int32_t)rcCommand[THROTTLE] - 1000;
|
int32_t throttleOffset = (int32_t)rcCommand[THROTTLE] - 1000;
|
||||||
|
|
||||||
currentMeterVirtualRefresh(lastUpdateAt, armed, throttleLowAndMotorStop, throttleOffset);
|
currentMeterVirtualRefresh(lastUpdateAt, ARMING_FLAG(ARMED), throttleLowAndMotorStop, throttleOffset);
|
||||||
currentMeterVirtualRead(¤tMeter);
|
currentMeterVirtualRead(¤tMeter);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "config/parameter_group.h"
|
#include "config/parameter_group.h"
|
||||||
|
|
||||||
#include "common/filter.h"
|
#include "common/filter.h"
|
||||||
|
#include "common/time.h"
|
||||||
#include "sensors/current.h"
|
#include "sensors/current.h"
|
||||||
#include "sensors/voltage.h"
|
#include "sensors/voltage.h"
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ typedef enum {
|
||||||
} batteryState_e;
|
} batteryState_e;
|
||||||
|
|
||||||
void batteryInit(void);
|
void batteryInit(void);
|
||||||
void batteryUpdateVoltage(void);
|
void batteryUpdateVoltage(timeUs_t currentTimeUs);
|
||||||
void batteryUpdatePresence(void);
|
void batteryUpdatePresence(void);
|
||||||
|
|
||||||
batteryState_e getBatteryState(void);
|
batteryState_e getBatteryState(void);
|
||||||
|
@ -74,4 +75,4 @@ int32_t getAmperage(void);
|
||||||
int32_t getAmperageLatest(void);
|
int32_t getAmperageLatest(void);
|
||||||
int32_t getMAhDrawn(void);
|
int32_t getMAhDrawn(void);
|
||||||
|
|
||||||
void batteryUpdateCurrentMeter(int32_t lastUpdateAt, bool armed);
|
void batteryUpdateCurrentMeter(timeUs_t currentTimeUs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue