Subversion Repositories FlightCtrl

Rev

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

Rev 2482 Rev 2486
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + www.MikroKopter.com
2
// + www.MikroKopter.com
3
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// + Software Nutzungsbedingungen (english version: see below)
4
// + Software Nutzungsbedingungen (english version: see below)
5
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
5
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
6
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
6
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
7
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
7
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
8
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
8
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
9
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
9
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
10
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
11
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
12
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
12
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
13
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
13
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
14
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
14
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
15
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
15
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
16
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
16
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
17
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
17
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
18
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
18
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
19
// + des Mitverschuldens offen.
19
// + des Mitverschuldens offen.
20
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
20
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
21
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
21
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
22
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
22
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
23
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
23
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
24
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
24
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
25
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
25
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
26
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
26
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
27
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
27
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// + Software LICENSING TERMS
29
// + Software LICENSING TERMS
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
31
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
32
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
32
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
33
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
33
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
34
// + The Software may only be used with the Licensor's products.
34
// + The Software may only be used with the Licensor's products.
35
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
35
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
36
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
36
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
37
// + agreement shall be the property of the Licensor.
37
// + agreement shall be the property of the Licensor.
38
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
38
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
39
// + features that can be used to identify the program may not be altered or defaced by the customer.
39
// + features that can be used to identify the program may not be altered or defaced by the customer.
40
// + The customer shall be responsible for taking reasonable precautions
40
// + The customer shall be responsible for taking reasonable precautions
41
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
41
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
42
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
42
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
43
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
43
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
44
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
44
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
45
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
45
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
46
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
46
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
47
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
47
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
48
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
48
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
49
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
49
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
50
// + #### END OF LICENSING TERMS ####
50
// + #### END OF LICENSING TERMS ####
51
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
51
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
52
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
52
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53
#include "main.h"
53
#include "main.h"
54
unsigned char DisableRcOffBeeping = 0;
54
unsigned char DisableRcOffBeeping = 0;
55
unsigned char PlatinenVersion = 10;
55
unsigned char PlatinenVersion = 10;
56
unsigned char BattLowVoltageWarning = 94;
56
unsigned char BattLowVoltageWarning = 94;
57
unsigned char BattAutoLandingVoltage = 0, BattComingHomeVoltage = 0;
57
unsigned char BattAutoLandingVoltage = 0, BattComingHomeVoltage = 0;
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
unsigned char FoundMotors = 0;
61
unsigned char FoundMotors = 0;
62
unsigned char JetiBeep = 0; // to allow any Morse-Beeping of the Jeti-Box
62
unsigned char JetiBeep = 0; // to allow any Morse-Beeping of the Jeti-Box
63
unsigned char ActiveParamSet = 3;
63
unsigned char ActiveParamSet = 3;
64
unsigned char LipoCells = 4;
64
unsigned char LipoCells = 4;
65
 
65
 
66
void PrintLine(void)
66
void PrintLine(void)
67
{
67
{
68
 printf("\n\r===================================");
68
 printf("\n\r===================================");
69
}
69
}
70
 
70
 
71
 
71
 
72
void CalMk3Mag(void)
72
void CalMk3Mag(void)
73
{
73
{
74
 static unsigned char stick = 1;
74
 static unsigned char stick = 1;
75
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
75
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
76
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
76
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
77
  {
77
  {
78
   stick = 1;
78
   stick = 1;
79
   WinkelOut.CalcState++;
79
   WinkelOut.CalcState++;
80
   if(WinkelOut.CalcState > 4)
80
   if(WinkelOut.CalcState > 4)
81
    {
81
    {
82
//     WinkelOut.CalcState = 0; // in Uart.c
82
//     WinkelOut.CalcState = 0; // in Uart.c
83
     beeptime = 1000;
83
     beeptime = 1000;
84
    }
84
    }
85
   else Piep(WinkelOut.CalcState,150);
85
   else Piep(WinkelOut.CalcState,150);
86
  }
86
  }
87
}
87
}
88
 
88
 
89
 
89
 
90
void LipoDetection(unsigned char print)
90
void LipoDetection(unsigned char print)
91
{
91
{
92
        #define MAX_CELL_VOLTAGE 43 // max cell voltage for LiPO
92
        #define MAX_CELL_VOLTAGE 43 // max cell voltage for LiPO
93
        if(print)
93
        if(print)
94
         {
94
         {
95
          printf("\n\rBatt:");
95
          printf("\n\rBatt:");
96
          LipoCells = 1 + UBat / MAX_CELL_VOLTAGE;
96
          LipoCells = 1 + UBat / MAX_CELL_VOLTAGE;
97
          if(LipoCells > 6) LipoCells = 6;
97
          if(LipoCells > 6) LipoCells = 6;
98
         }
98
         }
99
 
99
 
100
        if(EE_Parameter.UnterspannungsWarnung < 50)
100
        if(EE_Parameter.UnterspannungsWarnung < 50)
101
        {
101
        {
102
                BattLowVoltageWarning = LipoCells * EE_Parameter.UnterspannungsWarnung;
102
                BattLowVoltageWarning = LipoCells * EE_Parameter.UnterspannungsWarnung;
103
                if(print)
103
                if(print)
104
                {
104
                {
105
                        Piep(LipoCells, 200);
105
                        Piep(LipoCells, 200);
106
                        printf(" %d Cells ", LipoCells);
106
                        printf(" %d Cells ", LipoCells);
107
                }
107
                }
108
        }
108
        }
109
        else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
109
        else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
110
 
110
 
111
        // automatische Zellenerkennung
111
        // automatische Zellenerkennung
112
        if(EE_Parameter.AutoLandingVoltage < 50) BattAutoLandingVoltage = LipoCells * EE_Parameter.AutoLandingVoltage; else BattAutoLandingVoltage = EE_Parameter.AutoLandingVoltage;
112
        if(EE_Parameter.AutoLandingVoltage < 50) BattAutoLandingVoltage = LipoCells * EE_Parameter.AutoLandingVoltage; else BattAutoLandingVoltage = EE_Parameter.AutoLandingVoltage;
113
        if(EE_Parameter.ComingHomeVoltage < 50)  BattComingHomeVoltage = LipoCells * EE_Parameter.ComingHomeVoltage; else BattComingHomeVoltage = EE_Parameter.ComingHomeVoltage;
113
        if(EE_Parameter.ComingHomeVoltage < 50)  BattComingHomeVoltage = LipoCells * EE_Parameter.ComingHomeVoltage; else BattComingHomeVoltage = EE_Parameter.ComingHomeVoltage;
114
 
114
 
115
        if(BattAutoLandingVoltage > BattLowVoltageWarning) BattAutoLandingVoltage = BattLowVoltageWarning - 1;
115
        if(BattAutoLandingVoltage > BattLowVoltageWarning) BattAutoLandingVoltage = BattLowVoltageWarning - 1;
116
        if(BattComingHomeVoltage  >= BattLowVoltageWarning) BattComingHomeVoltage  = BattLowVoltageWarning - 1;
116
        if(BattComingHomeVoltage  >= BattLowVoltageWarning) BattComingHomeVoltage  = BattLowVoltageWarning - 1;
117
        if(BattAutoLandingVoltage >= BattComingHomeVoltage && EE_Parameter.ComingHomeVoltage) BattAutoLandingVoltage = BattComingHomeVoltage - 1;
117
        if(BattAutoLandingVoltage >= BattComingHomeVoltage && EE_Parameter.ComingHomeVoltage) BattAutoLandingVoltage = BattComingHomeVoltage - 1;
118
       
118
       
119
        if(print)
119
        if(print)
120
         {
120
         {
121
          printf(" Low warning: %d.%dV",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
121
          printf(" Low warning: %d.%dV",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
122
          if(BattComingHomeVoltage) printf("  Auto-CH: %d.%dV",BattComingHomeVoltage/10,BattComingHomeVoltage%10);
122
          if(BattComingHomeVoltage) printf("  Auto-CH: %d.%dV",BattComingHomeVoltage/10,BattComingHomeVoltage%10);
123
          if(BattAutoLandingVoltage) printf("  Autolanding: %d.%dV",BattAutoLandingVoltage/10,BattAutoLandingVoltage%10);
123
          if(BattAutoLandingVoltage) printf("  Autolanding: %d.%dV",BattAutoLandingVoltage/10,BattAutoLandingVoltage%10);
124
         }
124
         }
125
 
125
 
126
}
126
}
127
 
127
 
128
//############################################################################
128
//############################################################################
129
//Hauptprogramm
129
//Hauptprogramm
130
int main (void)
130
int main (void)
131
//############################################################################
131
//############################################################################
132
{
132
{
133
        unsigned int timer,i,timer2 = 0, timerPolling;
133
        unsigned int timer,i,timer2 = 0, timerPolling;
134
        unsigned char update_spi = 1;
134
        unsigned char update_spi = 1;
135
    DDRB  = 0x00;
135
    DDRB  = 0x00;
136
    PORTB = 0x00;
136
    PORTB = 0x00;
137
    DDRD  = 0x0A; // UART & J3 J4 J5
137
    DDRD  = 0x0A; // UART & J3 J4 J5
138
        PORTD = 0x5F; // PPM-Input & UART
138
        PORTD = 0x5F; // PPM-Input & UART
139
    for(timer = 0; timer < 1000; timer++); // verzögern
139
    for(timer = 0; timer < 1000; timer++); // verzögern
140
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
140
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
141
        unsigned char AccZ_ErrorCnt = 0;
141
        unsigned char AccZ_ErrorCnt = 0;
142
    if(PINB & 0x02)
142
    if(PINB & 0x02)
143
         {
143
         {
144
          if(PIND & 0x10) PlatinenVersion = 21; // No Bridge from J4 to GND
144
          if(PIND & 0x10) PlatinenVersion = 21; // No Bridge from J4 to GND
145
          else { PlatinenVersion = 22; ACC_AltitudeControl = 1;};
145
          else { PlatinenVersion = 22; ACC_AltitudeControl = 1;};
146
         }
146
         }
147
     else          
147
     else          
148
     {
148
     {
149
          PlatinenVersion = 25; ACC_AltitudeControl = 1;
149
          PlatinenVersion = 25; ACC_AltitudeControl = 1;
150
         }  
150
         }  
151
#else
151
#else
152
        if(PINB & 0x01)
152
        if(PINB & 0x01)
153
     {
153
     {
154
      if(PINB & 0x02) PlatinenVersion = 13;
154
      if(PINB & 0x02) PlatinenVersion = 13;
155
       else           PlatinenVersion = 11;
155
       else           PlatinenVersion = 11;
156
     }
156
     }
157
    else
157
    else
158
     {
158
     {
159
      if(PINB & 0x02) PlatinenVersion = 20;
159
      if(PINB & 0x02) PlatinenVersion = 20;
160
       else          
160
       else          
161
            {
161
            {
162
                 PlatinenVersion = 10;
162
                 PlatinenVersion = 10;
163
                 DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
163
                 DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
164
             PORTD = 0x47; // 
164
             PORTD = 0x47; // 
165
                }
165
                }
166
     }
166
     }
167
#endif
167
#endif
168
 
168
 
169
    DDRC  = 0x81; // I2C, Spaker
169
    DDRC  = 0x81; // I2C, Spaker
170
    DDRC  |=0x40; // HEF4017 Reset
170
    DDRC  |=0x40; // HEF4017 Reset
171
    PORTC = 0xff; // Pullup SDA
171
    PORTC = 0xff; // Pullup SDA
172
    DDRB  = 0x1B; // LEDs und Druckoffset
172
    DDRB  = 0x1B; // LEDs und Druckoffset
173
    PORTB = 0x01; // LED_Rot
173
    PORTB = 0x01; // LED_Rot
174
 
174
 
175
    HEF4017Reset_ON;
175
    HEF4017Reset_ON;
176
    MCUSR &=~(1<<WDRF);
176
    MCUSR &=~(1<<WDRF);
177
    WDTCSR |= (1<<WDCE)|(1<<WDE);
177
    WDTCSR |= (1<<WDCE)|(1<<WDE);
178
    WDTCSR = 0;
178
    WDTCSR = 0;
179
 
179
 
180
    beeptime = 2500;
180
    beeptime = 2500;
181
        StickGier = 0; PPM_in[K_GAS] = 0; StickRoll = 0; StickNick = 0;
181
        StickGier = 0; PPM_in[K_GAS] = 0; StickRoll = 0; StickNick = 0;
182
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1220; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
182
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1220; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
183
    ROT_OFF;
183
    ROT_OFF;
184
    GRN_ON;
184
    GRN_ON;
185
 
185
 
186
    Timer_Init();
186
    Timer_Init();
187
        TIMER2_Init();
187
        TIMER2_Init();
188
        UART_Init();
188
        UART_Init();
189
    rc_sum_init();
189
    rc_sum_init();
190
        ADC_Init();
190
        ADC_Init();
191
        I2C_Init(1);
191
        I2C_Init(1);
192
        SPI_MasterInit();
192
        SPI_MasterInit();
193
        Capacity_Init();
193
        Capacity_Init();
194
        LIBFC_Init(LIB_FC_COMPATIBLE);
194
        LIBFC_Init(LIB_FC_COMPATIBLE);
195
        GRN_ON;
195
        GRN_ON;
196
    sei();
196
    sei();
197
        ParamSet_Init();
197
        ParamSet_Init();
198
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
198
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
199
    if(PlatinenVersion < 20)
199
    if(PlatinenVersion < 20)
200
        {
200
        {
201
            wdt_enable(WDTO_250MS); // Reset-Commando
201
            wdt_enable(WDTO_250MS); // Reset-Commando
202
                while(1) printf("\n\rOld FC Hardware not supported by this Firmware!");
202
                while(1) printf("\n\rOld FC Hardware not supported by this Firmware!");
203
        }
203
        }
204
#ifndef REDUNDANT_FC_SLAVE
204
#ifndef REDUNDANT_FC_SLAVE
205
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
205
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
206
// + Check connected BL-Ctrls
206
// + Check connected BL-Ctrls
207
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
207
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
208
        // Check connected BL-Ctrls
208
        // Check connected BL-Ctrls
209
        BLFlags |= BLFLAG_READ_VERSION;
209
        BLFlags |= BLFLAG_READ_VERSION;
210
        motor_read = 0;  // read the first I2C-Data
210
        motor_read = 0;  // read the first I2C-Data
211
        for(i=0; i < 500; i++)
211
        for(i=0; i < 500; i++)
212
        {
212
        {
213
         SendMotorData();
213
         SendMotorData();
214
         timer = SetDelay(5);
214
         timer = SetDelay(5);
215
         while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
215
         while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
216
    }
216
    }
217
    printf("\n\rFound BL-Ctrl: ");
217
    printf("\n\rFound BL-Ctrl: ");
218
//    timer = SetDelay(1000);
218
//    timer = SetDelay(1000);
219
        for(i=0; i < MAX_MOTORS; i++)
219
        for(i=0; i < MAX_MOTORS; i++)
220
        {
220
        {
221
//              SendMotorData();
221
//              SendMotorData();
222
//              while(!(BLFlags & BLFLAG_TX_COMPLETE)  && !CheckDelay(timer)); //wait for complete transfer
222
//              while(!(BLFlags & BLFLAG_TX_COMPLETE)  && !CheckDelay(timer)); //wait for complete transfer
223
                if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up
223
                if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up
224
                {
224
                {
225
                        while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) )
225
                        while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) )
226
                        {
226
                        {
227
                                SendMotorData();
227
                                SendMotorData();
228
                                while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
228
                                while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
229
                        }
229
                        }
230
                }
230
                }
231
                if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
231
                if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
232
                {
232
                {
233
                    unsigned char vers;
233
                    unsigned char vers;
234
                        printf("%d",(i+1)%10);
234
                        printf("%d",(i+1)%10);
235
                        FoundMotors++;
235
                        FoundMotors++;
236
                        vers = Motor[i].VersionMajor * 100 + Motor[i].VersionMinor; // creates 104 from 1.04
236
                        vers = Motor[i].VersionMajor * 100 + Motor[i].VersionMinor; // creates 104 from 1.04
237
                        if(vers && VersionInfo.BL_Firmware > vers) VersionInfo.BL_Firmware = vers;
237
                        if(vers && VersionInfo.BL_Firmware > vers) VersionInfo.BL_Firmware = vers;
238
//                      if(Motor[i].Version & MOTOR_STATE_FAST_MODE) printf("(fast)\n\r");
238
//                      if(Motor[i].Version & MOTOR_STATE_FAST_MODE) printf("(fast)\n\r");
239
//                      else if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new)\n\r");
239
//                      else if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new)\n\r");
240
//                      printf(":V%03d\n\r",vers);
240
//                      printf(":V%03d\n\r",vers);
241
                }
241
                }
242
        }
242
        }
243
        for(i=0; i < MAX_MOTORS; i++)
243
        for(i=0; i < MAX_MOTORS; i++)
244
        {
244
        {
245
                if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
245
                if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
246
                {
246
                {
247
                        printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
247
                        printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
248
                        ServoActive = 2; // just in case the FC would be used as camera-stabilizer
248
                        ServoActive = 2; // just in case the FC would be used as camera-stabilizer
249
                }
249
                }
250
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
250
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
251
        }
251
        }
252
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
252
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
253
   if(VersionInfo.BL_Firmware != 255)
253
   if(VersionInfo.BL_Firmware != 255)
254
    {
254
    {
255
         printf("\n\rBL-Firmware %d.%02d",VersionInfo.BL_Firmware/100,VersionInfo.BL_Firmware%100);
255
         printf("\n\rBL-Firmware %d.%02d",VersionInfo.BL_Firmware/100,VersionInfo.BL_Firmware%100);
256
         if(VersionInfo.BL_Firmware >= 100 && VersionInfo.BL_Firmware <= 102) printf("<-- warning old Version!");
256
         if(VersionInfo.BL_Firmware >= 100 && VersionInfo.BL_Firmware <= 102) printf("<-- warning old Version!");
257
        }
257
        }
258
#endif
258
#endif
259
 
259
 
260
   PrintLine();// ("\n\r===================================");
260
   PrintLine();// ("\n\r===================================");
261
    if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER;
261
    if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER;
262
        if(RequiredMotors > 8) Max_I2C_Packets = 8; else Max_I2C_Packets = RequiredMotors;
262
        if(RequiredMotors > 8) Max_I2C_Packets = 8; else Max_I2C_Packets = RequiredMotors;
263
#else
263
#else
264
 printf("\n\r\n\r--> REDUNDANT SLAVE <---\n\r");
264
 printf("\n\r\n\r--> REDUNDANT SLAVE <---\n\r");
265
#endif
265
#endif
266
 
266
 
267
#ifdef REDUNDANT_FC_MASTER
267
#ifdef REDUNDANT_FC_MASTER
268
 printf("\n\r\n\r--> REDUNDANT MASTER <---\n\r");
268
 printf("\n\r\n\r--> REDUNDANT MASTER <---\n\r");
269
#endif
269
#endif
270
 
270
 
271
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
271
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
272
// Calibrating altitude sensor
272
// Calibrating altitude sensor
273
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
273
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
274
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
274
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
275
        {
275
        {
276
                printf("\n\rCalibrating pressure sensor..");
276
                printf("\n\rCalibrating pressure sensor..");
277
                timer = SetDelay(1000);
277
                timer = SetDelay(1000);
278
                SucheLuftruckOffset();
278
                SucheLuftruckOffset();
279
                while (!CheckDelay(timer));
279
                while (!CheckDelay(timer));
280
                printf("OK\n\r");
280
                printf("OK\n\r");
281
        }
281
        }
282
 
282
 
283
#ifdef REDUNDANT_FC_SLAVE
283
#ifdef REDUNDANT_FC_SLAVE
284
VersionInfo.HardwareError[0] = 0;
284
VersionInfo.HardwareError[0] = 0;
285
VersionInfo.HardwareError[1] = 0;
285
VersionInfo.HardwareError[1] = 0;
286
#endif
286
#endif
287
 
287
 
288
        SetNeutral(0);
288
        SetNeutral(0);
289
 
289
 
290
        ROT_OFF;
290
        ROT_OFF;
291
 
291
 
292
    beeptime = 2000;
292
    beeptime = 2000;
293
    ExternControl.Digital[0] = 0x55;
293
    ExternControl.Digital[0] = 0x55;
294
 
294
 
295
 
295
 
296
        FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1);
296
        FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1);
297
        FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1);
297
        FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1);
298
 
298
 
299
        if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF))
299
        if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF))
300
        {
300
        {
301
                FlugMinuten = 0;
301
                FlugMinuten = 0;
302
                FlugMinutenGesamt = 0;
302
                FlugMinutenGesamt = 0;
303
        }
303
        }
304
    printf("\n\rFlight-time %u min Total:%u min", FlugMinuten, FlugMinutenGesamt);
304
    printf("\n\rFlight-time %u min Total:%u min", FlugMinuten, FlugMinutenGesamt);
305
    LcdClear();
305
    LcdClear();
306
    I2CTimeout = 5000;
306
    I2CTimeout = 5000;
307
    WinkelOut.Orientation = 1;
307
    WinkelOut.Orientation = 1;
308
    LipoDetection(1);
308
    LipoDetection(1);
309
        LIBFC_ReceiverInit(EE_Parameter.Receiver);
309
        LIBFC_ReceiverInit(EE_Parameter.Receiver);
310
    PrintLine();// ("\n\r===================================");
310
    PrintLine();// ("\n\r===================================");
311
        //SpektrumBinding();
311
        //SpektrumBinding();
312
    timer = SetDelay(2000);
312
    timer = SetDelay(2000);
313
        timerPolling = SetDelay(250);
313
        timerPolling = SetDelay(250);
314
 
314
 
315
        Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt);   // Note: this won't waste flash memory, if #DEBUG is not active
315
        Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt);   // Note: this won't waste flash memory, if #DEBUG is not active
316
//printf("\n\rEE_Parameter size:%i\n\r", PARAMSET_STRUCT_LEN);
316
//printf("\n\rEE_Parameter size:%i\n\r", PARAMSET_STRUCT_LEN);
317
 
317
 
318
    DebugOut.Status[0] = 0x01 | 0x02;
318
    DebugOut.Status[0] = 0x01 | 0x02;
319
        JetiBeep = 0;
319
        JetiBeep = 0;
320
    if(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING)   DisableRcOffBeeping = 1;
320
    if(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING)   DisableRcOffBeeping = 1;
321
        ReadBlSize = 3; // don't read the version any more
321
        ReadBlSize = 3; // don't read the version any more
322
#ifdef REDUNDANT_FC_SLAVE
322
#ifdef REDUNDANT_FC_SLAVE
323
        timer = SetDelay(2500);
323
        timer = SetDelay(2500);
324
        while(!CheckDelay(timer));
324
        while(!CheckDelay(timer));
325
        printf("\n\rStart\n\r");
325
        printf("\n\rStart\n\r");
326
#endif
326
#endif
327
        while(1)
327
        while(1)
328
        {
328
        {
329
        EEAR = EE_DUMMY;  // Set the EEPROM Address pointer to an unused space
329
        EEAR = EE_DUMMY;  // Set the EEPROM Address pointer to an unused space
330
        if(ReceiverUpdateModeActive) while (1) PORTC &= ~(1<<7); // Beeper off
330
        if(ReceiverUpdateModeActive) while (1) PORTC &= ~(1<<7); // Beeper off
331
        if(UpdateMotor && AdReady)      // ReglerIntervall
331
        if(UpdateMotor && AdReady)      // ReglerIntervall
332
            {
332
            {
333
cli();
333
cli();
334
                        UpdateMotor--;    
334
                        UpdateMotor--;    
335
sei();
335
sei();
336
            if(WinkelOut.CalcState) CalMk3Mag();
336
            if(WinkelOut.CalcState) CalMk3Mag();
337
            else  MotorRegler();
337
            else  MotorRegler();
338
                        SendMotorData();
338
                        SendMotorData();
339
            ROT_OFF;
339
            ROT_OFF;
340
            if(SenderOkay)  { SenderOkay--; /*VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM;*/ }
340
            if(SenderOkay)  { SenderOkay--; /*VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM;*/ }
341
                        else
341
                        else
342
                        {
342
                        {
343
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
343
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
344
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
344
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
345
                                VersionInfo.HardwareError[1] |= FC_ERROR1_PPM;
345
                                VersionInfo.HardwareError[1] |= FC_ERROR1_PPM;
-
 
346
                                // Now clear the channel values - they would be wrong
-
 
347
                                PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
-
 
348
                                PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
-
 
349
                                PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
-
 
350
                                PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
-
 
351
                                PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
-
 
352
                                PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] = 0;
346
                        }
353
                        }
347
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
354
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
348
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
355
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
349
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
356
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
350
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
357
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
351
            if(!--I2CTimeout || MissingMotor)
358
            if(!--I2CTimeout || MissingMotor)
352
                {
359
                {
353
                  if(!I2CTimeout)
360
                  if(!I2CTimeout)
354
                                   {
361
                                   {
355
                                    I2C_Reset();
362
                                    I2C_Reset();
356
                    I2CTimeout = 5;
363
                    I2CTimeout = 5;
357
                                        DebugOut.Analog[28]++; // I2C-Error
364
                                        DebugOut.Analog[28]++; // I2C-Error
358
                                        VersionInfo.HardwareError[1] |= FC_ERROR1_I2C;
365
                                        VersionInfo.HardwareError[1] |= FC_ERROR1_I2C;
359
                                        DebugOut.Status[1] |= 0x02; // BL-Error-Status
366
                                        DebugOut.Status[1] |= 0x02; // BL-Error-Status
360
                                   }
367
                                   }
361
                  if((BeepMuster == 0xffff) && MotorenEin)
368
                  if((BeepMuster == 0xffff) && MotorenEin)
362
                   {
369
                   {
363
                    beeptime = 25000;
370
                    beeptime = 25000;
364
                    BeepMuster = 0x0080;
371
                    BeepMuster = 0x0080;
365
                   }
372
                   }
366
                }
373
                }
367
            else
374
            else
368
                {
375
                {
369
                 ROT_OFF;
376
                 ROT_OFF;
370
                }
377
                }
371
                  LIBFC_Polling();
378
                  LIBFC_Polling();
372
 
379
 
373
          if(!UpdateMotor)
380
          if(!UpdateMotor)
374
                  {
381
                  {
375
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
382
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
376
                   if(NewSBusData) ProcessSBus();  
383
                   if(NewSBusData) ProcessSBus();  
377
                   else
384
                   else
378
#endif
385
#endif
379
                   {
386
                   {
380
                        if(BytegapSPI == 0)  SPI_TransmitByte();
387
                        if(BytegapSPI == 0)  SPI_TransmitByte();
381
                        if(CalculateServoSignals) CalculateServo();
388
                        if(CalculateServoSignals) CalculateServo();
382
                        DatenUebertragung();
389
                        DatenUebertragung();
383
                        BearbeiteRxDaten();
390
                        BearbeiteRxDaten();
384
                        if(CheckDelay(timer))
391
                        if(CheckDelay(timer))
385
                        {
392
                        {
386
                                static unsigned char second;
393
                                static unsigned char second;
387
                                timer += 20; // 20 ms interval
394
                                timer += 20; // 20 ms interval
388
                                CalcNickServoValue();
395
                                CalcNickServoValue();
389
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
396
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
390
                                if(EE_Parameter.Receiver == RECEIVER_HOTT) HoTT_Menu();
397
                                if(EE_Parameter.Receiver == RECEIVER_HOTT) HoTT_Menu();
391
                                else
398
                                else
392
                                if(EE_Parameter.Receiver == RECEIVER_JETI) BuildJeti_Vario();
399
                                if(EE_Parameter.Receiver == RECEIVER_JETI) BuildJeti_Vario();
393
                                // ++++++++++++++++++++++++++++
400
                                // ++++++++++++++++++++++++++++
394
                                // + check the ACC-Z range
401
                                // + check the ACC-Z range
395
                                if(ACC_AltitudeControl && ((Aktuell_az < 300) || (DebugOut.Analog[7] < (128 * 4) && Aktuell_az > 850))) // DebugOut.Analog[7] = GasMischanteil
402
                                if(ACC_AltitudeControl && ((Aktuell_az < 300) || (DebugOut.Analog[7] < (128 * 4) && Aktuell_az > 850))) // DebugOut.Analog[7] = GasMischanteil
396
                                 {
403
                                 {
397
                                  if(++AccZ_ErrorCnt > 50)
404
                                  if(++AccZ_ErrorCnt > 50)
398
                                   {
405
                                   {
399
                                    if(MotorenEin) VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP;
406
                                    if(MotorenEin) VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP;
400
                                        else CalibrationDone = 0;
407
                                        else CalibrationDone = 0;
401
                                   }
408
                                   }
402
                                 }
409
                                 }
403
                                 else AccZ_ErrorCnt = 0;
410
                                 else AccZ_ErrorCnt = 0;
404
                                // ++++++++++++++++++++++++++++
411
                                // ++++++++++++++++++++++++++++
405
#endif
412
#endif
406
                                if(MissingMotor || Capacity.MinOfMaxPWM < 30)
413
                                if(MissingMotor || Capacity.MinOfMaxPWM < 30)
407
                                 {
414
                                 {
408
                                  if(MissingMotor) VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING;
415
                                  if(MissingMotor) VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING;
409
                                  DebugOut.Status[1] |= 0x02; // BL-Error-Status
416
                                  DebugOut.Status[1] |= 0x02; // BL-Error-Status
410
                                 }
417
                                 }
411
                                 else
418
                                 else
412
                                 {
419
                                 {
413
                                   if(!beeptime)
420
                                   if(!beeptime)
414
                                    {
421
                                    {
415
                                     if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status
422
                                     if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status
416
                                        }
423
                                        }
417
                                 }
424
                                 }
418
                                if(DisableRcOffBeeping) if(SenderOkay > 150) { DisableRcOffBeeping = 0; beeptime = 5000;};
425
                                if(DisableRcOffBeeping) if(SenderOkay > 150) { DisableRcOffBeeping = 0; beeptime = 5000;};
419
                                if(PcZugriff) PcZugriff--;
426
                                if(PcZugriff) PcZugriff--;
420
                                else
427
                                else
421
                                {
428
                                {
422
                                        ExternControl.Config = 0;
429
                                        ExternControl.Config = 0;
423
                                        ExternStickNick = 0;
430
                                        ExternStickNick = 0;
424
                                        ExternStickRoll = 0;
431
                                        ExternStickRoll = 0;
425
                                        ExternStickGier = 0;
432
                                        ExternStickGier = 0;
426
                                        if(!SenderOkay)
433
                                        if(!SenderOkay)
427
                                        {
434
                                        {
428
                                          if(BeepMuster == 0xffff && DisableRcOffBeeping != 2)  
435
                                          if(BeepMuster == 0xffff && DisableRcOffBeeping != 2)  
429
                                          {
436
                                          {
430
                                                  beeptime = 15000;
437
                                                  beeptime = 15000;
431
                                                  BeepMuster = 0x0c00;
438
                                                  BeepMuster = 0x0c00;
432
                                                  if(DisableRcOffBeeping) DisableRcOffBeeping = 2;
439
                                                  if(DisableRcOffBeeping) DisableRcOffBeeping = 2;
433
                                          }
440
                                          }
434
                                        }
441
                                        }
435
                                }
442
                                }
436
                                if(NaviDataOkay > 200)
443
                                if(NaviDataOkay > 200)
437
                                {
444
                                {
438
                                        NaviDataOkay--;
445
                                        NaviDataOkay--;
439
                                        VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX;
446
                                        VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX;
440
                                        VersionInfo.Flags |= FC_VERSION_FLAG_NC_PRESENT;
447
                                        VersionInfo.Flags |= FC_VERSION_FLAG_NC_PRESENT;
441
                                }
448
                                }
442
                                else
449
                                else
443
                                {
450
                                {
444
                                        if(NC_Version.Compatible)
451
                                        if(NC_Version.Compatible)
445
                                         {
452
                                         {
446
                                           VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX;
453
                                           VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX;
447
                                           NC_ErrorCode = 9; // "ERR: no NC communication"
454
                                           NC_ErrorCode = 9; // "ERR: no NC communication"
448
                       if(BeepMuster == 0xffff && MotorenEin)
455
                       if(BeepMuster == 0xffff && MotorenEin)
449
                                                {
456
                                                {
450
                                                        beeptime = 15000;
457
                                                        beeptime = 15000;
451
                                                        BeepMuster = 0xA800;
458
                                                        BeepMuster = 0xA800;
452
                                                }
459
                                                }
453
                                         }
460
                                         }
454
                                        GPS_Nick = 0;
461
                                        GPS_Nick = 0;
455
                                        GPS_Roll = 0;
462
                                        GPS_Roll = 0;
456
                                        GPS_Aid_StickMultiplikator = 0;
463
                                        GPS_Aid_StickMultiplikator = 0;
457
                                        GPSInfo.Flags = 0;
464
                                        GPSInfo.Flags = 0;
458
                                        FromNaviCtrl_Value.Kalman_K = -1;
465
                                        FromNaviCtrl_Value.Kalman_K = -1;
459
                                        FromNaviCtrl.AccErrorN = 0;
466
                                        FromNaviCtrl.AccErrorN = 0;
460
                                        FromNaviCtrl.AccErrorR = 0;
467
                                        FromNaviCtrl.AccErrorR = 0;
461
                    FromNaviCtrl.CompassValue = -1;
468
                    FromNaviCtrl.CompassValue = -1;
462
                                        FromNC_AltitudeSpeed = 0;
469
                                        FromNC_AltitudeSpeed = 0;
463
                                        FromNC_AltitudeSetpoint = 0;
470
                                        FromNC_AltitudeSetpoint = 0;
464
                                        VersionInfo.Flags &= ~FC_VERSION_FLAG_NC_PRESENT;
471
                                        VersionInfo.Flags &= ~FC_VERSION_FLAG_NC_PRESENT;
465
                    NaviDataOkay = 0;
472
                    NaviDataOkay = 0;
466
                                }
473
                                }
467
                           if(UBat <= BattLowVoltageWarning)
474
                           if(UBat <= BattLowVoltageWarning)
468
                                {
475
                                {
469
                                        FC_StatusFlags |= FC_STATUS_LOWBAT;
476
                                        FC_StatusFlags |= FC_STATUS_LOWBAT;
470
                                        if(BeepMuster == 0xffff && UBat > 10) // Do not beep, if the voltage reading is below 1V (Supplied via MKUSB)
477
                                        if(BeepMuster == 0xffff && UBat > 10) // Do not beep, if the voltage reading is below 1V (Supplied via MKUSB)
471
                                        {
478
                                        {
472
                                                beeptime = 6000;
479
                                                beeptime = 6000;
473
                                                BeepMuster = 0x0300;
480
                                                BeepMuster = 0x0300;
474
                                        }
481
                                        }
475
                                }
482
                                }
476
                                // +++++++++++++++++++++++++++++++++
483
                                // +++++++++++++++++++++++++++++++++
477
                                // Sekundentakt
484
                                // Sekundentakt
478
                if(++second == 49)
485
                if(++second == 49)
479
                                 {
486
                                 {
480
                                   second = 0;
487
                                   second = 0;
481
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
488
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
482
                                   if(ShowSettingNameTime) ShowSettingNameTime--;
489
                                   if(ShowSettingNameTime) ShowSettingNameTime--;
483
#endif                             
490
#endif                             
484
                                   if(FC_StatusFlags & FC_STATUS_FLY) FlugSekunden++;
491
                                   if(FC_StatusFlags & FC_STATUS_FLY) FlugSekunden++;
485
                                   else timer2 = 1450; // 0,5 Minuten aufrunden
492
                                   else timer2 = 1450; // 0,5 Minuten aufrunden
486
                                   if(modell_fliegt < 1024)
493
                                   if(modell_fliegt < 1024)
487
                                    {
494
                                    {
488
                                         if(StartLuftdruck < Luftdruck) StartLuftdruck += 5;
495
                                         if(StartLuftdruck < Luftdruck) StartLuftdruck += 5;
489
                                         else
496
                                         else
490
                                         if(StartLuftdruck > Luftdruck) StartLuftdruck -= 5;
497
                                         if(StartLuftdruck > Luftdruck) StartLuftdruck -= 5;
491
                                        }
498
                                        }
492
                             if(UBat > BattLowVoltageWarning + 1) FC_StatusFlags &= ~FC_STATUS_LOWBAT;
499
                             if(UBat > BattLowVoltageWarning + 1) FC_StatusFlags &= ~FC_STATUS_LOWBAT;
493
                                 }
500
                                 }
494
                                // +++++++++++++++++++++++++++++++++
501
                                // +++++++++++++++++++++++++++++++++
495
                                if(++timer2 == 2930)  // eine Minute
502
                                if(++timer2 == 2930)  // eine Minute
496
                                 {
503
                                 {
497
                                   timer2 = 0;
504
                                   timer2 = 0;
498
                   FlugMinuten++;
505
                   FlugMinuten++;
499
                       FlugMinutenGesamt++;
506
                       FlugMinutenGesamt++;
500
                   SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256);
507
                   SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256);
501
                   SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256);
508
                   SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256);
502
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256);
509
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256);
503
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256);
510
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256);
504
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
511
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
505
                             }
512
                             }
506
                        }
513
                        }
507
           LED_Update();
514
           LED_Update();
508
           Capacity_Update();
515
           Capacity_Update();
509
           }
516
           }
510
          } //else DebugOut.Analog[18]++;
517
          } //else DebugOut.Analog[18]++;
511
                  if(update_spi) update_spi--;
518
                  if(update_spi) update_spi--;
512
                 } // 500Hz
519
                 } // 500Hz
513
         if(update_spi == 0) // 41Hz
520
         if(update_spi == 0) // 41Hz
514
          {
521
          {
515
            if(SPI_StartTransmitPacket()) update_spi = 12;
522
            if(SPI_StartTransmitPacket()) update_spi = 12;
516
                else
523
                else
517
                if(BytegapSPI == 0)  SPI_TransmitByte();  
524
                if(BytegapSPI == 0)  SPI_TransmitByte();  
518
           }  
525
           }  
519
         else if(BytegapSPI == 0)  SPI_TransmitByte();
526
         else if(BytegapSPI == 0)  SPI_TransmitByte();
520
    }
527
    }
521
}
528
}
522
//DebugOut.Analog[16] 
529
//DebugOut.Analog[16] 
523
 
530
 
524
 
531