Subversion Repositories NaviCtrl

Rev

Rev 474 | Rev 482 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 474 Rev 480
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + www.MikroKopter.com
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
// + Software Nutzungsbedingungen (english version: see below)
7
// + Software Nutzungsbedingungen (english version: see below)
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
22
// + des Mitverschuldens offen.
22
// + des Mitverschuldens offen.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Software LICENSING TERMS
32
// + Software LICENSING TERMS
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
37
// + The Software may only be used with the Licensor's products.
37
// + The Software may only be used with the Licensor's products.
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
40
// + agreement shall be the property of the Licensor.
40
// + agreement shall be the property of the Licensor.
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
43
// + The customer shall be responsible for taking reasonable precautions
43
// + The customer shall be responsible for taking reasonable precautions
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
53
// + #### END OF LICENSING TERMS ####
53
// + #### END OF LICENSING TERMS ####
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
#include "91x_lib.h"
56
#include "91x_lib.h"
57
#include "compass.h"
57
#include "compass.h"
58
#include "mk3mag.h"
58
#include "mk3mag.h"
59
#include "ncmag.h"
59
#include "ncmag.h"
60
#include "spi_slave.h"
60
#include "spi_slave.h"
61
#include "mymath.h"
61
#include "mymath.h"
62
#include "uart1.h"
62
#include "uart1.h"
63
#include "fifo.h"
63
#include "fifo.h"
64
#include "led.h"
64
#include "led.h"
65
#include "main.h"
65
#include "main.h"
66
 
66
 
67
u8 CompassCalStateQueue[10];
67
u8 CompassCalStateQueue[10];
68
fifo_t CompassCalcStateFiFo;
68
fifo_t CompassCalcStateFiFo;
69
 
69
 
70
volatile s16vec_t MagVector;   // is written by mk3mag or ncmag implementation
70
volatile s16vec_t MagVector;   // is written by mk3mag or ncmag implementation
71
volatile s16 Compass_Heading;  // is written by mk3mag or ncmag implementation
71
volatile s16 Compass_Heading;  // is written by mk3mag or ncmag implementation
72
volatile u8  Compass_CalState; // is written by mk3mag or ncmag implementation
72
volatile u8  Compass_CalState; // is written by mk3mag or ncmag implementation
73
s16 Hx = 0, Hy = 0;
73
s16 Hx = 0, Hy = 0;
74
s32 EarthMagneticField = 100;
74
s32 EarthMagneticField = 100;
75
s32 EarthMagneticFieldFiltered = 100;
75
s32 EarthMagneticFieldFiltered = 100;
76
s32 EarthMagneticInclination = 0;
76
s32 EarthMagneticInclination = 0;
77
s32 EarthMagneticInclinationFiltered = 0;
77
s32 EarthMagneticInclinationFiltered = 0;
78
s32 EarthMagneticInclinationTheoretic = 0;
78
s32 EarthMagneticInclinationTheoretic = 0;
79
u8  ErrorDisturbedEarthMagnetField = 0;
79
u8  ErrorDisturbedEarthMagnetField = 0;
80
s16 EarthMagneticStrengthTheoretic = 0; // in mT (50 in Germany - 22 in Brazil)
80
s16 EarthMagneticStrengthTheoretic = 0; // in mT (50 in Germany - 22 in Brazil)
81
 
81
 
82
#define COMPASS_NONE    0
82
#define COMPASS_NONE    0
83
#define COMPASS_MK3MAG  1
83
#define COMPASS_MK3MAG  1
84
#define COMPASS_NCMAG   2
84
#define COMPASS_NCMAG   2
85
u8 Compass_Device = COMPASS_NONE;
85
u8 Compass_Device = COMPASS_NONE;
86
 
86
 
87
void Compass_Init(void)
87
void Compass_Init(void)
88
{
88
{
89
        switch(Compass_Device)
89
        switch(Compass_Device)
90
        {
90
        {
91
                case COMPASS_NONE:
91
                case COMPASS_NONE:
92
                        UART1_PutString("\r\n Looking for compass");
92
                        UART1_PutString("\r\n Looking for compass");
93
                        if(     MK3MAG_Init() ) Compass_Device = COMPASS_MK3MAG;
93
                        if(     MK3MAG_Init() ) Compass_Device = COMPASS_MK3MAG;
94
                        else if( NCMAG_Init() ) Compass_Device = COMPASS_NCMAG;
94
                        else if( NCMAG_Init() ) Compass_Device = COMPASS_NCMAG;
95
 
95
 
96
/*                      if(Version_HW > 11)
96
/*                      if(Version_HW > 11)
97
                        {
97
                        {
98
                                if(      NCMAG_Init() ) Compass_Device = COMPASS_NCMAG;
98
                                if(      NCMAG_Init() ) Compass_Device = COMPASS_NCMAG;
99
                                else if( MK3MAG_Init()) Compass_Device = COMPASS_MK3MAG;
99
                                else if( MK3MAG_Init()) Compass_Device = COMPASS_MK3MAG;
100
                        }
100
                        }
101
                        else
101
                        else
102
                        {
102
                        {
103
                                if(     MK3MAG_Init() ) Compass_Device = COMPASS_MK3MAG;
103
                                if(     MK3MAG_Init() ) Compass_Device = COMPASS_MK3MAG;
104
                                else if( NCMAG_Init() ) Compass_Device = COMPASS_NCMAG;
104
                                else if( NCMAG_Init() ) Compass_Device = COMPASS_NCMAG;
105
                        }
105
                        }
106
*/
106
*/
107
                        break;
107
                        break;
108
 
108
 
109
                case COMPASS_NCMAG:
109
                case COMPASS_NCMAG:
110
                        UART1_PutString("\r\n Re-Init compass");
110
                        UART1_PutString("\r\n Re-Init compass");
111
                        if( NCMAG_Init() )      Compass_Device = COMPASS_NCMAG;
111
                        if( NCMAG_Init() )      Compass_Device = COMPASS_NCMAG;
112
                        else                            Compass_Device = COMPASS_NONE;
112
                        else                            Compass_Device = COMPASS_NONE;
113
                        break;
113
                        break;
114
 
114
 
115
                case COMPASS_MK3MAG:
115
                case COMPASS_MK3MAG:
116
                default:
116
                default:
117
                        // nothing to do
117
                        // nothing to do
118
                        break;
118
                        break;
119
 
119
 
120
        }
120
        }
121
        fifo_init(&CompassCalcStateFiFo, CompassCalStateQueue, sizeof(CompassCalStateQueue), NO_ITLine, NO_ITLine);
121
        fifo_init(&CompassCalcStateFiFo, CompassCalStateQueue, sizeof(CompassCalStateQueue), NO_ITLine, NO_ITLine);
122
 
122
 
123
        if(Compass_Device == COMPASS_MK3MAG) UART_VersionInfo.Flags |= NC_VERSION_FLAG_MK3MAG_PRESENT; else UART_VersionInfo.Flags &= ~NC_VERSION_FLAG_MK3MAG_PRESENT;
123
        if(Compass_Device == COMPASS_MK3MAG) UART_VersionInfo.Flags |= NC_VERSION_FLAG_MK3MAG_PRESENT; else UART_VersionInfo.Flags &= ~NC_VERSION_FLAG_MK3MAG_PRESENT;
124
 
124
 
125
}
125
}
126
 
126
 
127
 
127
 
128
void Compass_CalcHeading(void)
128
void Compass_CalcHeading(void)
129
{
129
{
130
        if((UART_VersionInfo.HardwareError[0] & NC_ERROR0_SPI_RX) || Compass_CalState)
130
        if((UART_VersionInfo.HardwareError[0] & NC_ERROR0_SPI_RX) || Compass_CalState)
131
        {
131
        {
132
                Compass_Heading = -1;
132
                Compass_Heading = -1;
133
        }
133
        }
134
        else // fc attitude is avialable and no compass calibration active
134
        else // fc attitude is avialable and no compass calibration active
135
        {
135
        {
136
                // calculate attitude correction
136
                // calculate attitude correction
137
                // a float implementation takes too long
137
                // a float implementation takes too long
138
                s16 tmp;
138
                s16 tmp;
139
                s32 sinnick, cosnick, sinroll, cosroll;
139
                s32 sinnick, cosnick, sinroll, cosroll;
140
                tmp = FromFlightCtrl.AngleNick/10; // in deg
140
                tmp = FromFlightCtrl.AngleNick/10; // in deg
141
                sinnick = (s32)c_sin_8192(tmp);
141
                sinnick = (s32)c_sin_8192(tmp);
142
                cosnick = (s32)c_cos_8192(tmp);
142
                cosnick = (s32)c_cos_8192(tmp);
143
                tmp = FromFlightCtrl.AngleRoll/10; // in deg
143
                tmp = FromFlightCtrl.AngleRoll/10; // in deg
144
                sinroll = (s32)c_sin_8192(tmp);
144
                sinroll = (s32)c_sin_8192(tmp);
145
                cosroll = (s32)c_cos_8192(tmp);
145
                cosroll = (s32)c_cos_8192(tmp);
146
                // tbd. compensation signs and oriantation has to be fixed
146
                // tbd. compensation signs and oriantation has to be fixed
147
                Hx = (s16)((MagVector.Y * cosnick + MagVector.Z * sinnick)/8192L);
147
                Hx = (s16)((MagVector.Y * cosnick + MagVector.Z * sinnick)/8192L);
148
                Hy = (s16)((MagVector.X * cosroll - MagVector.Z * sinroll)/8192L);
148
                Hy = (s16)((MagVector.X * cosroll - MagVector.Z * sinroll)/8192L);
149
                // calculate heading
149
                // calculate heading
150
                tmp = (s16)(c_atan2_546(Hy, Hx)/546L);
150
                tmp = (s16)(c_atan2_546(Hy, Hx)/546L);
151
                if (tmp > 0) tmp = 360 - tmp;
151
                if (tmp > 0) tmp = 360 - tmp;
152
                else tmp = -tmp;
152
                else tmp = -tmp;
153
                Compass_Heading = tmp;
153
                Compass_Heading = tmp;
154
        }
154
        }
155
}
155
}
156
 
156
 
157
 
157
 
158
void Compass_Update(void)
158
void Compass_Update(void)
159
{
159
{
160
static s16vec_t old;  
160
static s16vec_t old;  
161
static u32 check_value_counter = 0;
161
static u32 check_value_counter = 0;
162
        // check for new cal state
162
        // check for new cal state
163
        Compass_UpdateCalState();
163
        Compass_UpdateCalState();
164
        if(Compass_CalState) FC_is_Calibrated = 0;
164
        if(Compass_CalState) FC_is_Calibrated = 0;
165
        // initiate new compass communication
165
        // initiate new compass communication
166
        switch(Compass_Device)
166
        switch(Compass_Device)
167
        {
167
        {
168
                case COMPASS_MK3MAG:
168
                case COMPASS_MK3MAG:
169
                        MK3MAG_Update();
169
                        MK3MAG_Update();
170
                        DebugOut.Analog[24] = MagVector.X;
170
                        DebugOut.Analog[24] = MagVector.X;
171
                        DebugOut.Analog[25] = MagVector.Y;
171
                        DebugOut.Analog[25] = MagVector.Y;
172
                        DebugOut.Analog[26] = MagVector.Z;
172
                        DebugOut.Analog[26] = MagVector.Z;
173
                        break;
173
                        break;
174
                case COMPASS_NCMAG:
174
                case COMPASS_NCMAG:
175
                        if(check_value_counter == 2000)
175
                        if(check_value_counter == 2000)
176
                         {
176
                         {
177
                          UART1_PutString("\n\r Init Mag.-Sensor");
177
                          UART1_PutString("\n\r Init Mag.-Sensor");
178
                          InitNC_MagnetSensor(); // 2 seconds no change of the compass value
178
                          InitNC_MagnetSensor(); // 2 seconds no change of the compass value
179
                         }
179
                         }
180
                        else NCMAG_Update();
180
                        else NCMAG_Update(0);
181
                        DebugOut.Analog[24] = MagRawVector.X;
181
                        DebugOut.Analog[24] = MagRawVector.X;
182
                        DebugOut.Analog[25] = MagRawVector.Y;
182
                        DebugOut.Analog[25] = MagRawVector.Y;
183
                        DebugOut.Analog[26] = MagRawVector.Z;
183
                        DebugOut.Analog[26] = MagRawVector.Z;
184
                default:
184
                default:
185
                        break;
185
                        break;
186
        }
186
        }
187
    if(!((old.X == MagVector.X) || (old.Y == MagVector.Y) || (old.Z == MagVector.Z))) check_value_counter = 0; // Values are normally changing
187
    if(!((old.X == MagVector.X) || (old.Y == MagVector.Y) || (old.Z == MagVector.Z))) check_value_counter = 0; // Values are normally changing
188
 
188
 
189
        if(check_value_counter > 5000)
189
        if(check_value_counter > 5000)
190
         {
190
         {
191
          Compass_Heading = -1; // values didn't change for 5 seconds -> probably a compass-fault
191
          Compass_Heading = -1; // values didn't change for 5 seconds -> probably a compass-fault
192
         }
192
         }
193
         else check_value_counter++;
193
         else check_value_counter++;
194
 
194
 
195
        old.X = MagVector.X;
195
        old.X = MagVector.X;
196
        old.Y = MagVector.Y;
196
        old.Y = MagVector.Y;
197
        old.Z = MagVector.Z;
197
        old.Z = MagVector.Z;
198
}
198
}
199
 
199
 
200
// put cal state into fifo
200
// put cal state into fifo
201
void Compass_SetCalState(u8 CalState)
201
void Compass_SetCalState(u8 CalState)
202
{
202
{
203
        fifo_put(&CompassCalcStateFiFo, CalState);
203
        fifo_put(&CompassCalcStateFiFo, CalState);
204
}
204
}
205
 
205
 
206
// get cal state from fifo
206
// get cal state from fifo
207
void Compass_UpdateCalState()
207
void Compass_UpdateCalState()
208
{
208
{
209
        fifo_get(&CompassCalcStateFiFo, (u8*)&Compass_CalState);
209
        fifo_get(&CompassCalcStateFiFo, (u8*)&Compass_CalState);
210
}
210
}
211
 
211
 
212
 
212