Subversion Repositories FlightCtrl

Rev

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

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