mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 17:55:30 +03:00
Remove sensor_compass.c's dependency on mw.h/board.h.
Also changed type of magZero from int16_t[3] to int16_flightDynamicsTrims_t.
This commit is contained in:
parent
1464b7398a
commit
e963496263
4 changed files with 37 additions and 22 deletions
|
@ -37,7 +37,7 @@ typedef struct master_t {
|
||||||
uint8_t moron_threshold; // people keep forgetting that moving model while init results in wrong gyro offsets. and then they never reset gyro. so this is now on by default.
|
uint8_t moron_threshold; // people keep forgetting that moving model while init results in wrong gyro offsets. and then they never reset gyro. so this is now on by default.
|
||||||
uint16_t max_angle_inclination; // max inclination allowed in angle (level) mode. default 500 (50 degrees).
|
uint16_t max_angle_inclination; // max inclination allowed in angle (level) mode. default 500 (50 degrees).
|
||||||
int16_flightDynamicsTrims_t accZero;
|
int16_flightDynamicsTrims_t accZero;
|
||||||
int16_t magZero[3];
|
int16_flightDynamicsTrims_t magZero;
|
||||||
|
|
||||||
batteryConfig_t batteryConfig;
|
batteryConfig_t batteryConfig;
|
||||||
|
|
||||||
|
|
2
src/mw.c
2
src/mw.c
|
@ -483,7 +483,7 @@ void loop(void)
|
||||||
case 0:
|
case 0:
|
||||||
taskOrder++;
|
taskOrder++;
|
||||||
#ifdef MAG
|
#ifdef MAG
|
||||||
if (sensors(SENSOR_MAG) && compassGetADC())
|
if (sensors(SENSOR_MAG) && compassGetADC(&masterConfig.magZero))
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 1:
|
case 1:
|
||||||
|
|
|
@ -1,8 +1,24 @@
|
||||||
#include "board.h"
|
#include <stdbool.h>
|
||||||
#include "mw.h"
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
#include "common/axis.h"
|
#include "common/axis.h"
|
||||||
|
|
||||||
|
#include "drivers/compass_hmc5883l.h"
|
||||||
|
#include "drivers/gpio_common.h"
|
||||||
|
#include "drivers/light_led.h"
|
||||||
|
|
||||||
|
#include "flight_common.h"
|
||||||
|
#include "boardalignment.h"
|
||||||
|
#include "runtime_config.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sensors_common.h"
|
||||||
|
#include "sensors_compass.h"
|
||||||
|
|
||||||
|
extern uint32_t currentTime; // FIXME dependency on global variable, pass it in instead.
|
||||||
|
|
||||||
int16_t magADC[XYZ_AXIS_COUNT];
|
int16_t magADC[XYZ_AXIS_COUNT];
|
||||||
sensor_align_e magAlign = 0;
|
sensor_align_e magAlign = 0;
|
||||||
#ifdef MAG
|
#ifdef MAG
|
||||||
|
@ -17,11 +33,11 @@ void compassInit(void)
|
||||||
magInit = 1;
|
magInit = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int compassGetADC(void)
|
int compassGetADC(int16_flightDynamicsTrims_t *magZero)
|
||||||
{
|
{
|
||||||
static uint32_t t, tCal = 0;
|
static uint32_t t, tCal = 0;
|
||||||
static int16_t magZeroTempMin[3];
|
static int16_flightDynamicsTrims_t magZeroTempMin;
|
||||||
static int16_t magZeroTempMax[3];
|
static int16_flightDynamicsTrims_t magZeroTempMax;
|
||||||
uint32_t axis;
|
uint32_t axis;
|
||||||
|
|
||||||
if ((int32_t)(currentTime - t) < 0)
|
if ((int32_t)(currentTime - t) < 0)
|
||||||
|
@ -35,36 +51,35 @@ int compassGetADC(void)
|
||||||
if (f.CALIBRATE_MAG) {
|
if (f.CALIBRATE_MAG) {
|
||||||
tCal = t;
|
tCal = t;
|
||||||
for (axis = 0; axis < 3; axis++) {
|
for (axis = 0; axis < 3; axis++) {
|
||||||
masterConfig.magZero[axis] = 0;
|
magZero->raw[axis] = 0;
|
||||||
magZeroTempMin[axis] = magADC[axis];
|
magZeroTempMin.raw[axis] = magADC[axis];
|
||||||
magZeroTempMax[axis] = magADC[axis];
|
magZeroTempMax.raw[axis] = magADC[axis];
|
||||||
}
|
}
|
||||||
f.CALIBRATE_MAG = 0;
|
f.CALIBRATE_MAG = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (magInit) { // we apply offset only once mag calibration is done
|
if (magInit) { // we apply offset only once mag calibration is done
|
||||||
magADC[X] -= masterConfig.magZero[X];
|
magADC[X] -= magZero->raw[X];
|
||||||
magADC[Y] -= masterConfig.magZero[Y];
|
magADC[Y] -= magZero->raw[Y];
|
||||||
magADC[Z] -= masterConfig.magZero[Z];
|
magADC[Z] -= magZero->raw[Z];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tCal != 0) {
|
if (tCal != 0) {
|
||||||
if ((t - tCal) < 30000000) { // 30s: you have 30s to turn the multi in all directions
|
if ((t - tCal) < 30000000) { // 30s: you have 30s to turn the multi in all directions
|
||||||
LED0_TOGGLE;
|
LED0_TOGGLE;
|
||||||
for (axis = 0; axis < 3; axis++) {
|
for (axis = 0; axis < 3; axis++) {
|
||||||
if (magADC[axis] < magZeroTempMin[axis])
|
if (magADC[axis] < magZeroTempMin.raw[axis])
|
||||||
magZeroTempMin[axis] = magADC[axis];
|
magZeroTempMin.raw[axis] = magADC[axis];
|
||||||
if (magADC[axis] > magZeroTempMax[axis])
|
if (magADC[axis] > magZeroTempMax.raw[axis])
|
||||||
magZeroTempMax[axis] = magADC[axis];
|
magZeroTempMax.raw[axis] = magADC[axis];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tCal = 0;
|
tCal = 0;
|
||||||
for (axis = 0; axis < 3; axis++) {
|
for (axis = 0; axis < 3; axis++) {
|
||||||
masterConfig.magZero[axis] = (magZeroTempMin[axis] + magZeroTempMax[axis]) / 2; // Calculate offsets
|
magZero->raw[axis] = (magZeroTempMin.raw[axis] + magZeroTempMax.raw[axis]) / 2; // Calculate offsets
|
||||||
}
|
}
|
||||||
copyCurrentProfileToProfileSlot(masterConfig.current_profile_index);
|
|
||||||
writeEEPROM();
|
saveAndReloadCurrentProfileToCurrentProfileSlot();
|
||||||
readEEPROMAndNotify();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#ifdef MAG
|
#ifdef MAG
|
||||||
void compassInit(void);
|
void compassInit(void);
|
||||||
int compassGetADC(void);
|
int compassGetADC(int16_flightDynamicsTrims_t *magZero);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int16_t magADC[XYZ_AXIS_COUNT];
|
extern int16_t magADC[XYZ_AXIS_COUNT];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue