Subversion Repositories FlightCtrl

Rev

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

Rev 1598 Rev 1603
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + Copyright (c) Holger Buss, Ingo Busker
2
// + Copyright (c) Holger Buss, Ingo Busker
3
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
3
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
4
// + www.MikroKopter.com
4
// + www.MikroKopter.com
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
7
// + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist.
7
// + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist.
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
11
// + Verkauf von Luftbildaufnahmen, usw.
11
// + Verkauf von Luftbildaufnahmen, usw.
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
17
// + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
17
// + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
18
// + eindeutig als Ursprung verlinkt und genannt werden
18
// + eindeutig als Ursprung verlinkt und genannt werden
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
21
// + Benutzung auf eigene Gefahr
21
// + Benutzung auf eigene Gefahr
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
24
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
25
// + mit unserer Zustimmung zulässig
25
// + mit unserer Zustimmung zulässig
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
30
// + this list of conditions and the following disclaimer.
30
// + this list of conditions and the following disclaimer.
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
32
// +     from this software without specific prior written permission.
32
// +     from this software without specific prior written permission.
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
34
// +     for non-commercial use (directly or indirectly)
34
// +     for non-commercial use (directly or indirectly)
35
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
35
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
36
// +     with our written permission
36
// +     with our written permission
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
38
// +     clearly linked as origin
38
// +     clearly linked as origin
39
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
39
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50
// +  POSSIBILITY OF SUCH DAMAGE.
50
// +  POSSIBILITY OF SUCH DAMAGE.
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
52
#include "main.h"
52
#include "main.h"
53
 
53
 
54
 
54
 
55
unsigned char PlatinenVersion = 10;
55
unsigned char PlatinenVersion = 10;
56
unsigned char SendVersionToNavi = 1;
56
unsigned char SendVersionToNavi = 1;
57
unsigned char BattLowVoltageWarning = 94;
57
unsigned char BattLowVoltageWarning = 94;
58
unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0;
58
unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0;
59
unsigned int FlugSekunden = 0;
59
unsigned int FlugSekunden = 0;
60
pVoidFnct_pVoidFnctChar_const_fmt _printf_P;
60
pVoidFnct_pVoidFnctChar_const_fmt _printf_P;
61
 
61
 
62
// -- Parametersatz aus EEPROM lesen ---
62
// -- Parametersatz aus EEPROM lesen ---
63
// number [1..5]
63
// number [1..5]
64
void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
64
void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
65
{
65
{
66
   if((number > 5)||(number < 1)) number = 3;
66
   if((number > 5)||(number < 1)) number = 3;
67
   eeprom_read_block(buffer, (void*)(EEPROM_ADR_PARAM_BEGIN + length * (number - 1)), length);
67
   eeprom_read_block(buffer, (void*)(EEPROM_ADR_PARAM_BEGIN + length * (number - 1)), length);
68
   LED_Init();
68
   LED_Init();
69
}
69
}
70
 
70
 
71
// -- Parametersatz ins EEPROM schreiben ---
71
// -- Parametersatz ins EEPROM schreiben ---
72
// number [1..5]
72
// number [1..5]
73
void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
73
void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
74
{
74
{
75
   if(number > 5) number = 5;
75
   if(number > 5) number = 5;
76
   if(number < 1) return;
76
   if(number < 1) return;
77
   eeprom_write_block(buffer, (void*)(EEPROM_ADR_PARAM_BEGIN + length * (number - 1)), length);
77
   eeprom_write_block(buffer, (void*)(EEPROM_ADR_PARAM_BEGIN + length * (number - 1)), length);
78
   eeprom_write_byte((unsigned char*)(EEPROM_ADR_PARAM_LENGTH), length); // Länge der Datensätze merken
78
   eeprom_write_byte((unsigned char*)(EEPROM_ADR_PARAM_LENGTH), length); // Länge der Datensätze merken
79
   eeprom_write_block(buffer, (void*)(EEPROM_ADR_CHANNELS), 12); // 12 Kanäle merken
79
   eeprom_write_block(buffer, (void*)(EEPROM_ADR_CHANNELS), 12); // 12 Kanäle merken
80
   SetActiveParamSetNumber(number);
80
   SetActiveParamSetNumber(number);
81
   LED_Init();
81
   LED_Init();
82
}
82
}
83
 
83
 
84
unsigned char GetActiveParamSetNumber(void)
84
unsigned char GetActiveParamSetNumber(void)
85
{
85
{
86
        unsigned char set;
86
        unsigned char set;
87
        set = eeprom_read_byte((unsigned char*)(EEPROM_ADR_ACTIVE_SET));
87
        set = eeprom_read_byte((unsigned char*)(EEPROM_ADR_ACTIVE_SET));
88
        if((set > 5) || (set < 1))
88
        if((set > 5) || (set < 1))
89
        {
89
        {
90
                set = 3;
90
                set = 3;
91
                SetActiveParamSetNumber(set);                           // diesen Parametersatz als aktuell merken
91
                SetActiveParamSetNumber(set);                           // diesen Parametersatz als aktuell merken
92
        }
92
        }
93
        return(set);
93
        return(set);
94
}
94
}
95
 
95
 
96
void SetActiveParamSetNumber(unsigned char number)
96
void SetActiveParamSetNumber(unsigned char number)
97
{
97
{
98
        if(number > 5) number = 5;
98
        if(number > 5) number = 5;
99
        if(number < 1) return;
99
        if(number < 1) return;
100
        eeprom_write_byte((unsigned char*)(EEPROM_ADR_ACTIVE_SET), number);                             // diesen Parametersatz als aktuell merken
100
        eeprom_write_byte((unsigned char*)(EEPROM_ADR_ACTIVE_SET), number);                             // diesen Parametersatz als aktuell merken
101
}
101
}
102
 
102
 
103
 
103
 
104
void CalMk3Mag(void)
104
void CalMk3Mag(void)
105
{
105
{
106
 static unsigned char stick = 1;
106
 static unsigned char stick = 1;
107
 
107
 
108
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
108
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
109
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
109
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
110
  {
110
  {
111
   stick = 1;
111
   stick = 1;
112
   WinkelOut.CalcState++;
112
   WinkelOut.CalcState++;
113
   if(WinkelOut.CalcState > 4)
113
   if(WinkelOut.CalcState > 4)
114
    {
114
    {
115
//     WinkelOut.CalcState = 0; // in Uart.c
115
//     WinkelOut.CalcState = 0; // in Uart.c
116
     beeptime = 1000;
116
     beeptime = 1000;
117
    }
117
    }
118
   else Piep(WinkelOut.CalcState,150);
118
   else Piep(WinkelOut.CalcState,150);
119
  }
119
  }
120
  DebugOut.Analog[19] = WinkelOut.CalcState;
120
  DebugOut.Analog[19] = WinkelOut.CalcState;
121
}
121
}
122
 
122
 
123
 
123
 
124
 
124
 
125
void LipoDetection(unsigned char print)
125
void LipoDetection(unsigned char print)
126
{
126
{
127
   unsigned int timer;
127
   unsigned int timer;
128
   if(print) printf("\n\rBatt:");
128
   if(print) printf("\n\rBatt:");
129
   if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung
129
   if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung
130
    {
130
    {
131
         timer = SetDelay(500);
131
         timer = SetDelay(500);
132
         if(print) while (!CheckDelay(timer));
132
         if(print) while (!CheckDelay(timer));
133
         if(UBat < 130)
133
         if(UBat < 130)
134
          {
134
          {
135
           BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung;
135
           BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung;
136
           if(print)
136
           if(print)
137
            {
137
            {
138
                 Piep(3,200);
138
                 Piep(3,200);
139
             printf(" 3 Cells  ");
139
             printf(" 3 Cells  ");
140
                }
140
                }
141
          }
141
          }
142
         else
142
         else
143
          {
143
          {
144
           BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung;
144
           BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung;
145
           if(print)
145
           if(print)
146
            {
146
            {
147
                 Piep(4,200);
147
                 Piep(4,200);
148
             printf(" 4 Cells  ");
148
             printf(" 4 Cells  ");
149
                }
149
                }
150
          }
150
          }
151
    }
151
    }
152
    else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
152
    else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
153
//      if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93;
153
//      if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93;
154
   if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
154
   if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
155
}
155
}
156
 
156
 
157
//############################################################################
157
//############################################################################
158
//Hauptprogramm
158
//Hauptprogramm
159
int main (void)
159
int main (void)
160
//############################################################################
160
//############################################################################
161
{
161
{
162
        unsigned int timer,i,timer2 = 0, timerPolling;
162
        unsigned int timer,i,timer2 = 0, timerPolling;
163
        unsigned char RequiredMotors = 0;
163
        unsigned char RequiredMotors = 0;
164
 
164
 
165
    DDRB  = 0x00;
165
    DDRB  = 0x00;
166
    PORTB = 0x00;
166
    PORTB = 0x00;
167
    for(timer = 0; timer < 1000; timer++); // verzögern
167
    for(timer = 0; timer < 1000; timer++); // verzögern
168
    if(PINB & 0x01)
168
    if(PINB & 0x01)
169
     {
169
     {
170
      if(PINB & 0x02) PlatinenVersion = 13;
170
      if(PINB & 0x02) PlatinenVersion = 13;
171
       else           PlatinenVersion = 11;
171
       else           PlatinenVersion = 11;
172
     }
172
     }
173
    else
173
    else
174
     {
174
     {
175
      if(PINB & 0x02) PlatinenVersion = 20;
175
      if(PINB & 0x02) PlatinenVersion = 20;
176
       else           PlatinenVersion = 10;
176
       else           PlatinenVersion = 10;
177
     }
177
     }
178
 
178
 
179
    DDRC  = 0x81; // SCL
179
    DDRC  = 0x81; // SCL
180
    DDRC  |=0x40; // HEF4017 Reset
180
    DDRC  |=0x40; // HEF4017 Reset
181
    PORTC = 0xff; // Pullup SDA
181
    PORTC = 0xff; // Pullup SDA
182
    DDRB  = 0x1B; // LEDs und Druckoffset
182
    DDRB  = 0x1B; // LEDs und Druckoffset
183
    PORTB = 0x01; // LED_Rot
183
    PORTB = 0x01; // LED_Rot
184
    DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
184
    DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
185
        PORTD = 0x47; // LED
185
        PORTD = 0x47; // LED
186
    HEF4017R_ON;
186
    HEF4017R_ON;
187
    MCUSR &=~(1<<WDRF);
187
    MCUSR &=~(1<<WDRF);
188
    WDTCSR |= (1<<WDCE)|(1<<WDE);
188
    WDTCSR |= (1<<WDCE)|(1<<WDE);
189
    WDTCSR = 0;
189
    WDTCSR = 0;
190
 
190
 
191
    beeptime = 2000;
191
    beeptime = 2000;
192
        StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0;
192
        StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0;
193
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
193
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
194
    ROT_OFF;
194
    ROT_OFF;
195
 
195
 
196
    Timer_Init();
196
    Timer_Init();
197
        TIMER2_Init();
197
        TIMER2_Init();
198
        UART_Init();
198
        UART_Init();
199
    rc_sum_init();
199
    rc_sum_init();
200
        ADC_Init();
200
        ADC_Init();
201
        i2c_init();
201
        i2c_init();
202
        SPI_MasterInit();
202
        SPI_MasterInit();
203
        Capacity_Init();
203
        Capacity_Init();
204
        LIBFC_Init();
204
        LIBFC_Init();
205
        GRN_ON;
205
        GRN_ON;
206
    sei();
206
    sei();
207
 
207
 
208
        ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 13); // read only the first bytes
208
        ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 13); // read only the first bytes
209
 
209
 
210
 
210
 
211
    if((eeprom_read_byte((unsigned char*)(EEPROM_ADR_MIXER_TABLE)) == MIXER_REVISION) && // Check Revision in the first Byte
211
    if((eeprom_read_byte((unsigned char*)(EEPROM_ADR_MIXER_TABLE)) == MIXER_REVISION) && // Check Revision in the first Byte
212
       (eeprom_read_byte((unsigned char*)(EEPROM_ADR_VALID)) != 0xff))                   // Settings reset via Koptertool
212
       (eeprom_read_byte((unsigned char*)(EEPROM_ADR_VALID)) != 0xff))                   // Settings reset via Koptertool
213
        {
213
        {
214
     unsigned char i;
214
     unsigned char i;
215
     eeprom_read_block(&Mixer, (unsigned char*)(EEPROM_ADR_MIXER_TABLE), sizeof(Mixer));
215
     eeprom_read_block(&Mixer, (unsigned char*)(EEPROM_ADR_MIXER_TABLE), sizeof(Mixer));
216
     for(i=0; i<16;i++) { if(Mixer.Motor[i][0] > 0) RequiredMotors++;}
216
     for(i=0; i<16;i++) { if(Mixer.Motor[i][0] > 0) RequiredMotors++;}
217
        }
217
        }
218
        else // default
218
        else // default
219
        {
219
        {
220
     unsigned char i;
220
     unsigned char i;
221
         printf("\n\rGenerating default Mixer Table");
221
         printf("\n\rGenerating default Mixer Table");
222
         for(i=0; i<16;i++) { Mixer.Motor[i][0] = 0;Mixer.Motor[i][1] = 0;Mixer.Motor[i][2] = 0;Mixer.Motor[i][3] = 0;};
222
         for(i=0; i<16;i++) { Mixer.Motor[i][0] = 0;Mixer.Motor[i][1] = 0;Mixer.Motor[i][2] = 0;Mixer.Motor[i][3] = 0;};
223
     // default = Quadro
223
     // default = Quadro
224
     Mixer.Motor[0][0] = 64; Mixer.Motor[0][1] = +64; Mixer.Motor[0][2] =   0; Mixer.Motor[0][3] = +64;
224
     Mixer.Motor[0][0] = 64; Mixer.Motor[0][1] = +64; Mixer.Motor[0][2] =   0; Mixer.Motor[0][3] = +64;
225
     Mixer.Motor[1][0] = 64; Mixer.Motor[1][1] = -64; Mixer.Motor[1][2] =   0; Mixer.Motor[1][3] = +64;
225
     Mixer.Motor[1][0] = 64; Mixer.Motor[1][1] = -64; Mixer.Motor[1][2] =   0; Mixer.Motor[1][3] = +64;
226
     Mixer.Motor[2][0] = 64; Mixer.Motor[2][1] =   0; Mixer.Motor[2][2] = -64; Mixer.Motor[2][3] = -64;
226
     Mixer.Motor[2][0] = 64; Mixer.Motor[2][1] =   0; Mixer.Motor[2][2] = -64; Mixer.Motor[2][3] = -64;
227
     Mixer.Motor[3][0] = 64; Mixer.Motor[3][1] =   0; Mixer.Motor[3][2] = +64; Mixer.Motor[3][3] = -64;
227
     Mixer.Motor[3][0] = 64; Mixer.Motor[3][1] =   0; Mixer.Motor[3][2] = +64; Mixer.Motor[3][3] = -64;
228
         Mixer.Revision = MIXER_REVISION;
228
         Mixer.Revision = MIXER_REVISION;
229
     memcpy(Mixer.Name, "Quadro\0", 11);
229
     memcpy(Mixer.Name, "Quadro\0", 11);
230
     eeprom_write_block(&Mixer, (void*)(EEPROM_ADR_MIXER_TABLE), sizeof(Mixer));
230
     eeprom_write_block(&Mixer, (void*)(EEPROM_ADR_MIXER_TABLE), sizeof(Mixer));
231
    }
231
    }
232
    printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors);
232
    printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors);
233
 
233
 
234
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
234
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
235
// + Check connected BL-Ctrls
235
// + Check connected BL-Ctrls
236
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
236
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
237
    motorread = 0;   UpdateMotor = 0;   SendMotorData(); while(!UpdateMotor); motorread = 0;  // read the first I2C-Data
237
    motorread = 0;   UpdateMotor = 0;   SendMotorData(); while(!UpdateMotor); motorread = 0;  // read the first I2C-Data
238
        printf("\n\rFound BL-Ctrl: ");
238
        printf("\n\rFound BL-Ctrl: ");
239
    timer = SetDelay(4000);
239
    timer = SetDelay(4000);
240
 
240
 
241
        for(i=0; i < MAX_MOTORS; i++)
241
        for(i=0; i < MAX_MOTORS; i++)
242
         {
242
         {
243
          UpdateMotor = 0;
243
          UpdateMotor = 0;
244
      SendMotorData();
244
      SendMotorData();
245
          while(!UpdateMotor);
245
          while(!UpdateMotor);
246
      if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up
246
      if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up
247
        {
247
        {
248
             while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);};
248
             while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);};
249
                }
249
                }
250
          if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) printf("%d ",i+1);
250
          if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) printf("%d ",i+1);
251
     }
251
     }
252
        for(i=0; i < MAX_MOTORS; i++)
252
        for(i=0; i < MAX_MOTORS; i++)
253
         {
253
         {
254
          if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
254
          if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
255
           {
255
           {
256
            printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
256
            printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
257
                ServoActive = 1; // just in case the FC would be used as camera-stabilizer
257
                ServoActive = 1; // just in case the FC would be used as camera-stabilizer
258
           }
258
           }
259
          Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
259
          Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
260
     }
260
     }
261
        printf("\n\r===================================");
261
        printf("\n\r===================================");
262
    SendMotorData();
262
    SendMotorData();
263
//printf("\n size: %u",STRUCT_PARAM_LAENGE);
263
//printf("\n size: %u",STRUCT_PARAM_LAENGE);
264
 
264
 
265
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
265
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
266
// + Check Settings
266
// + Check Settings
267
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
267
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
268
    if(eeprom_read_byte((unsigned char*)(EEPROM_ADR_VALID)) != EE_DATENREVISION)
268
    if(eeprom_read_byte((unsigned char*)(EEPROM_ADR_VALID)) != EE_DATENREVISION)
269
        {
269
        {
270
          DefaultKonstanten1();
270
          DefaultKonstanten1();
271
          printf("\n\rInit. EEPROM");
271
          printf("\n\rInit. EEPROM");
272
          for (unsigned char i=1;i<6;i++)
272
          for (unsigned char i=1;i<6;i++)
273
      {
273
      {
274
       if(i==2) DefaultKonstanten2(); // Kamera
274
       if(i==2) DefaultKonstanten2(); // Kamera
275
       if(i==3) DefaultKonstanten3(); // Beginner
275
       if(i==3) DefaultKonstanten3(); // Beginner
276
       if(i>3)  DefaultKonstanten2(); // Kamera
276
       if(i>3)  DefaultKonstanten2(); // Kamera
277
           if(PlatinenVersion >= 20)
277
           if(PlatinenVersion >= 20)
278
            {
278
            {
279
                 EE_Parameter.Gyro_D = 5;
279
                 EE_Parameter.Gyro_D = 5;
280
                 EE_Parameter.Driftkomp = 0;
280
                 EE_Parameter.Driftkomp = 0;
281
                 EE_Parameter.GyroAccFaktor = 27;
281
                 EE_Parameter.GyroAccFaktor = 27;
282
         EE_Parameter.WinkelUmschlagNick = 78;
282
         EE_Parameter.WinkelUmschlagNick = 78;
283
         EE_Parameter.WinkelUmschlagRoll = 78;
283
         EE_Parameter.WinkelUmschlagRoll = 78;
284
                }
284
                }
285
    // valid Stick-Settings?
285
    // valid Stick-Settings?
286
           if(eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS)) < 12 && eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+1)) < 12 && eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+2)) < 12 && eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+3)) < 12)
286
           if(eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS)) < 12 && eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+1)) < 12 && eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+2)) < 12 && eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+3)) < 12)
287
            {
287
            {
288
         EE_Parameter.Kanalbelegung[0] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+0));
288
         EE_Parameter.Kanalbelegung[0] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+0));
289
         EE_Parameter.Kanalbelegung[1] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+1));
289
         EE_Parameter.Kanalbelegung[1] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+1));
290
         EE_Parameter.Kanalbelegung[2] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+2));
290
         EE_Parameter.Kanalbelegung[2] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+2));
291
         EE_Parameter.Kanalbelegung[3] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+3));
291
         EE_Parameter.Kanalbelegung[3] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+3));
292
         EE_Parameter.Kanalbelegung[4] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+4));
292
         EE_Parameter.Kanalbelegung[4] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+4));
293
         EE_Parameter.Kanalbelegung[5] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+5));
293
         EE_Parameter.Kanalbelegung[5] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+5));
294
         EE_Parameter.Kanalbelegung[6] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+6));
294
         EE_Parameter.Kanalbelegung[6] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+6));
295
         EE_Parameter.Kanalbelegung[7] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+7));
295
         EE_Parameter.Kanalbelegung[7] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+7));
296
 
296
 
297
         if(eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+8)) < 0xFF)
297
         if(eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+8)) < 0xFF)
298
                  {
298
                  {
299
                   EE_Parameter.Kanalbelegung[K_POTI5] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+8));
299
                   EE_Parameter.Kanalbelegung[K_POTI5] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+8));
300
           EE_Parameter.Kanalbelegung[K_POTI6] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+9));
300
           EE_Parameter.Kanalbelegung[K_POTI6] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+9));
301
           EE_Parameter.Kanalbelegung[K_POTI7] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+10));
301
           EE_Parameter.Kanalbelegung[K_POTI7] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+10));
302
           EE_Parameter.Kanalbelegung[K_POTI8] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+11));
302
           EE_Parameter.Kanalbelegung[K_POTI8] = eeprom_read_byte((unsigned char*)(EEPROM_ADR_CHANNELS+11));
303
                  }
303
                  }
304
                  else
304
                  else
305
                  {
305
                  {
306
           EE_Parameter.Kanalbelegung[K_POTI5] = 9;
306
           EE_Parameter.Kanalbelegung[K_POTI5] = 9;
307
           EE_Parameter.Kanalbelegung[K_POTI6] = 10;
307
           EE_Parameter.Kanalbelegung[K_POTI6] = 10;
308
           EE_Parameter.Kanalbelegung[K_POTI7] = 11;
308
           EE_Parameter.Kanalbelegung[K_POTI7] = 11;
309
           EE_Parameter.Kanalbelegung[K_POTI8] = 12;
309
           EE_Parameter.Kanalbelegung[K_POTI8] = 12;
310
                  }
310
                  }
311
         if(i==1) printf(": Generating Default-Parameter using old Stick Settings");
311
         if(i==1) printf(": Generating Default-Parameter using old Stick Settings");
312
                } else DefaultStickMapping();
312
                } else DefaultStickMapping();
313
       WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
313
       WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
314
      }
314
      }
315
          SetActiveParamSetNumber(3); // default-Setting
315
          SetActiveParamSetNumber(3); // default-Setting
316
          eeprom_write_byte((unsigned char*)(EEPROM_ADR_VALID), EE_DATENREVISION);
316
          eeprom_write_byte((unsigned char*)(EEPROM_ADR_VALID), EE_DATENREVISION);
317
        }
317
        }
318
 
318
 
319
    FlugMinuten = (int)eeprom_read_byte((unsigned char*)(EEPROM_ADR_MINUTES2)) * 256 + (int)eeprom_read_byte((unsigned char*)(EEPROM_ADR_MINUTES2+1));
319
    FlugMinuten = (int)eeprom_read_byte((unsigned char*)(EEPROM_ADR_MINUTES2)) * 256 + (int)eeprom_read_byte((unsigned char*)(EEPROM_ADR_MINUTES2+1));
320
    FlugMinutenGesamt = (int)eeprom_read_byte((unsigned char*)(EEPROM_ADR_MINUTES)) * 256 + (int)eeprom_read_byte((unsigned char*)(EEPROM_ADR_MINUTES+1));
320
    FlugMinutenGesamt = (int)eeprom_read_byte((unsigned char*)(EEPROM_ADR_MINUTES)) * 256 + (int)eeprom_read_byte((unsigned char*)(EEPROM_ADR_MINUTES+1));
321
    if(FlugMinutenGesamt == 0xffff || FlugMinuten == 0xffff)
321
    if(FlugMinutenGesamt == 0xffff || FlugMinuten == 0xffff)
322
         {
322
         {
323
          FlugMinuten = 0;
323
          FlugMinuten = 0;
324
          FlugMinutenGesamt = 0;
324
          FlugMinutenGesamt = 0;
325
         }
325
         }
326
    printf("\n\rFlight-time %u min  Total:%u min" ,FlugMinuten,FlugMinutenGesamt);
326
    printf("\n\rFlight-time %u min  Total:%u min" ,FlugMinuten,FlugMinutenGesamt);
327
 
327
 
328
    if(eeprom_read_byte((unsigned char*)(EEPROM_ADR_ACC_NICK)) > 4)
328
    if(eeprom_read_byte((unsigned char*)(EEPROM_ADR_ACC_NICK)) > 4)
329
     {
329
     {
330
       printf("\n\rACC not calibrated !");
330
       printf("\n\rACC not calibrated !");
331
     }
331
     }
332
 
332
 
333
        ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
333
        ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
334
    printf("\n\rUsing parameterset %d", GetActiveParamSetNumber());
334
    printf("\n\rUsing parameterset %d", GetActiveParamSetNumber());
335
 
335
 
336
 
336
 
337
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
337
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
338
         {
338
         {
339
           printf("\n\rCalibrating pressure sensor..");
339
           printf("\n\rCalibrating pressure sensor..");
340
           timer = SetDelay(1000);
340
           timer = SetDelay(1000);
341
       SucheLuftruckOffset();
341
       SucheLuftruckOffset();
342
           while (!CheckDelay(timer));
342
           while (!CheckDelay(timer));
343
       printf("OK\n\r");
343
       printf("OK\n\r");
344
        }
344
        }
345
 
345
 
346
        SetNeutral();
346
        SetNeutral();
347
 
347
 
348
        ROT_OFF;
348
        ROT_OFF;
349
 
349
 
350
    beeptime = 2000;
350
    beeptime = 2000;
351
    ExternControl.Digital[0] = 0x55;
351
    ExternControl.Digital[0] = 0x55;
352
 
352
 
353
 
353
 
354
        printf("\n\rControl: ");
354
        printf("\n\rControl: ");
355
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
355
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
356
        else printf("Normal (ACC-Mode)");
356
        else printf("Normal (ACC-Mode)");
357
 
357
 
358
    LcdClear();
358
    LcdClear();
359
    I2CTimeout = 5000;
359
    I2CTimeout = 5000;
360
    WinkelOut.Orientation = 1;
360
    WinkelOut.Orientation = 1;
361
    LipoDetection(1);
361
    LipoDetection(1);
362
 
362
 
363
        LIBFC_ReceiverInit();
363
        LIBFC_ReceiverInit();
364
 
364
 
365
        printf("\n\r===================================\n\r");
365
        printf("\n\r===================================\n\r");
366
//SpektrumBinding();
366
//SpektrumBinding();
367
    timer = SetDelay(2000);
367
    timer = SetDelay(2000);
368
        timerPolling = SetDelay(250);
368
        timerPolling = SetDelay(250);
369
 
369
 
370
        while (1)
370
        while (1)
371
        {
371
        {
372
 
372
 
373
        if(CheckDelay(timerPolling))
373
        if(CheckDelay(timerPolling))
374
        {
374
        {
375
          timerPolling = SetDelay(100);
375
          timerPolling = SetDelay(100);
376
          LIBFC_Polling();
376
          LIBFC_Polling();
377
        }
377
        }
378
 
378
 
379
        if(UpdateMotor && AdReady)      // ReglerIntervall
379
        if(UpdateMotor && AdReady)      // ReglerIntervall
380
            {
380
            {
381
                    UpdateMotor=0;
381
                    UpdateMotor=0;
382
            if(WinkelOut.CalcState) CalMk3Mag();
382
            if(WinkelOut.CalcState) CalMk3Mag();
383
            else MotorRegler();
383
            else MotorRegler();
384
            SendMotorData();
384
            SendMotorData();
385
            ROT_OFF;
385
            ROT_OFF;
386
            if(SenderOkay)  SenderOkay--;
386
            if(SenderOkay)  SenderOkay--;
-
 
387
                        else
-
 
388
                        {
387
                        else TIMSK1 |= _BV(ICIE1); // enable PPM-Input
389
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
-
 
390
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
-
 
391
                        }
388
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
392
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
389
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
393
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
390
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
394
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
391
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
395
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
392
 
396
 
393
            if(!--I2CTimeout || MissingMotor)
397
            if(!--I2CTimeout || MissingMotor)
394
                {
398
                {
395
                  if(!I2CTimeout)
399
                  if(!I2CTimeout)
396
                                   {
400
                                   {
397
                                    i2c_reset();
401
                                    i2c_reset();
398
                    I2CTimeout = 5;
402
                    I2CTimeout = 5;
399
                                        DebugOut.Analog[28]++; // I2C-Error
403
                                        DebugOut.Analog[28]++; // I2C-Error
400
                                        FCFlags |= FCFLAG_I2CERR;
404
                                        FCFlags |= FCFLAG_I2CERR;
401
                                   }
405
                                   }
402
                  if((BeepMuster == 0xffff) && MotorenEin)
406
                  if((BeepMuster == 0xffff) && MotorenEin)
403
                   {
407
                   {
404
                    beeptime = 10000;
408
                    beeptime = 10000;
405
                    BeepMuster = 0x0080;
409
                    BeepMuster = 0x0080;
406
                   }
410
                   }
407
                }
411
                }
408
            else
412
            else
409
                {
413
                {
410
                 ROT_OFF;
414
                 ROT_OFF;
411
                                 if(!beeptime) FCFlags &= ~FCFLAG_I2CERR;
415
                                 if(!beeptime) FCFlags &= ~FCFLAG_I2CERR;
412
                }
416
                }
413
            if(SIO_DEBUG && (!UpdateMotor || !MotorenEin))
417
            if(SIO_DEBUG && (!UpdateMotor || !MotorenEin))
414
              {
418
              {
415
               DatenUebertragung();
419
               DatenUebertragung();
416
               BearbeiteRxDaten();
420
               BearbeiteRxDaten();
417
              }
421
              }
418
                        else BearbeiteRxDaten();
422
                        else BearbeiteRxDaten();
419
                        if(CheckDelay(timer))
423
                        if(CheckDelay(timer))
420
                        {
424
                        {
421
                                static unsigned char second;
425
                                static unsigned char second;
422
                                timer += 20; // 20 ms interval
426
                                timer += 20; // 20 ms interval
423
                                if(PcZugriff) PcZugriff--;
427
                                if(PcZugriff) PcZugriff--;
424
                                else
428
                                else
425
                                {
429
                                {
426
                                        ExternControl.Config = 0;
430
                                        ExternControl.Config = 0;
427
                                        ExternStickNick = 0;
431
                                        ExternStickNick = 0;
428
                                        ExternStickRoll = 0;
432
                                        ExternStickRoll = 0;
429
                                        ExternStickGier = 0;
433
                                        ExternStickGier = 0;
430
                                        if(BeepMuster == 0xffff && SenderOkay == 0)
434
                                        if(BeepMuster == 0xffff && SenderOkay == 0)
431
                                        {
435
                                        {
432
                                                beeptime = 15000;
436
                                                beeptime = 15000;
433
                                                BeepMuster = 0x0c00;
437
                                                BeepMuster = 0x0c00;
434
                                        }
438
                                        }
435
                                }
439
                                }
436
                                if(NaviDataOkay)
440
                                if(NaviDataOkay)
437
                                {
441
                                {
438
                                        NaviDataOkay--;
442
                                        NaviDataOkay--;
439
                                        FCFlags &= ~FCFLAG_SPI_RX_ERR;
443
                                        FCFlags &= ~FCFLAG_SPI_RX_ERR;
440
                                }
444
                                }
441
                                else
445
                                else
442
                                {
446
                                {
443
                                        GPS_Nick = 0;
447
                                        GPS_Nick = 0;
444
                                        GPS_Roll = 0;
448
                                        GPS_Roll = 0;
445
                                        if(!beeptime) FCFlags |= FCFLAG_SPI_RX_ERR;
449
                                        if(!beeptime) FCFlags |= FCFLAG_SPI_RX_ERR;
446
                                }
450
                                }
447
                           if(UBat < BattLowVoltageWarning)
451
                           if(UBat < BattLowVoltageWarning)
448
                                {
452
                                {
449
                                        FCFlags |= FCFLAG_LOWBAT;
453
                                        FCFlags |= FCFLAG_LOWBAT;
450
                                        if(BeepMuster == 0xffff)
454
                                        if(BeepMuster == 0xffff)
451
                                        {
455
                                        {
452
                                                beeptime = 6000;
456
                                                beeptime = 6000;
453
                                                BeepMuster = 0x0300;
457
                                                BeepMuster = 0x0300;
454
                                        }
458
                                        }
455
                                }
459
                                }
456
                                else if(!beeptime) FCFlags &= ~FCFLAG_LOWBAT;
460
                                else if(!beeptime) FCFlags &= ~FCFLAG_LOWBAT;
457
 
461
 
458
                                SPI_StartTransmitPacket();
462
                                SPI_StartTransmitPacket();
459
                                SendSPI = 4;
463
                                SendSPI = 4;
460
                                if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden
464
                                if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden
461
                                else
465
                                else
462
                if(++second == 49)
466
                if(++second == 49)
463
                                 {
467
                                 {
464
                                   second = 0;
468
                                   second = 0;
465
                                   FlugSekunden++;
469
                                   FlugSekunden++;
466
                                 }
470
                                 }
467
 
471
 
468
                                if(++timer2 == 2930)  // eine Minute
472
                                if(++timer2 == 2930)  // eine Minute
469
                                 {
473
                                 {
470
                                   timer2 = 0;
474
                                   timer2 = 0;
471
                   FlugMinuten++;
475
                   FlugMinuten++;
472
                       FlugMinutenGesamt++;
476
                       FlugMinutenGesamt++;
473
                   eeprom_write_byte((unsigned char*)(EEPROM_ADR_MINUTES2),FlugMinuten / 256);
477
                   eeprom_write_byte((unsigned char*)(EEPROM_ADR_MINUTES2),FlugMinuten / 256);
474
                   eeprom_write_byte((unsigned char*)(EEPROM_ADR_MINUTES2+1),FlugMinuten % 256);
478
                   eeprom_write_byte((unsigned char*)(EEPROM_ADR_MINUTES2+1),FlugMinuten % 256);
475
                   eeprom_write_byte((unsigned char*)(EEPROM_ADR_MINUTES),FlugMinutenGesamt / 256);
479
                   eeprom_write_byte((unsigned char*)(EEPROM_ADR_MINUTES),FlugMinutenGesamt / 256);
476
                   eeprom_write_byte((unsigned char*)(EEPROM_ADR_MINUTES+1),FlugMinutenGesamt % 256);
480
                   eeprom_write_byte((unsigned char*)(EEPROM_ADR_MINUTES+1),FlugMinutenGesamt % 256);
477
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
481
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
478
                             }
482
                             }
479
                        }
483
                        }
480
           LED_Update();
484
           LED_Update();
481
           Capacity_Update();
485
           Capacity_Update();
482
          }
486
          }
483
     if(!SendSPI) { SPI_TransmitByte(); }
487
     if(!SendSPI) { SPI_TransmitByte(); }
484
    }
488
    }
485
 return (1);
489
 return (1);
486
}
490
}
487
 
491
 
488
 
492
 
489
 
493