Subversion Repositories FlightCtrl

Rev

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

Rev 1403 Rev 1419
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
unsigned char EEPromArray[E2END+1] EEMEM;
54
unsigned char EEPromArray[E2END+1] EEMEM;
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
// -- Parametersatz aus EEPROM lesen ---
59
// -- Parametersatz aus EEPROM lesen ---
60
// number [1..5]
60
// number [1..5]
61
void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
61
void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
62
{
62
{
63
   if((number > 5)||(number < 1)) number = 3;
63
   if((number > 5)||(number < 1)) number = 3;
64
   eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length);
64
   eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length);
65
   LED_Init();
65
   LED_Init();
66
}
66
}
67
 
67
 
68
// -- Parametersatz ins EEPROM schreiben ---
68
// -- Parametersatz ins EEPROM schreiben ---
69
// number [1..5]
69
// number [1..5]
70
void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
70
void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
71
{
71
{
72
   if(number > 5) number = 5;
72
   if(number > 5) number = 5;
73
   if(number < 1) return;
73
   if(number < 1) return;
74
   eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length);
74
   eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length);
75
   eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_LENGTH], length); // Länge der Datensätze merken
75
   eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_LENGTH], length); // Länge der Datensätze merken
76
   eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_CHANNELS], 12); // 12 Kanäle merken
76
   eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_CHANNELS], 12); // 12 Kanäle merken
77
   SetActiveParamSetNumber(number);
77
   SetActiveParamSetNumber(number);
78
   LED_Init();
78
   LED_Init();
79
}
79
}
80
 
80
 
81
unsigned char GetActiveParamSetNumber(void)
81
unsigned char GetActiveParamSetNumber(void)
82
{
82
{
83
        unsigned char set;
83
        unsigned char set;
84
        set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]);
84
        set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]);
85
        if((set > 5) || (set < 1))
85
        if((set > 5) || (set < 1))
86
        {
86
        {
87
                set = 3;
87
                set = 3;
88
                SetActiveParamSetNumber(set);                           // diesen Parametersatz als aktuell merken
88
                SetActiveParamSetNumber(set);                           // diesen Parametersatz als aktuell merken
89
        }
89
        }
90
        return(set);
90
        return(set);
91
}
91
}
92
 
92
 
93
void SetActiveParamSetNumber(unsigned char number)
93
void SetActiveParamSetNumber(unsigned char number)
94
{
94
{
95
        if(number > 5) number = 5;
95
        if(number > 5) number = 5;
96
        if(number < 1) return;
96
        if(number < 1) return;
97
        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number);                                 // diesen Parametersatz als aktuell merken
97
        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number);                                 // diesen Parametersatz als aktuell merken
98
}
98
}
99
 
99
 
100
 
100
 
101
void CalMk3Mag(void)
101
void CalMk3Mag(void)
102
{
102
{
103
 static unsigned char stick = 1;
103
 static unsigned char stick = 1;
104
 
104
 
105
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
105
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
106
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
106
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
107
  {
107
  {
108
   stick = 1;
108
   stick = 1;
109
   WinkelOut.CalcState++;
109
   WinkelOut.CalcState++;
110
   if(WinkelOut.CalcState > 4)
110
   if(WinkelOut.CalcState > 4)
111
    {
111
    {
112
//     WinkelOut.CalcState = 0; // in Uart.c
112
//     WinkelOut.CalcState = 0; // in Uart.c
113
     beeptime = 1000;
113
     beeptime = 1000;
114
    }
114
    }
115
   else Piep(WinkelOut.CalcState,150);
115
   else Piep(WinkelOut.CalcState,150);
116
  }
116
  }
117
  DebugOut.Analog[19] = WinkelOut.CalcState;
117
  DebugOut.Analog[19] = WinkelOut.CalcState;
118
}
118
}
119
 
119
 
120
void LipoDetection(unsigned char print)
120
void LipoDetection(unsigned char print)
121
{
121
{
122
   unsigned int timer;
122
   unsigned int timer;
123
   if(print) printf("\n\rBatt:");
123
   if(print) printf("\n\rBatt:");
124
   if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung
124
   if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung
125
    {
125
    {
126
         timer = SetDelay(500);
126
         timer = SetDelay(500);
127
         if(print) while (!CheckDelay(timer));
127
         if(print) while (!CheckDelay(timer));
128
         if(UBat < 130)
128
         if(UBat < 130)
129
          {
129
          {
130
           BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung;
130
           BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung;
131
           if(print)
131
           if(print)
132
            {
132
            {
133
                 Piep(3,200);
133
                 Piep(3,200);
134
             printf(" 3 Cells  ");
134
             printf(" 3 Cells  ");
135
                }
135
                }
136
          }
136
          }
137
         else
137
         else
138
          {
138
          {
139
           BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung;
139
           BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung;
140
           if(print)
140
           if(print)
141
            {
141
            {
142
                 Piep(4,200);
142
                 Piep(4,200);
143
             printf(" 4 Cells  ");
143
             printf(" 4 Cells  ");
144
                }
144
                }
145
          }
145
          }
146
    }
146
    }
147
    else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
147
    else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
148
//      if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93;
148
//      if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93;
149
   if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
149
   if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
150
}
150
}
151
 
151
 
152
//############################################################################
152
//############################################################################
153
//Hauptprogramm
153
//Hauptprogramm
154
int main (void)
154
int main (void)
155
//############################################################################
155
//############################################################################
156
{
156
{
157
        unsigned int timer,i,timer2 = 0;
157
        unsigned int timer,i,timer2 = 0, timerJeti;
158
    DDRB  = 0x00;
158
    DDRB  = 0x00;
159
    PORTB = 0x00;
159
    PORTB = 0x00;
160
    for(timer = 0; timer < 1000; timer++); // verzögern
160
    for(timer = 0; timer < 1000; timer++); // verzögern
161
    if(PINB & 0x01)
161
    if(PINB & 0x01)
162
     {
162
     {
163
      if(PINB & 0x02) PlatinenVersion = 13;
163
      if(PINB & 0x02) PlatinenVersion = 13;
164
       else           PlatinenVersion = 11;
164
       else           PlatinenVersion = 11;
165
     }
165
     }
166
    else
166
    else
167
     {
167
     {
168
      if(PINB & 0x02) PlatinenVersion = 20;
168
      if(PINB & 0x02) PlatinenVersion = 20;
169
       else           PlatinenVersion = 10;
169
       else           PlatinenVersion = 10;
170
     }
170
     }
171
 
171
 
172
    DDRC  = 0x81; // SCL
172
    DDRC  = 0x81; // SCL
173
    DDRC  |=0x40; // HEF4017 Reset
173
    DDRC  |=0x40; // HEF4017 Reset
174
    PORTC = 0xff; // Pullup SDA
174
    PORTC = 0xff; // Pullup SDA
175
    DDRB  = 0x1B; // LEDs und Druckoffset
175
    DDRB  = 0x1B; // LEDs und Druckoffset
176
    PORTB = 0x01; // LED_Rot
176
    PORTB = 0x01; // LED_Rot
177
    DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
177
    DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
178
        PORTD = 0x47; // LED
178
        PORTD = 0x47; // LED
179
    HEF4017R_ON;
179
    HEF4017R_ON;
180
    MCUSR &=~(1<<WDRF);
180
    MCUSR &=~(1<<WDRF);
181
    WDTCSR |= (1<<WDCE)|(1<<WDE);
181
    WDTCSR |= (1<<WDCE)|(1<<WDE);
182
    WDTCSR = 0;
182
    WDTCSR = 0;
183
 
183
 
184
    beeptime = 2000;
184
    beeptime = 2000;
185
        StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0;
185
        StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0;
186
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
186
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
187
    ROT_OFF;
187
    ROT_OFF;
188
 
188
 
189
    Timer_Init();
189
    Timer_Init();
190
        TIMER2_Init();
190
        TIMER2_Init();
191
        UART_Init();
191
        UART_Init();
192
    rc_sum_init();
192
    rc_sum_init();
193
        ADC_Init();
193
        ADC_Init();
194
        i2c_init();
194
        i2c_init();
195
        SPI_MasterInit();
195
        SPI_MasterInit();
-
 
196
 
-
 
197
    if(UCSR1A == 0x20 && UCSR1C == 0x06)  // initial Values for 644P
-
 
198
     {
-
 
199
      //Uart1Init();
-
 
200
          JetiBoxUartInit();
-
 
201
     }
196
 
202
 
197
        sei();
203
        sei();
198
        printf("\n\r===================================");
204
        printf("\n\r===================================");
199
        printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",PlatinenVersion/10,PlatinenVersion%10, VERSION_MAJOR, VERSION_MINOR,VERSION_PATCH + 'a');
205
        printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",PlatinenVersion/10,PlatinenVersion%10, VERSION_MAJOR, VERSION_MINOR,VERSION_PATCH + 'a');
200
        printf("\n\rthe use of this software is only permitted \n\ron original MikroKopter-Hardware");
206
        printf("\n\rthe use of this software is only permitted \n\ron original MikroKopter-Hardware");
201
        printf("\n\rwww.MikroKopter.de (c) HiSystems GmbH");
207
        printf("\n\rwww.MikroKopter.de (c) HiSystems GmbH");
202
        printf("\n\r===================================");
208
        printf("\n\r===================================");
203
 
-
 
204
    if(UCSR1A == 0x20 && UCSR1C == 0x06)  // initial Values for 644P
-
 
205
     {
-
 
206
      Uart1Init();
-
 
207
     }
209
 
208
        GRN_ON;
210
        GRN_ON;
209
        ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 13); // read only the first bytes
211
        ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 13); // read only the first bytes
210
    if((eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == MIXER_REVISION) && // Check Revision in the first Byte
212
    if((eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == MIXER_REVISION) && // Check Revision in the first Byte
211
       (eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != 0xff))                   // Settings reset via Koptertool
213
       (eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != 0xff))                   // Settings reset via Koptertool
212
        {
214
        {
213
     unsigned char i;
215
     unsigned char i;
214
         RequiredMotors = 0;
216
         RequiredMotors = 0;
215
     eeprom_read_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer));
217
     eeprom_read_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer));
216
     for(i=0; i<16;i++) { if(Mixer.Motor[i][0] > 0) RequiredMotors++;}
218
     for(i=0; i<16;i++) { if(Mixer.Motor[i][0] > 0) RequiredMotors++;}
217
        }
219
        }
218
        else // default
220
        else // default
219
        {
221
        {
220
     unsigned char i;
222
     unsigned char i;
221
         printf("\n\rGenerating default Mixer Table");
223
         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;};
224
         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
225
     // default = Quadro
224
     Mixer.Motor[0][0] = 64; Mixer.Motor[0][1] = +64; Mixer.Motor[0][2] =   0; Mixer.Motor[0][3] = +64;
226
     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;
227
     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;
228
     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;
229
     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;
230
         Mixer.Revision = MIXER_REVISION;
229
     memcpy(Mixer.Name, "Quadro\0", 11);
231
     memcpy(Mixer.Name, "Quadro\0", 11);
230
     eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer));
232
     eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer));
231
    }
233
    }
232
    printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors);
234
    printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors);
233
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
235
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
234
// + Check connected BL-Ctrls
236
// + Check connected BL-Ctrls
235
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
237
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
236
        printf("\n\rFound BL-Ctrl: ");
238
        printf("\n\rFound BL-Ctrl: ");
237
    motorread = 0;   UpdateMotor = 0;   SendMotorData(); while(!UpdateMotor); motorread = 0;  // read the first I2C-Data
239
    motorread = 0;   UpdateMotor = 0;   SendMotorData(); while(!UpdateMotor); motorread = 0;  // read the first I2C-Data
238
    timer = SetDelay(2000);
240
    timer = SetDelay(2000);
-
 
241
       
-
 
242
       
239
        for(i=0; i < MAX_MOTORS; i++)
243
        for(i=0; i < MAX_MOTORS; i++)
240
         {
244
         {
241
          UpdateMotor = 0;
245
          UpdateMotor = 0;
242
      SendMotorData();
246
      SendMotorData();
243
          while(!UpdateMotor);
247
          while(!UpdateMotor);
244
      if(Mixer.Motor[i][0] > 0) // wait max 2 sec for the BL-Ctrls to wake up
248
      if(Mixer.Motor[i][0] > 0) // wait max 2 sec for the BL-Ctrls to wake up
245
        {
249
        {
246
             while(!CheckDelay(timer) && !MotorPresent[i]) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);};
250
             while(!CheckDelay(timer) && !MotorPresent[i]) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);};
247
                }
251
                }
248
          if(MotorPresent[i]) printf("%d ",i+1);
252
          if(MotorPresent[i]) printf("%d ",i+1);
249
     }
253
     }
250
        for(i=0; i < MAX_MOTORS; i++)
254
        for(i=0; i < MAX_MOTORS; i++)
251
         {
255
         {
252
          if(!MotorPresent[i] && Mixer.Motor[i][0] > 0)
256
          if(!MotorPresent[i] && Mixer.Motor[i][0] > 0)
253
           {
257
           {
254
            printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
258
            printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
255
                ServoActive = 1; // just in case the FC would be used as camera-stabilizer
259
                ServoActive = 1; // just in case the FC would be used as camera-stabilizer
256
           }   
260
           }   
257
          MotorError[i] = 0;
261
          MotorError[i] = 0;
258
     }
262
     }
259
        printf("\n\r===================================");
263
        printf("\n\r===================================");
260
    SendMotorData();
264
    SendMotorData();
261
//printf("\n size: %u",STRUCT_PARAM_LAENGE);
265
//printf("\n size: %u",STRUCT_PARAM_LAENGE);
262
 
266
 
263
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
267
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
264
// + Check Settings
268
// + Check Settings
265
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
269
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
266
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION)
270
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION)
267
        {
271
        {
268
          DefaultKonstanten1();
272
          DefaultKonstanten1();
269
          printf("\n\rInit. EEPROM");
273
          printf("\n\rInit. EEPROM");
270
          for (unsigned char i=1;i<6;i++)
274
          for (unsigned char i=1;i<6;i++)
271
      {
275
      {
272
       if(i==2) DefaultKonstanten2(); // Kamera
276
       if(i==2) DefaultKonstanten2(); // Kamera
273
       if(i==3) DefaultKonstanten3(); // Beginner
277
       if(i==3) DefaultKonstanten3(); // Beginner
274
       if(i>3)  DefaultKonstanten2(); // Kamera
278
       if(i>3)  DefaultKonstanten2(); // Kamera
275
           if(PlatinenVersion >= 20)
279
           if(PlatinenVersion >= 20)
276
            {
280
            {
277
                 EE_Parameter.Gyro_D = 5;
281
                 EE_Parameter.Gyro_D = 5;
278
                 EE_Parameter.Driftkomp = 0;
282
                 EE_Parameter.Driftkomp = 0;
279
                 EE_Parameter.GyroAccFaktor = 27;
283
                 EE_Parameter.GyroAccFaktor = 27;
280
         EE_Parameter.WinkelUmschlagNick = 78;
284
         EE_Parameter.WinkelUmschlagNick = 78;
281
         EE_Parameter.WinkelUmschlagRoll = 78;
285
         EE_Parameter.WinkelUmschlagRoll = 78;
282
                }
286
                }
283
    // valid Stick-Settings?
287
    // valid Stick-Settings?
284
           if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]) < 12)
288
           if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]) < 12)
285
            {
289
            {
286
         EE_Parameter.Kanalbelegung[0] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]);
290
         EE_Parameter.Kanalbelegung[0] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]);
287
         EE_Parameter.Kanalbelegung[1] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]);
291
         EE_Parameter.Kanalbelegung[1] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]);
288
         EE_Parameter.Kanalbelegung[2] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]);
292
         EE_Parameter.Kanalbelegung[2] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]);
289
         EE_Parameter.Kanalbelegung[3] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]);
293
         EE_Parameter.Kanalbelegung[3] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]);
290
         EE_Parameter.Kanalbelegung[4] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+4]);
294
         EE_Parameter.Kanalbelegung[4] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+4]);
291
         EE_Parameter.Kanalbelegung[5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+5]);
295
         EE_Parameter.Kanalbelegung[5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+5]);
292
         EE_Parameter.Kanalbelegung[6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+6]);
296
         EE_Parameter.Kanalbelegung[6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+6]);
293
         EE_Parameter.Kanalbelegung[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]);
297
         EE_Parameter.Kanalbelegung[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]);
294
                 
298
                 
295
         if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]) < 255)
299
         if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]) < 255)
296
                  {
300
                  {
297
                   EE_Parameter.Kanalbelegung[K_POTI5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]);
301
                   EE_Parameter.Kanalbelegung[K_POTI5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]);
298
           EE_Parameter.Kanalbelegung[K_POTI6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+9]);
302
           EE_Parameter.Kanalbelegung[K_POTI6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+9]);
299
           EE_Parameter.Kanalbelegung[K_POTI7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+10]);
303
           EE_Parameter.Kanalbelegung[K_POTI7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+10]);
300
           EE_Parameter.Kanalbelegung[K_POTI8] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+11]);
304
           EE_Parameter.Kanalbelegung[K_POTI8] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+11]);
301
                  }
305
                  }
302
                  else
306
                  else
303
                  {
307
                  {
304
           EE_Parameter.Kanalbelegung[K_POTI5] = 9;
308
           EE_Parameter.Kanalbelegung[K_POTI5] = 9;
305
           EE_Parameter.Kanalbelegung[K_POTI6] = 10;
309
           EE_Parameter.Kanalbelegung[K_POTI6] = 10;
306
           EE_Parameter.Kanalbelegung[K_POTI7] = 11;
310
           EE_Parameter.Kanalbelegung[K_POTI7] = 11;
307
           EE_Parameter.Kanalbelegung[K_POTI8] = 12;
311
           EE_Parameter.Kanalbelegung[K_POTI8] = 12;
308
                  }
312
                  }
309
         if(i==1) printf(": Generating Default-Parameter using old Stick Settings");
313
         if(i==1) printf(": Generating Default-Parameter using old Stick Settings");
310
                } else DefaultStickMapping();
314
                } else DefaultStickMapping();
311
       WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
315
       WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
312
      }
316
      }
313
          SetActiveParamSetNumber(3); // default-Setting
317
          SetActiveParamSetNumber(3); // default-Setting
314
          eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION);
318
          eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION);
315
        }
319
        }
316
 
320
 
317
    FlugMinuten = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1]);
321
    FlugMinuten = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1]);
318
    FlugMinutenGesamt = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES+1]);
322
    FlugMinutenGesamt = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES+1]);
319
    if(FlugMinutenGesamt == 0xffff || FlugMinuten == 0xffff)
323
    if(FlugMinutenGesamt == 0xffff || FlugMinuten == 0xffff)
320
         {
324
         {
321
          FlugMinuten = 0;
325
          FlugMinuten = 0;
322
          FlugMinutenGesamt = 0;
326
          FlugMinutenGesamt = 0;
323
         }
327
         }
324
    printf("\n\rFlight-time %u min  Total:%u min" ,FlugMinuten,FlugMinutenGesamt);
328
    printf("\n\rFlight-time %u min  Total:%u min" ,FlugMinuten,FlugMinutenGesamt);
325
 
329
 
326
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
330
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
327
     {
331
     {
328
       printf("\n\rACC not calibrated !");
332
       printf("\n\rACC not calibrated !");
329
     }
333
     }
330
 
334
 
331
        ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
335
        ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
332
    printf("\n\rUsing parameterset %d", GetActiveParamSetNumber());
336
    printf("\n\rUsing parameterset %d", GetActiveParamSetNumber());
333
 
337
 
334
 
338
 
335
        if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
339
        if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
336
         {
340
         {
337
           printf("\n\rCalibrating pressure sensor..");
341
           printf("\n\rCalibrating pressure sensor..");
338
           timer = SetDelay(1000);
342
           timer = SetDelay(1000);
339
       SucheLuftruckOffset();
343
       SucheLuftruckOffset();
340
           while (!CheckDelay(timer));
344
           while (!CheckDelay(timer));
341
       printf("OK\n\r");
345
       printf("OK\n\r");
342
        }
346
        }
343
 
347
 
344
        SetNeutral();
348
        SetNeutral();
345
 
349
 
346
        ROT_OFF;
350
        ROT_OFF;
347
 
351
 
348
    beeptime = 2000;
352
    beeptime = 2000;
349
    ExternControl.Digital[0] = 0x55;
353
    ExternControl.Digital[0] = 0x55;
350
 
354
 
351
 
355
 
352
        printf("\n\rControl: ");
356
        printf("\n\rControl: ");
353
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
357
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
354
        else printf("Normal (ACC-Mode)");
358
        else printf("Normal (ACC-Mode)");
355
 
359
 
356
    LcdClear();
360
    LcdClear();
357
    I2CTimeout = 5000;
361
    I2CTimeout = 5000;
358
    WinkelOut.Orientation = 1;
362
    WinkelOut.Orientation = 1;
359
    LipoDetection(1);
363
    LipoDetection(1);
360
        printf("\n\r===================================\n\r");
364
        printf("\n\r===================================\n\r");
361
//SpektrumBinding();
365
//SpektrumBinding();
362
    timer = SetDelay(2000);
366
    timer = SetDelay(2000);
-
 
367
        timerJeti = SetDelay(250);
363
        while (1)
368
        while (1)
364
        {
369
        {
-
 
370
           
-
 
371
        if(CheckDelay(timerJeti))
-
 
372
        {
-
 
373
          timerJeti = SetDelay(100);
-
 
374
          JetiBoxPolling();
-
 
375
        }
-
 
376
       
365
            if(UpdateMotor && AdReady)      // ReglerIntervall
377
        if(UpdateMotor && AdReady)      // ReglerIntervall
366
            {
378
            {
367
                    UpdateMotor=0;
379
                    UpdateMotor=0;
368
            if(WinkelOut.CalcState) CalMk3Mag();
380
            if(WinkelOut.CalcState) CalMk3Mag();
369
            else MotorRegler();
381
            else MotorRegler();
370
            SendMotorData();
382
            SendMotorData();
371
            ROT_OFF;
383
            ROT_OFF;
372
            if(SenderOkay)  SenderOkay--;
384
            if(SenderOkay)  SenderOkay--;
373
                        else TIMSK1 |= _BV(ICIE1); // enable PPM-Input
385
                        else TIMSK1 |= _BV(ICIE1); // enable PPM-Input
374
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                 
386
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                 
375
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
387
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
376
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
388
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
377
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
389
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
378
            if(NaviDataOkay)
390
            if(NaviDataOkay)
379
                         {
391
                         {
380
                          if(--NaviDataOkay == 0)
392
                          if(--NaviDataOkay == 0)
381
                           {
393
                           {
382
                    GPS_Nick = 0;
394
                    GPS_Nick = 0;
383
                GPS_Roll = 0;
395
                GPS_Roll = 0;
384
               }
396
               }
385
              }
397
              }
-
 
398
                         
386
            if(!--I2CTimeout || MissingMotor)
399
            if(!--I2CTimeout || MissingMotor)
387
                {
400
                {
388
                  if(!I2CTimeout)
401
                  if(!I2CTimeout)
389
                                   {
402
                                   {
390
                                    i2c_reset();
403
                                    i2c_reset();
391
                    I2CTimeout = 5;
404
                    I2CTimeout = 5;
392
                                        DebugOut.Analog[28]++; // I2C-Error
405
                                        DebugOut.Analog[28]++; // I2C-Error
393
                                   }
406
                                   }
394
                  if((BeepMuster == 0xffff) && MotorenEin)
407
                  if((BeepMuster == 0xffff) && MotorenEin)
395
                   {
408
                   {
396
                    beeptime = 10000;
409
                    beeptime = 10000;
397
                    BeepMuster = 0x0080;
410
                    BeepMuster = 0x0080;
398
                   }
411
                   }
399
                }
412
                }
400
            else
413
            else
401
                {
414
                {
402
                 ROT_OFF;
415
                 ROT_OFF;
403
                }
416
                }
-
 
417
                               
404
            if(SIO_DEBUG && (!UpdateMotor || !MotorenEin))
418
            if(SIO_DEBUG && (!UpdateMotor || !MotorenEin))
405
              {
419
              {
406
               DatenUebertragung();
420
               DatenUebertragung();
407
               BearbeiteRxDaten();
421
               BearbeiteRxDaten();
408
              }
422
              }
409
                        else BearbeiteRxDaten();
423
                        else BearbeiteRxDaten();
-
 
424
                       
-
 
425
                       
410
                        if(CheckDelay(timer))
426
                        if(CheckDelay(timer))
411
                        {
427
                        {
-
 
428
                         
412
                          timer += 20;
429
                  timer += 20;
-
 
430
       
-
 
431
                 
-
 
432
 
413
              if(PcZugriff) PcZugriff--;
433
              if(PcZugriff) PcZugriff--;
414
              else
434
              else
415
               {
435
               {
416
                            ExternControl.Config = 0;
436
                            ExternControl.Config = 0;
417
                ExternStickNick = 0;
437
                ExternStickNick = 0;
418
                ExternStickRoll = 0;
438
                ExternStickRoll = 0;
419
                ExternStickGier = 0;
439
                ExternStickGier = 0;
420
                if(BeepMuster == 0xffff && SenderOkay == 0)
440
                if(BeepMuster == 0xffff && SenderOkay == 0)
421
                {
441
                {
422
                 beeptime = 15000;
442
                 beeptime = 15000;
423
                 BeepMuster = 0x0c00;
443
                 BeepMuster = 0x0c00;
424
                }
444
                }
425
               }
445
               }
426
                           if(UBat < BattLowVoltageWarning)
446
                           if(UBat < BattLowVoltageWarning)
427
                                {
447
                                {
428
                                        MikroKopterFlags |= FLAG_LOWBAT;
448
                                        MikroKopterFlags |= FLAG_LOWBAT;
429
                                        if(BeepMuster == 0xffff)
449
                                        if(BeepMuster == 0xffff)
430
                                        {
450
                                        {
431
                                                beeptime = 6000;
451
                                                beeptime = 6000;
432
                                                BeepMuster = 0x0300;
452
                                                BeepMuster = 0x0300;
433
                                        }
453
                                        }
434
                                }
454
                                }
435
                                else MikroKopterFlags &= ~FLAG_LOWBAT;
455
                                else MikroKopterFlags &= ~FLAG_LOWBAT;
-
 
456
                               
436
                                SPI_StartTransmitPacket();
457
                                SPI_StartTransmitPacket();
437
                                SendSPI = 4;
458
                                SendSPI = 4;
-
 
459
                               
438
                                if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden
460
                                if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden
-
 
461
                               
439
                                if(++timer2 == 2930)  // eine Minute
462
                                if(++timer2 == 2930)  // eine Minute
440
                                 {
463
                                 {
441
                                   timer2 = 0;
464
                                   timer2 = 0;
442
                   FlugMinuten++;
465
                   FlugMinuten++;
443
                       FlugMinutenGesamt++;
466
                       FlugMinutenGesamt++;
444
                   eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2],FlugMinuten / 256);
467
                   eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2],FlugMinuten / 256);
445
                   eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1],FlugMinuten % 256);
468
                   eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1],FlugMinuten % 256);
446
                   eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES],FlugMinutenGesamt / 256);
469
                   eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES],FlugMinutenGesamt / 256);
447
                   eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES+1],FlugMinutenGesamt % 256);
470
                   eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES+1],FlugMinutenGesamt % 256);
448
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
471
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
449
                             }
472
                             }
450
                        }
473
                        }
451
           LED_Update();
474
           LED_Update();
452
          }
475
          }
453
     if(!SendSPI) { SPI_TransmitByte(); }
476
     if(!SendSPI) { SPI_TransmitByte(); }
454
    }
477
    }
455
 return (1);
478
 return (1);
456
}
479
}
457
 
480
 
458
 
481
 
459
 
482