Subversion Repositories FlightCtrl

Rev

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

Rev 2499 Rev 2500
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
 ChannelAssingment();
75
 ChannelAssingment();
76
 if(ChannelNick > -20) stick = 0;
76
 if(ChannelNick > -20) stick = 0;
77
 if((ChannelNick < -70) && !stick)
77
 if((ChannelNick < -70) && !stick)
78
  {
78
  {
79
   stick = 1;
79
   stick = 1;
80
   WinkelOut.CalcState++;
80
   WinkelOut.CalcState++;
81
   if(WinkelOut.CalcState > 4)
81
   if(WinkelOut.CalcState > 4)
82
    {
82
    {
83
//     WinkelOut.CalcState = 0; // in Uart.c
83
//     WinkelOut.CalcState = 0; // in Uart.c
84
     beeptime = 1000;
84
     beeptime = 1000;
85
    }
85
    }
86
   else Piep(WinkelOut.CalcState,150);
86
   else Piep(WinkelOut.CalcState,150);
87
  }
87
  }
88
}
88
}
89
 
89
 
90
 
90
 
91
void LipoDetection(unsigned char print)
91
void LipoDetection(unsigned char print)
92
{
92
{
93
        #define MAX_CELL_VOLTAGE 43 // max cell voltage for LiPO
93
        #define MAX_CELL_VOLTAGE 43 // max cell voltage for LiPO
94
        if(print)
94
        if(print)
95
         {
95
         {
96
          printf("\n\rBatt:");
96
          printf("\n\rBatt:");
97
          LipoCells = 1 + UBat / MAX_CELL_VOLTAGE;
97
          LipoCells = 1 + UBat / MAX_CELL_VOLTAGE;
98
          if(LipoCells > 6) LipoCells = 6;
98
          if(LipoCells > 6) LipoCells = 6;
99
         }
99
         }
100
 
100
 
101
        if(EE_Parameter.UnterspannungsWarnung < 50)
101
        if(EE_Parameter.UnterspannungsWarnung < 50)
102
        {
102
        {
103
                BattLowVoltageWarning = LipoCells * EE_Parameter.UnterspannungsWarnung;
103
                BattLowVoltageWarning = LipoCells * EE_Parameter.UnterspannungsWarnung;
104
                if(print)
104
                if(print)
105
                {
105
                {
106
                        Piep(LipoCells, 200);
106
                        Piep(LipoCells, 200);
107
                        printf(" %d Cells ", LipoCells);
107
                        printf(" %d Cells ", LipoCells);
108
                }
108
                }
109
        }
109
        }
110
        else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
110
        else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
111
 
111
 
112
        // automatische Zellenerkennung
112
        // automatische Zellenerkennung
113
        if(EE_Parameter.AutoLandingVoltage < 50) BattAutoLandingVoltage = LipoCells * EE_Parameter.AutoLandingVoltage; else BattAutoLandingVoltage = EE_Parameter.AutoLandingVoltage;
113
        if(EE_Parameter.AutoLandingVoltage < 50) BattAutoLandingVoltage = LipoCells * EE_Parameter.AutoLandingVoltage; else BattAutoLandingVoltage = EE_Parameter.AutoLandingVoltage;
114
        if(EE_Parameter.ComingHomeVoltage < 50)  BattComingHomeVoltage = LipoCells * EE_Parameter.ComingHomeVoltage; else BattComingHomeVoltage = EE_Parameter.ComingHomeVoltage;
114
        if(EE_Parameter.ComingHomeVoltage < 50)  BattComingHomeVoltage = LipoCells * EE_Parameter.ComingHomeVoltage; else BattComingHomeVoltage = EE_Parameter.ComingHomeVoltage;
115
 
115
 
116
        if(BattAutoLandingVoltage > BattLowVoltageWarning) BattAutoLandingVoltage = BattLowVoltageWarning - 1;
116
        if(BattAutoLandingVoltage > BattLowVoltageWarning) BattAutoLandingVoltage = BattLowVoltageWarning - 1;
117
        if(BattComingHomeVoltage  >= BattLowVoltageWarning) BattComingHomeVoltage  = BattLowVoltageWarning - 1;
117
        if(BattComingHomeVoltage  >= BattLowVoltageWarning) BattComingHomeVoltage  = BattLowVoltageWarning - 1;
118
        if(BattAutoLandingVoltage >= BattComingHomeVoltage && EE_Parameter.ComingHomeVoltage) BattAutoLandingVoltage = BattComingHomeVoltage - 1;
118
        if(BattAutoLandingVoltage >= BattComingHomeVoltage && EE_Parameter.ComingHomeVoltage) BattAutoLandingVoltage = BattComingHomeVoltage - 1;
119
       
119
       
120
        if(print)
120
        if(print)
121
         {
121
         {
122
          printf(" Low warning: %d.%dV",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
122
          printf(" Low warning: %d.%dV",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
123
          if(BattComingHomeVoltage) printf("  Auto-CH: %d.%dV",BattComingHomeVoltage/10,BattComingHomeVoltage%10);
123
          if(BattComingHomeVoltage) printf("  Auto-CH: %d.%dV",BattComingHomeVoltage/10,BattComingHomeVoltage%10);
124
          if(BattAutoLandingVoltage) printf("  Autolanding: %d.%dV",BattAutoLandingVoltage/10,BattAutoLandingVoltage%10);
124
          if(BattAutoLandingVoltage) printf("  Autolanding: %d.%dV",BattAutoLandingVoltage/10,BattAutoLandingVoltage%10);
125
         }
125
         }
126
 
126
 
127
}
127
}
128
 
128
 
129
//############################################################################
129
//############################################################################
130
//Hauptprogramm
130
//Hauptprogramm
131
int main (void)
131
int main (void)
132
//############################################################################
132
//############################################################################
133
{
133
{
134
        unsigned int timer,i,timer2 = 0, timerPolling;
134
        unsigned int timer,i,timer2 = 0, timerPolling;
135
        unsigned char update_spi = 1;
135
        unsigned char update_spi = 1;
136
    DDRB  = 0x00;
136
    DDRB  = 0x00;
137
    PORTB = 0x00;
137
    PORTB = 0x00;
138
    DDRD  = 0x0A; // UART & J3 J4 J5
138
    DDRD  = 0x0A; // UART & J3 J4 J5
139
        PORTD = 0x5F; // PPM-Input & UART
139
        PORTD = 0x5F; // PPM-Input & UART
140
    for(timer = 0; timer < 1000; timer++); // verzögern
140
    for(timer = 0; timer < 1000; timer++); // verzögern
141
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
141
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
142
        unsigned char AccZ_ErrorCnt = 0;
142
        unsigned char AccZ_ErrorCnt = 0;
143
    if(PINB & 0x02)
143
    if(PINB & 0x02)
144
         {
144
         {
145
          if(PIND & 0x10) PlatinenVersion = 21; // No Bridge from J4 to GND
145
          if(PIND & 0x10) PlatinenVersion = 21; // No Bridge from J4 to GND
146
          else { PlatinenVersion = 22; ACC_AltitudeControl = 1;};
146
          else { PlatinenVersion = 22; ACC_AltitudeControl = 1;};
147
         }
147
         }
148
     else          
148
     else          
149
     {
149
     {
150
          PlatinenVersion = 25; ACC_AltitudeControl = 1;
150
          PlatinenVersion = 25; ACC_AltitudeControl = 1;
151
         }  
151
         }  
152
#else
152
#else
153
        if(PINB & 0x01)
153
        if(PINB & 0x01)
154
     {
154
     {
155
      if(PINB & 0x02) PlatinenVersion = 13;
155
      if(PINB & 0x02) PlatinenVersion = 13;
156
       else           PlatinenVersion = 11;
156
       else           PlatinenVersion = 11;
157
     }
157
     }
158
    else
158
    else
159
     {
159
     {
160
      if(PINB & 0x02) PlatinenVersion = 20;
160
      if(PINB & 0x02) PlatinenVersion = 20;
161
       else          
161
       else          
162
            {
162
            {
163
                 PlatinenVersion = 10;
163
                 PlatinenVersion = 10;
164
                 DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
164
                 DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
165
             PORTD = 0x47; // 
165
             PORTD = 0x47; // 
166
                }
166
                }
167
     }
167
     }
168
#endif
168
#endif
169
 
169
 
170
    DDRC  = 0x81; // I2C, Spaker
170
    DDRC  = 0x81; // I2C, Spaker
171
    DDRC  |=0x40; // HEF4017 Reset
171
    DDRC  |=0x40; // HEF4017 Reset
172
    PORTC = 0xff; // Pullup SDA
172
    PORTC = 0xff; // Pullup SDA
173
    DDRB  = 0x1B; // LEDs und Druckoffset
173
    DDRB  = 0x1B; // LEDs und Druckoffset
174
    PORTB = 0x01; // LED_Rot
174
    PORTB = 0x01; // LED_Rot
175
 
175
 
176
    HEF4017Reset_ON;
176
    HEF4017Reset_ON;
177
    MCUSR &=~(1<<WDRF);
177
    MCUSR &=~(1<<WDRF);
178
    WDTCSR |= (1<<WDCE)|(1<<WDE);
178
    WDTCSR |= (1<<WDCE)|(1<<WDE);
179
    WDTCSR = 0;
179
    WDTCSR = 0;
180
 
180
 
181
    beeptime = 2500;
181
    beeptime = 2500;
182
        StickGier = 0; StickRoll = 0; StickNick = 0;
182
        StickGier = 0; StickRoll = 0; StickNick = 0;
183
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1220; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
183
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1220; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
184
    ROT_OFF;
184
    ROT_OFF;
185
    GRN_ON;
185
    GRN_ON;
186
 
186
 
187
    Timer_Init();
187
    Timer_Init();
188
        TIMER2_Init();
188
        TIMER2_Init();
189
        UART_Init();
189
        UART_Init();
190
    rc_sum_init();
190
    rc_sum_init();
191
        ADC_Init();
191
        ADC_Init();
192
        I2C_Init(1);
192
        I2C_Init(1);
193
        SPI_MasterInit();
193
        SPI_MasterInit();
194
        Capacity_Init();
194
        Capacity_Init();
195
        LIBFC_Init(LIB_FC_COMPATIBLE);
195
        LIBFC_Init(LIB_FC_COMPATIBLE);
196
        GRN_ON;
196
        GRN_ON;
197
    sei();
197
    sei();
198
        ParamSet_Init();
198
        ParamSet_Init();
199
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
199
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
200
    if(PlatinenVersion < 20)
200
    if(PlatinenVersion < 20)
201
        {
201
        {
202
            wdt_enable(WDTO_250MS); // Reset-Commando
202
            wdt_enable(WDTO_250MS); // Reset-Commando
203
                while(1) printf("\n\rOld FC Hardware not supported by this Firmware!");
203
                while(1) printf("\n\rOld FC Hardware not supported by this Firmware!");
204
        }
204
        }
205
#ifndef REDUNDANT_FC_SLAVE
205
#ifndef REDUNDANT_FC_SLAVE
206
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
206
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
207
// + Check connected BL-Ctrls
207
// + Check connected BL-Ctrls
208
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
208
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
209
        // Check connected BL-Ctrls
209
        // Check connected BL-Ctrls
210
        BLFlags |= BLFLAG_READ_VERSION;
210
        BLFlags |= BLFLAG_READ_VERSION;
211
        motor_read = 0;  // read the first I2C-Data
211
        motor_read = 0;  // read the first I2C-Data
212
        for(i=0; i < 500; i++)
212
        for(i=0; i < 500; i++)
213
        {
213
        {
214
         SendMotorData();
214
         SendMotorData();
215
         timer = SetDelay(5);
215
         timer = SetDelay(5);
216
         while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
216
         while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
217
    }
217
    }
218
    printf("\n\rFound BL-Ctrl: ");
218
    printf("\n\rFound BL-Ctrl: ");
219
//    timer = SetDelay(1000);
219
//    timer = SetDelay(1000);
220
        for(i=0; i < MAX_MOTORS; i++)
220
        for(i=0; i < MAX_MOTORS; i++)
221
        {
221
        {
222
//              SendMotorData();
222
//              SendMotorData();
223
//              while(!(BLFlags & BLFLAG_TX_COMPLETE)  && !CheckDelay(timer)); //wait for complete transfer
223
//              while(!(BLFlags & BLFLAG_TX_COMPLETE)  && !CheckDelay(timer)); //wait for complete transfer
224
                if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up
224
                if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up
225
                {
225
                {
226
                        while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) )
226
                        while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) )
227
                        {
227
                        {
228
                                if((BLFlags & BLFLAG_TX_COMPLETE)) SendMotorData();
228
                                if((BLFlags & BLFLAG_TX_COMPLETE)) SendMotorData();
229
                                //while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
229
                                //while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
230
                        }
230
                        }
231
                }
231
                }
232
                if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
232
                if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
233
                {
233
                {
234
                    unsigned char vers;
234
                    unsigned char vers;
235
                        printf("%d",(i+1)%10);
235
                        printf("%d",(i+1)%10);
236
                        FoundMotors++;
236
                        FoundMotors++;
237
                        vers = Motor[i].VersionMajor * 100 + Motor[i].VersionMinor; // creates 104 from 1.04
237
                        vers = Motor[i].VersionMajor * 100 + Motor[i].VersionMinor; // creates 104 from 1.04
238
                        if(vers && VersionInfo.BL_Firmware > vers) VersionInfo.BL_Firmware = vers;
238
                        if(vers && VersionInfo.BL_Firmware > vers) VersionInfo.BL_Firmware = vers;
239
//                      if(Motor[i].Version & MOTOR_STATE_FAST_MODE) printf("(fast)\n\r");
239
//                      if(Motor[i].Version & MOTOR_STATE_FAST_MODE) printf("(fast)\n\r");
240
//                      else if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new)\n\r");
240
//                      else if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new)\n\r");
241
//                      printf(":V%03d\n\r",vers);
241
//                      printf(":V%03d\n\r",vers);
242
                }
242
                }
243
        }
243
        }
244
        for(i=0; i < MAX_MOTORS; i++)
244
        for(i=0; i < MAX_MOTORS; i++)
245
        {
245
        {
246
                if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
246
                if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
247
                {
247
                {
248
                        printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
248
                        printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
249
                        ServoActive = 2; // just in case the FC would be used as camera-stabilizer
249
                        ServoActive = 2; // just in case the FC would be used as camera-stabilizer
250
                }
250
                }
251
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
251
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
252
        }
252
        }
253
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
253
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
254
   if(VersionInfo.BL_Firmware != 255)
254
   if(VersionInfo.BL_Firmware != 255)
255
    {
255
    {
256
         printf("\n\rBL-Firmware %d.%02d",VersionInfo.BL_Firmware/100,VersionInfo.BL_Firmware%100);
256
         printf("\n\rBL-Firmware %d.%02d",VersionInfo.BL_Firmware/100,VersionInfo.BL_Firmware%100);
257
         if(VersionInfo.BL_Firmware >= 100 && VersionInfo.BL_Firmware <= 102) printf("<-- warning old Version!");
257
         if(VersionInfo.BL_Firmware >= 100 && VersionInfo.BL_Firmware <= 102) printf("<-- warning old Version!");
258
        }
258
        }
259
#endif
259
#endif
260
 
260
 
261
   PrintLine();// ("\n\r===================================");
261
   PrintLine();// ("\n\r===================================");
262
    if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER;
262
    if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER;
263
        if(RequiredMotors > 8) Max_I2C_Packets = 8; else Max_I2C_Packets = RequiredMotors;
263
        if(RequiredMotors > 8) Max_I2C_Packets = 8; else Max_I2C_Packets = RequiredMotors;
264
#else
264
#else
265
 printf("\n\r\n\r--> REDUNDANT SLAVE <---\n\r");
265
 printf("\n\r\n\r--> REDUNDANT SLAVE <---\n\r");
266
#endif
266
#endif
267
 
267
 
268
#ifdef REDUNDANT_FC_MASTER
268
#ifdef REDUNDANT_FC_MASTER
269
 printf("\n\r\n\r--> REDUNDANT MASTER <---\n\r");
269
 printf("\n\r\n\r--> REDUNDANT MASTER <---\n\r");
270
#endif
270
#endif
271
 
271
 
272
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
272
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
273
// Calibrating altitude sensor
273
// Calibrating altitude sensor
274
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
274
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
275
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
275
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
276
        {
276
        {
277
                printf("\n\rCalibrating pressure sensor..");
277
                printf("\n\rCalibrating pressure sensor..");
278
                timer = SetDelay(1000);
278
                timer = SetDelay(1000);
279
                SucheLuftruckOffset();
279
                SucheLuftruckOffset();
280
                while (!CheckDelay(timer));
280
                while (!CheckDelay(timer));
281
                printf("OK\n\r");
281
                printf("OK\n\r");
282
        }
282
        }
283
 
283
 
284
#ifdef REDUNDANT_FC_SLAVE
284
#ifdef REDUNDANT_FC_SLAVE
285
VersionInfo.HardwareError[0] = 0;
285
VersionInfo.HardwareError[0] = 0;
286
VersionInfo.HardwareError[1] = 0;
286
VersionInfo.HardwareError[1] = 0;
287
#endif
287
#endif
288
 
288
 
289
        SetNeutral(0);
289
        SetNeutral(0);
290
 
290
 
291
        ROT_OFF;
291
        ROT_OFF;
292
 
292
 
293
    beeptime = 2000;
293
    beeptime = 2000;
294
 
294
 
295
        FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1);
295
        FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1);
296
        FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1);
296
        FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1);
297
 
297
 
298
        if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF))
298
        if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF))
299
        {
299
        {
300
                FlugMinuten = 0;
300
                FlugMinuten = 0;
301
                FlugMinutenGesamt = 0;
301
                FlugMinutenGesamt = 0;
302
        }
302
        }
303
    printf("\n\rFlight-time %u min Total:%u min", FlugMinuten, FlugMinutenGesamt);
303
    printf("\n\rFlight-time %u min Total:%u min", FlugMinuten, FlugMinutenGesamt);
304
    LcdClear();
304
    LcdClear();
305
    I2CTimeout = 5000;
305
    I2CTimeout = 5000;
306
    WinkelOut.Orientation = 1;
306
    WinkelOut.Orientation = 1;
307
    LipoDetection(1);
307
    LipoDetection(1);
308
        LIBFC_ReceiverInit(EE_Parameter.Receiver);
308
        LIBFC_ReceiverInit(EE_Parameter.Receiver);
309
    PrintLine();// ("\n\r===================================");
309
    PrintLine();// ("\n\r===================================");
310
        //SpektrumBinding();
310
        //SpektrumBinding();
311
    timer = SetDelay(2000);
311
    timer = SetDelay(2000);
312
        timerPolling = SetDelay(250);
312
        timerPolling = SetDelay(250);
313
 
313
 
314
        Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt);   // Note: this won't waste flash memory, if #DEBUG is not active
314
        Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt);   // Note: this won't waste flash memory, if #DEBUG is not active
315
//printf("\n\rEE_Parameter size:%i\n\r", PARAMSET_STRUCT_LEN);
315
//printf("\n\rEE_Parameter size:%i\n\r", PARAMSET_STRUCT_LEN);
316
 
316
 
317
    DebugOut.Status[0] = 0x01 | 0x02;
317
    DebugOut.Status[0] = 0x01 | 0x02;
318
        JetiBeep = 0;
318
        JetiBeep = 0;
319
    if(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING)   DisableRcOffBeeping = 1;
319
    if(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING)   DisableRcOffBeeping = 1;
320
        ReadBlSize = 3; // don't read the version any more
320
        ReadBlSize = 3; // don't read the version any more
321
#ifdef REDUNDANT_FC_SLAVE
321
#ifdef REDUNDANT_FC_SLAVE
322
        timer = SetDelay(2500);
322
        timer = SetDelay(2500);
323
        while(!CheckDelay(timer));
323
        while(!CheckDelay(timer));
324
        printf("\n\rStart\n\r");
324
        printf("\n\rStart\n\r");
325
#endif
325
#endif
326
        while(1)
326
        while(1)
327
        {
327
        {
328
        EEAR = EE_DUMMY;  // Set the EEPROM Address pointer to an unused space
328
        EEAR = EE_DUMMY;  // Set the EEPROM Address pointer to an unused space
329
        if(ReceiverUpdateModeActive) while (1) PORTC &= ~(1<<7); // Beeper off
329
        if(ReceiverUpdateModeActive) while (1) PORTC &= ~(1<<7); // Beeper off
330
        if(UpdateMotor && AdReady)      // ReglerIntervall
330
        if(UpdateMotor && AdReady)      // ReglerIntervall
331
            {
331
            {
332
cli();
332
cli();
333
                        UpdateMotor--;    
333
                        UpdateMotor--;    
334
sei();
334
sei();
335
            if(WinkelOut.CalcState) CalMk3Mag();
335
            if(WinkelOut.CalcState) CalMk3Mag();
336
            else  MotorRegler();
336
            else  MotorRegler();
337
                        SendMotorData();
337
                        SendMotorData();
338
            ROT_OFF;
338
            ROT_OFF;
339
            if(SenderOkay)  { SenderOkay--; /*VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM;*/ }
339
            if(SenderOkay)  { SenderOkay--; /*VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM;*/ }
340
                        else
340
                        else
341
                        {
341
                        {
342
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
342
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
343
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
343
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
344
                                VersionInfo.HardwareError[1] |= FC_ERROR1_PPM;
344
                                VersionInfo.HardwareError[1] |= FC_ERROR1_PPM;
345
                                // Now clear the channel values - they would be wrong
345
                                // Now clear the channel values - they would be wrong
346
                                PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
346
                                PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
347
                                PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
347
                                PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
348
                                PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
348
                                PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
349
                                PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
349
                                PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
350
                                PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
350
                                PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
351
                                PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] = 0;
351
                                PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] = 0;
352
                                ChannelNick = 0;
352
                                ChannelNick = 0;
353
                                ChannelRoll = 0;
353
                                ChannelRoll = 0;
354
                                ChannelYaw = 0;
354
                                ChannelYaw = 0;
355
                                ChannelGas = 0;
355
                                ChannelGas = 0;
356
                        }
356
                        }
357
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
357
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
358
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
358
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
359
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
359
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
360
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
361
            if(!--I2CTimeout || MissingMotor)
361
            if(!--I2CTimeout || MissingMotor)
362
                {
362
                {
363
                  if(!I2CTimeout)
363
                  if(!I2CTimeout)
364
                                   {
364
                                   {
365
                                    I2C_Reset();
365
                                    I2C_Reset();
366
                    I2CTimeout = 5;
366
                    I2CTimeout = 5;
367
                                        DebugOut.Analog[28]++; // I2C-Error
367
                                        DebugOut.Analog[28]++; // I2C-Error
368
                                        VersionInfo.HardwareError[1] |= FC_ERROR1_I2C;
368
                                        VersionInfo.HardwareError[1] |= FC_ERROR1_I2C;
369
                                        DebugOut.Status[1] |= 0x02; // BL-Error-Status
369
                                        DebugOut.Status[1] |= 0x02; // BL-Error-Status
370
                                   }
370
                                   }
371
                  if((BeepMuster == 0xffff) && MotorenEin)
371
                  if((BeepMuster == 0xffff) && MotorenEin)
372
                   {
372
                   {
373
                    beeptime = 25000;
373
                    beeptime = 25000;
374
                    BeepMuster = 0x0080;
374
                    BeepMuster = 0x0080;
375
                   }
375
                   }
376
                }
376
                }
377
            else
377
            else
378
                {
378
                {
379
                 ROT_OFF;
379
                 ROT_OFF;
380
                }
380
                }
381
                  LIBFC_Polling();
381
                  LIBFC_Polling();
382
 
382
 
383
          if(!UpdateMotor)
383
          if(!UpdateMotor)
384
                  {
384
                  {
385
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
385
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
386
                   if(NewSBusData) ProcessSBus();  
386
                   if(NewSBusData) ProcessSBus();  
387
                   else
387
                   else
388
#endif
388
#endif
389
                   {
389
                   {
390
                        if(BytegapSPI == 0)  SPI_TransmitByte();
390
                        if(BytegapSPI == 0)  SPI_TransmitByte();
391
                        if(CalculateServoSignals) CalculateServo();
391
                        if(CalculateServoSignals) CalculateServo();
392
                        DatenUebertragung();
392
                        DatenUebertragung();
393
                        BearbeiteRxDaten();
393
                        BearbeiteRxDaten();
394
                        if(CheckDelay(timer))
394
                        if(CheckDelay(timer))
395
                        {
395
                        {
396
                                static unsigned char second;
396
                                static unsigned char second;
397
                                timer += 20; // 20 ms interval
397
                                timer += 20; // 20 ms interval
398
                                CalcNickServoValue();
398
                                CalcNickServoValue();
399
                                // ++++++++++++++++++++++++++++
399
                                // ++++++++++++++++++++++++++++
400
                                // + New direction setpoint from NC
400
                                // + New direction setpoint from NC
401
                                if(NC_CompassSetpoint != -1)
401
                                if(NC_CompassSetpoint != -1)
402
                                {
402
                                {
403
                                   int diff;
403
                                   int diff;
404
                                   if(!NeueKompassRichtungMerken && (KompassSollWert != NC_CompassSetpoint) && CareFree)
404
                                   if(!NeueKompassRichtungMerken && (KompassSollWert != NC_CompassSetpoint) && (CareFree || NCForcesNewDirection))
405
                                    {
405
                                    {
406
                                     diff = ((540 + (KompassSollWert - NC_CompassSetpoint)) % 360) - 180;
406
                                     diff = ((540 + (KompassSollWert - NC_CompassSetpoint)) % 360) - 180;
407
                                         if(diff > 2) diff = 2;    // max. 2° in 20ms = 100°/sec
407
                                         if(diff > 2) diff = 2;    // max. 2° in 20ms = 100°/sec
408
                                         else
408
                                         else
409
                                         if(diff < -2) diff = -2;
409
                                         if(diff < -2) diff = -2;
410
                                         KompassSollWert -= diff;
410
                                         KompassSollWert -= diff;
411
                                        }
411
                                        }
-
 
412
                                        else
-
 
413
                                         {
412
                                        else NC_CompassSetpoint = -1;
414
                                          NC_CompassSetpoint = -1;
-
 
415
                                          NCForcesNewDirection = 0; // allows Yawing without CareFree (Yawing at Coming Home)
-
 
416
                                         }
413
                                 }
417
                                 }
414
                                // ++++++++++++++++++++++++++++
418
                                // ++++++++++++++++++++++++++++
415
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
419
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
416
                                if(EE_Parameter.Receiver == RECEIVER_HOTT) HoTT_Menu();
420
                                if(EE_Parameter.Receiver == RECEIVER_HOTT) HoTT_Menu();
417
                                else
421
                                else
418
                                if(EE_Parameter.Receiver == RECEIVER_JETI) BuildJeti_Vario();
422
                                if(EE_Parameter.Receiver == RECEIVER_JETI) BuildJeti_Vario();
419
                                // ++++++++++++++++++++++++++++
423
                                // ++++++++++++++++++++++++++++
420
                                // + check the ACC-Z range
424
                                // + check the ACC-Z range
421
                                if(ACC_AltitudeControl && ((Aktuell_az < 300) || (DebugOut.Analog[7] < (128 * 4) && Aktuell_az > 850))) // DebugOut.Analog[7] = GasMischanteil
425
                                if(ACC_AltitudeControl && ((Aktuell_az < 300) || (DebugOut.Analog[7] < (128 * 4) && Aktuell_az > 850))) // DebugOut.Analog[7] = GasMischanteil
422
                                 {
426
                                 {
423
                                  if(++AccZ_ErrorCnt > 50)
427
                                  if(++AccZ_ErrorCnt > 50)
424
                                   {
428
                                   {
425
                                    if(MotorenEin) VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP;
429
                                    if(MotorenEin) VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP;
426
                                        else CalibrationDone = 0;
430
                                        else CalibrationDone = 0;
427
                                   }
431
                                   }
428
                                 }
432
                                 }
429
                                 else AccZ_ErrorCnt = 0;
433
                                 else AccZ_ErrorCnt = 0;
430
                                // ++++++++++++++++++++++++++++
434
                                // ++++++++++++++++++++++++++++
431
#endif
435
#endif
432
                                if(MissingMotor || Capacity.MinOfMaxPWM < 30)
436
                                if(MissingMotor || Capacity.MinOfMaxPWM < 30)
433
                                 {
437
                                 {
434
                                  if(MissingMotor) VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING;
438
                                  if(MissingMotor) VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING;
435
                                  DebugOut.Status[1] |= 0x02; // BL-Error-Status
439
                                  DebugOut.Status[1] |= 0x02; // BL-Error-Status
436
                                 }
440
                                 }
437
                                 else
441
                                 else
438
                                 {
442
                                 {
439
                                   if(!beeptime)
443
                                   if(!beeptime)
440
                                    {
444
                                    {
441
                                     if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status
445
                                     if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status
442
                                        }
446
                                        }
443
                                 }
447
                                 }
444
                                if(DisableRcOffBeeping) if(SenderOkay > 150) { DisableRcOffBeeping = 0; beeptime = 5000;};
448
                                if(DisableRcOffBeeping) if(SenderOkay > 150) { DisableRcOffBeeping = 0; beeptime = 5000;};
445
                                if(PcZugriff) PcZugriff--;
449
                                if(PcZugriff) PcZugriff--;
446
                                else
450
                                else
447
                                {
451
                                {
448
                                        if(!SenderOkay)
452
                                        if(!SenderOkay)
449
                                        {
453
                                        {
450
                                          if(BeepMuster == 0xffff && DisableRcOffBeeping != 2)  
454
                                          if(BeepMuster == 0xffff && DisableRcOffBeeping != 2)  
451
                                          {
455
                                          {
452
                                                  beeptime = 15000;
456
                                                  beeptime = 15000;
453
                                                  BeepMuster = 0x0c00;
457
                                                  BeepMuster = 0x0c00;
454
                                                  if(DisableRcOffBeeping) DisableRcOffBeeping = 2;
458
                                                  if(DisableRcOffBeeping) DisableRcOffBeeping = 2;
455
                                          }
459
                                          }
456
                                        }
460
                                        }
457
                                }
461
                                }
458
                                if(NaviDataOkay > 200)
462
                                if(NaviDataOkay > 200)
459
                                {
463
                                {
460
                                        NaviDataOkay--;
464
                                        NaviDataOkay--;
461
                                        VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX;
465
                                        VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX;
462
                                        VersionInfo.Flags |= FC_VERSION_FLAG_NC_PRESENT;
466
                                        VersionInfo.Flags |= FC_VERSION_FLAG_NC_PRESENT;
463
                                }
467
                                }
464
                                else
468
                                else
465
                                {
469
                                {
466
                                        if(NC_Version.Compatible)
470
                                        if(NC_Version.Compatible)
467
                                         {
471
                                         {
468
                                           VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX;
472
                                           VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX;
469
                                           NC_ErrorCode = 9; // "ERR: no NC communication"
473
                                           NC_ErrorCode = 9; // "ERR: no NC communication"
470
                       if(BeepMuster == 0xffff && MotorenEin)
474
                       if(BeepMuster == 0xffff && MotorenEin)
471
                                                {
475
                                                {
472
                                                        beeptime = 15000;
476
                                                        beeptime = 15000;
473
                                                        BeepMuster = 0xA800;
477
                                                        BeepMuster = 0xA800;
474
                                                }
478
                                                }
475
                                         }
479
                                         }
476
                                        GPS_Nick = 0;
480
                                        GPS_Nick = 0;
477
                                        GPS_Roll = 0;
481
                                        GPS_Roll = 0;
478
                                        GPS_Aid_StickMultiplikator = 0;
482
                                        GPS_Aid_StickMultiplikator = 0;
479
                                        GPSInfo.Flags = 0;
483
                                        GPSInfo.Flags = 0;
480
                                        FromNaviCtrl_Value.Kalman_K = -1;
484
                                        FromNaviCtrl_Value.Kalman_K = -1;
481
                                        FromNaviCtrl.AccErrorN = 0;
485
                                        FromNaviCtrl.AccErrorN = 0;
482
                                        FromNaviCtrl.AccErrorR = 0;
486
                                        FromNaviCtrl.AccErrorR = 0;
483
                    FromNaviCtrl.CompassValue = -1;
487
                    FromNaviCtrl.CompassValue = -1;
484
                                        FromNC_AltitudeSpeed = 0;
488
                                        FromNC_AltitudeSpeed = 0;
485
                                        FromNC_AltitudeSetpoint = 0;
489
                                        FromNC_AltitudeSetpoint = 0;
486
                                        VersionInfo.Flags &= ~FC_VERSION_FLAG_NC_PRESENT;
490
                                        VersionInfo.Flags &= ~FC_VERSION_FLAG_NC_PRESENT;
487
                    NaviDataOkay = 0;
491
                    NaviDataOkay = 0;
488
                                }
492
                                }
489
                           if(UBat <= BattLowVoltageWarning)
493
                           if(UBat <= BattLowVoltageWarning)
490
                                {
494
                                {
491
                                        FC_StatusFlags |= FC_STATUS_LOWBAT;
495
                                        FC_StatusFlags |= FC_STATUS_LOWBAT;
492
                                        if(BeepMuster == 0xffff && UBat > 10) // Do not beep, if the voltage reading is below 1V (Supplied via MKUSB)
496
                                        if(BeepMuster == 0xffff && UBat > 10) // Do not beep, if the voltage reading is below 1V (Supplied via MKUSB)
493
                                        {
497
                                        {
494
                                                beeptime = 6000;
498
                                                beeptime = 6000;
495
                                                BeepMuster = 0x0300;
499
                                                BeepMuster = 0x0300;
496
                                        }
500
                                        }
497
                                }
501
                                }
498
                                // +++++++++++++++++++++++++++++++++
502
                                // +++++++++++++++++++++++++++++++++
499
                                if(ExternalControlTimeout)
503
                                if(ExternalControlTimeout)
500
                                 {
504
                                 {
501
                                  ExternalControlTimeout--;
505
                                  ExternalControlTimeout--;
502
                                  if(ExternalControlTimeout == 1) beeptime = 2000;
506
                                  if(ExternalControlTimeout == 1) beeptime = 2000;
503
                                 }
507
                                 }
504
                                // +++++++++++++++++++++++++++++++++
508
                                // +++++++++++++++++++++++++++++++++
505
                                // Sekundentakt
509
                                // Sekundentakt
506
                if(++second == 49)
510
                if(++second == 49)
507
                                 {
511
                                 {
508
                                   second = 0;
512
                                   second = 0;
509
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
513
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
510
                                   if(ShowSettingNameTime) ShowSettingNameTime--;
514
                                   if(ShowSettingNameTime) ShowSettingNameTime--;
511
#endif                             
515
#endif                             
512
                                   if(FC_StatusFlags & FC_STATUS_FLY) FlugSekunden++;
516
                                   if(FC_StatusFlags & FC_STATUS_FLY) FlugSekunden++;
513
                                   else timer2 = 1450; // 0,5 Minuten aufrunden
517
                                   else timer2 = 1450; // 0,5 Minuten aufrunden
514
                                   if(modell_fliegt < 1024)
518
                                   if(modell_fliegt < 1024)
515
                                    {
519
                                    {
516
                                         if(StartLuftdruck < Luftdruck) StartLuftdruck += 5;
520
                                         if(StartLuftdruck < Luftdruck) StartLuftdruck += 5;
517
                                         else
521
                                         else
518
                                         if(StartLuftdruck > Luftdruck) StartLuftdruck -= 5;
522
                                         if(StartLuftdruck > Luftdruck) StartLuftdruck -= 5;
519
                                        }
523
                                        }
520
                             if(UBat > BattLowVoltageWarning + 1) FC_StatusFlags &= ~FC_STATUS_LOWBAT;
524
                             if(UBat > BattLowVoltageWarning + 1) FC_StatusFlags &= ~FC_STATUS_LOWBAT;
521
                                 }
525
                                 }
522
                                // +++++++++++++++++++++++++++++++++
526
                                // +++++++++++++++++++++++++++++++++
523
                                if(++timer2 == 2930)  // eine Minute
527
                                if(++timer2 == 2930)  // eine Minute
524
                                 {
528
                                 {
525
                                   timer2 = 0;
529
                                   timer2 = 0;
526
                   FlugMinuten++;
530
                   FlugMinuten++;
527
                       FlugMinutenGesamt++;
531
                       FlugMinutenGesamt++;
528
                   SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256);
532
                   SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256);
529
                   SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256);
533
                   SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256);
530
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256);
534
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256);
531
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256);
535
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256);
532
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
536
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
533
                             }
537
                             }
534
                        }
538
                        }
535
           LED_Update();
539
           LED_Update();
536
           Capacity_Update();
540
           Capacity_Update();
537
           }
541
           }
538
          } //else DebugOut.Analog[18]++;
542
          } //else DebugOut.Analog[18]++;
539
                  if(update_spi) update_spi--;
543
                  if(update_spi) update_spi--;
540
                 } // 500Hz
544
                 } // 500Hz
541
         if(update_spi == 0) // 41Hz
545
         if(update_spi == 0) // 41Hz
542
          {
546
          {
543
            if(SPI_StartTransmitPacket()) update_spi = 12;
547
            if(SPI_StartTransmitPacket()) update_spi = 12;
544
                else
548
                else
545
                if(BytegapSPI == 0)  SPI_TransmitByte();  
549
                if(BytegapSPI == 0)  SPI_TransmitByte();  
546
           }  
550
           }  
547
         else if(BytegapSPI == 0)  SPI_TransmitByte();
551
         else if(BytegapSPI == 0)  SPI_TransmitByte();
548
    }
552
    }
549
}
553
}
550
//DebugOut.Analog[16] 
554
//DebugOut.Analog[16] 
551
 
555
 
552
 
556