mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 12:25:20 +03:00
Merge pull request #4997 from martinbudden/bfa_compass_update
Avoided compass task wrapper function
This commit is contained in:
commit
ee4edb3da9
3 changed files with 11 additions and 19 deletions
|
@ -157,15 +157,6 @@ static void taskUpdateRxMain(timeUs_t currentTimeUs)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_MAG
|
||||
static void taskUpdateCompass(timeUs_t currentTimeUs)
|
||||
{
|
||||
if (sensors(SENSOR_MAG)) {
|
||||
compassUpdate(currentTimeUs, &compassConfigMutable()->magZero);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_BARO
|
||||
static void taskUpdateBaro(timeUs_t currentTimeUs)
|
||||
{
|
||||
|
@ -463,7 +454,7 @@ cfTask_t cfTasks[TASK_COUNT] = {
|
|||
#ifdef USE_MAG
|
||||
[TASK_COMPASS] = {
|
||||
.taskName = "COMPASS",
|
||||
.taskFunc = taskUpdateCompass,
|
||||
.taskFunc = compassUpdate,
|
||||
.desiredPeriod = TASK_PERIOD_HZ(10), // Compass is updated at 10 Hz
|
||||
.staticPriority = TASK_PRIORITY_LOW,
|
||||
},
|
||||
|
|
|
@ -262,9 +262,9 @@ bool compassInit(void)
|
|||
return true;
|
||||
}
|
||||
|
||||
void compassUpdate(uint32_t currentTime, flightDynamicsTrims_t *magZero)
|
||||
void compassUpdate(timeUs_t currentTimeUs)
|
||||
{
|
||||
static uint32_t tCal = 0;
|
||||
static timeUs_t tCal = 0;
|
||||
static flightDynamicsTrims_t magZeroTempMin;
|
||||
static flightDynamicsTrims_t magZeroTempMax;
|
||||
|
||||
|
@ -274,8 +274,9 @@ void compassUpdate(uint32_t currentTime, flightDynamicsTrims_t *magZero)
|
|||
}
|
||||
alignSensors(mag.magADC, magDev.magAlign);
|
||||
|
||||
flightDynamicsTrims_t *magZero = &compassConfigMutable()->magZero;
|
||||
if (STATE(CALIBRATE_MAG)) {
|
||||
tCal = currentTime;
|
||||
tCal = currentTimeUs;
|
||||
for (int axis = 0; axis < 3; axis++) {
|
||||
magZero->raw[axis] = 0;
|
||||
magZeroTempMin.raw[axis] = mag.magADC[axis];
|
||||
|
@ -291,7 +292,7 @@ void compassUpdate(uint32_t currentTime, flightDynamicsTrims_t *magZero)
|
|||
}
|
||||
|
||||
if (tCal != 0) {
|
||||
if ((currentTime - tCal) < 30000000) { // 30s: you have 30s to turn the multi in all directions
|
||||
if ((currentTimeUs - tCal) < 30000000) { // 30s: you have 30s to turn the multi in all directions
|
||||
LED0_TOGGLE;
|
||||
for (int axis = 0; axis < 3; axis++) {
|
||||
if (mag.magADC[axis] < magZeroTempMin.raw[axis])
|
||||
|
|
|
@ -17,12 +17,13 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "pg/pg.h"
|
||||
|
||||
#include "drivers/io.h"
|
||||
#include "drivers/io_types.h"
|
||||
#include "drivers/sensor.h"
|
||||
#include "common/time.h"
|
||||
#include "pg/pg.h"
|
||||
#include "sensors/sensors.h"
|
||||
|
||||
|
||||
// Type of magnetometer used/detected
|
||||
typedef enum {
|
||||
MAG_DEFAULT = 0,
|
||||
|
@ -56,6 +57,5 @@ typedef struct compassConfig_s {
|
|||
PG_DECLARE(compassConfig_t, compassConfig);
|
||||
|
||||
bool compassInit(void);
|
||||
union flightDynamicsTrims_u;
|
||||
void compassUpdate(uint32_t currentTime, union flightDynamicsTrims_u *magZero);
|
||||
void compassUpdate(timeUs_t currentTime);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue