mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 00:35:39 +03:00
CF/BF - use one task for each battery sensor.
This commit is contained in:
parent
d331ceff0b
commit
c0c6450e61
2 changed files with 25 additions and 34 deletions
|
@ -89,12 +89,6 @@ void taskBstMasterProcess(timeUs_t currentTimeUs);
|
||||||
#define TASK_PERIOD_MS(ms) ((ms) * 1000)
|
#define TASK_PERIOD_MS(ms) ((ms) * 1000)
|
||||||
#define TASK_PERIOD_US(us) (us)
|
#define TASK_PERIOD_US(us) (us)
|
||||||
|
|
||||||
/* VBAT monitoring interval (in microseconds) - 1s*/
|
|
||||||
#define VBATINTERVAL (6 * 3500)
|
|
||||||
/* IBat monitoring interval (in microseconds) - 6 default looptimes */
|
|
||||||
#define IBATINTERVAL (6 * 3500)
|
|
||||||
|
|
||||||
|
|
||||||
static void taskUpdateAccelerometer(timeUs_t currentTimeUs)
|
static void taskUpdateAccelerometer(timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
UNUSED(currentTimeUs);
|
UNUSED(currentTimeUs);
|
||||||
|
@ -116,28 +110,16 @@ static void taskHandleSerial(timeUs_t currentTimeUs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void taskBatterySensors(timeUs_t currentTimeUs)
|
void taskBatteryVoltage(timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
static uint32_t vbatLastServiced = 0;
|
UNUSED(currentTimeUs);
|
||||||
|
|
||||||
if (batteryConfig()->voltageMeterSource != VOLTAGE_METER_NONE) {
|
|
||||||
if (cmp32(currentTimeUs, vbatLastServiced) >= VBATINTERVAL) {
|
|
||||||
vbatLastServiced = currentTimeUs;
|
|
||||||
|
|
||||||
batteryUpdateVoltage();
|
batteryUpdateVoltage();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (batteryConfig()->currentMeterSource != CURRENT_METER_NONE) {
|
void taskBatteryCurrent(timeUs_t currentTimeUs)
|
||||||
|
{
|
||||||
static uint32_t ibatLastServiced = 0;
|
UNUSED(currentTimeUs);
|
||||||
const int32_t ibatTimeSinceLastServiced = cmp32(currentTimeUs, ibatLastServiced);
|
batteryUpdateCurrentMeter(getTaskDeltaTime(TASK_SELF), ARMING_FLAG(ARMED));
|
||||||
|
|
||||||
if (ibatTimeSinceLastServiced >= IBATINTERVAL) {
|
|
||||||
ibatLastServiced = currentTimeUs;
|
|
||||||
batteryUpdateCurrentMeter(ibatTimeSinceLastServiced, ARMING_FLAG(ARMED));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void taskBatteryAlerts(timeUs_t currentTimeUs)
|
void taskBatteryAlerts(timeUs_t currentTimeUs)
|
||||||
|
@ -254,11 +236,13 @@ void fcTasksInit(void)
|
||||||
setTaskEnabled(TASK_SERIAL, true);
|
setTaskEnabled(TASK_SERIAL, true);
|
||||||
rescheduleTask(TASK_SERIAL, TASK_PERIOD_HZ(serialConfig()->serial_update_rate_hz));
|
rescheduleTask(TASK_SERIAL, TASK_PERIOD_HZ(serialConfig()->serial_update_rate_hz));
|
||||||
|
|
||||||
bool useBatterySensors = batteryConfig()->voltageMeterSource != VOLTAGE_METER_NONE || batteryConfig()->currentMeterSource != CURRENT_METER_NONE;
|
bool useBatteryVoltage = batteryConfig()->voltageMeterSource != VOLTAGE_METER_NONE;
|
||||||
setTaskEnabled(TASK_BATTERY_SENSORS, useBatterySensors);
|
setTaskEnabled(TASK_BATTERY_VOLTAGE, useBatteryVoltage);
|
||||||
|
bool useBatteryCurrent = batteryConfig()->currentMeterSource != CURRENT_METER_NONE;
|
||||||
|
setTaskEnabled(TASK_BATTERY_CURRENT, useBatteryCurrent);
|
||||||
|
|
||||||
bool useBatteryAlerts = batteryConfig()->useVBatAlerts || batteryConfig()->useConsumptionAlerts || feature(FEATURE_OSD);
|
bool useBatteryAlerts = batteryConfig()->useVBatAlerts || batteryConfig()->useConsumptionAlerts || feature(FEATURE_OSD);
|
||||||
setTaskEnabled(TASK_BATTERY_ALERTS, useBatterySensors && useBatteryAlerts);
|
setTaskEnabled(TASK_BATTERY_ALERTS, (useBatteryVoltage || useBatteryCurrent) && useBatteryAlerts);
|
||||||
|
|
||||||
setTaskEnabled(TASK_RX, true);
|
setTaskEnabled(TASK_RX, true);
|
||||||
|
|
||||||
|
@ -395,10 +379,16 @@ cfTask_t cfTasks[TASK_COUNT] = {
|
||||||
.staticPriority = TASK_PRIORITY_MEDIUM,
|
.staticPriority = TASK_PRIORITY_MEDIUM,
|
||||||
},
|
},
|
||||||
|
|
||||||
[TASK_BATTERY_SENSORS] = {
|
[TASK_BATTERY_VOLTAGE] = {
|
||||||
.taskName = "BATTERY_SENSORS",
|
.taskName = "BATTERY_VOLTAGE",
|
||||||
.taskFunc = taskBatterySensors,
|
.taskFunc = taskBatteryVoltage,
|
||||||
.desiredPeriod = TASK_PERIOD_HZ(50), // 50 Hz
|
.desiredPeriod = TASK_PERIOD_HZ(50),
|
||||||
|
.staticPriority = TASK_PRIORITY_MEDIUM,
|
||||||
|
},
|
||||||
|
[TASK_BATTERY_CURRENT] = {
|
||||||
|
.taskName = "BATTERY_CURRENT",
|
||||||
|
.taskFunc = taskBatteryCurrent,
|
||||||
|
.desiredPeriod = TASK_PERIOD_HZ(50),
|
||||||
.staticPriority = TASK_PRIORITY_MEDIUM,
|
.staticPriority = TASK_PRIORITY_MEDIUM,
|
||||||
},
|
},
|
||||||
#ifdef BEEPER
|
#ifdef BEEPER
|
||||||
|
|
|
@ -56,7 +56,8 @@ typedef enum {
|
||||||
TASK_RX,
|
TASK_RX,
|
||||||
TASK_SERIAL,
|
TASK_SERIAL,
|
||||||
TASK_DISPATCH,
|
TASK_DISPATCH,
|
||||||
TASK_BATTERY_SENSORS,
|
TASK_BATTERY_VOLTAGE,
|
||||||
|
TASK_BATTERY_CURRENT,
|
||||||
TASK_BATTERY_ALERTS,
|
TASK_BATTERY_ALERTS,
|
||||||
#ifdef BEEPER
|
#ifdef BEEPER
|
||||||
TASK_BEEPER,
|
TASK_BEEPER,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue