Subversion Repositories FlightCtrl

Rev

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

Rev 1638 Rev 1639
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + Copyright (c) Holger Buss, Ingo Busker
2
// + Copyright (c) Holger Buss, Ingo Busker
3
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
3
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
4
// + www.MikroKopter.com
4
// + www.MikroKopter.com
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
7
// + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist.
7
// + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist.
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
11
// + Verkauf von Luftbildaufnahmen, usw.
11
// + Verkauf von Luftbildaufnahmen, usw.
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
17
// + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
17
// + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
18
// + eindeutig als Ursprung verlinkt und genannt werden
18
// + eindeutig als Ursprung verlinkt und genannt werden
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
21
// + Benutzung auf eigene Gefahr
21
// + Benutzung auf eigene Gefahr
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
24
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
25
// + mit unserer Zustimmung zulässig
25
// + mit unserer Zustimmung zulässig
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
30
// + this list of conditions and the following disclaimer.
30
// + this list of conditions and the following disclaimer.
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
32
// +     from this software without specific prior written permission.
32
// +     from this software without specific prior written permission.
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
34
// +     for non-commercial use (directly or indirectly)
34
// +     for non-commercial use (directly or indirectly)
35
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
35
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
36
// +     with our written permission
36
// +     with our written permission
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
38
// +     clearly linked as origin
38
// +     clearly linked as origin
39
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
39
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50
// +  POSSIBILITY OF SUCH DAMAGE.
50
// +  POSSIBILITY OF SUCH DAMAGE.
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
52
#include "main.h"
52
#include "main.h"
53
 
53
 
54
 
54
 
55
unsigned char PlatinenVersion = 10;
55
unsigned char PlatinenVersion = 10;
56
unsigned char SendVersionToNavi = 1;
56
unsigned char SendVersionToNavi = 1;
57
unsigned char BattLowVoltageWarning = 94;
57
unsigned char BattLowVoltageWarning = 94;
58
unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0;
58
unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0;
59
unsigned int FlugSekunden = 0;
59
unsigned int FlugSekunden = 0;
60
pVoidFnct_pVoidFnctChar_const_fmt _printf_P;
60
pVoidFnct_pVoidFnctChar_const_fmt _printf_P;
61
 
61
 
62
 
62
 
63
void CalMk3Mag(void)
63
void CalMk3Mag(void)
64
{
64
{
65
 static unsigned char stick = 1;
65
 static unsigned char stick = 1;
66
 
66
 
67
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
67
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
68
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
68
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
69
  {
69
  {
70
   stick = 1;
70
   stick = 1;
71
   WinkelOut.CalcState++;
71
   WinkelOut.CalcState++;
72
   if(WinkelOut.CalcState > 4)
72
   if(WinkelOut.CalcState > 4)
73
    {
73
    {
74
//     WinkelOut.CalcState = 0; // in Uart.c
74
//     WinkelOut.CalcState = 0; // in Uart.c
75
     beeptime = 1000;
75
     beeptime = 1000;
76
    }
76
    }
77
   else Piep(WinkelOut.CalcState,150);
77
   else Piep(WinkelOut.CalcState,150);
78
  }
78
  }
79
  DebugOut.Analog[19] = WinkelOut.CalcState;
79
  DebugOut.Analog[19] = WinkelOut.CalcState;
80
}
80
}
81
 
81
 
82
 
82
 
83
 
83
 
84
void LipoDetection(unsigned char print)
84
void LipoDetection(unsigned char print)
85
{
85
{
86
   unsigned int timer;
86
   unsigned int timer;
87
   if(print) printf("\n\rBatt:");
87
   if(print) printf("\n\rBatt:");
88
   if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung
88
   if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung
89
    {
89
    {
90
         timer = SetDelay(500);
90
         timer = SetDelay(500);
91
         if(print) while (!CheckDelay(timer));
91
         if(print) while (!CheckDelay(timer));
92
         if(UBat < 130)
92
         if(UBat < 130)
93
          {
93
          {
94
           BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung;
94
           BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung;
95
           if(print)
95
           if(print)
96
            {
96
            {
97
                 Piep(3,200);
97
                 Piep(3,200);
98
             printf(" 3 Cells  ");
98
             printf(" 3 Cells  ");
99
                }
99
                }
100
          }
100
          }
101
         else
101
         else
102
          {
102
          {
103
           BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung;
103
           BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung;
104
           if(print)
104
           if(print)
105
            {
105
            {
106
                 Piep(4,200);
106
                 Piep(4,200);
107
             printf(" 4 Cells  ");
107
             printf(" 4 Cells  ");
108
                }
108
                }
109
          }
109
          }
110
    }
110
    }
111
    else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
111
    else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
112
//      if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93;
112
//      if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93;
113
   if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
113
   if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
114
}
114
}
115
 
115
 
116
//############################################################################
116
//############################################################################
117
//Hauptprogramm
117
//Hauptprogramm
118
int main (void)
118
int main (void)
119
//############################################################################
119
//############################################################################
120
{
120
{
121
        unsigned int timer,i,timer2 = 0, timerPolling;
121
        unsigned int timer,i,timer2 = 0, timerPolling;
122
 
122
 
123
    DDRB  = 0x00;
123
    DDRB  = 0x00;
124
    PORTB = 0x00;
124
    PORTB = 0x00;
125
    for(timer = 0; timer < 1000; timer++); // verzögern
125
    for(timer = 0; timer < 1000; timer++); // verzögern
126
    if(PINB & 0x01)
126
    if(PINB & 0x01)
127
     {
127
     {
128
      if(PINB & 0x02) PlatinenVersion = 13;
128
      if(PINB & 0x02) PlatinenVersion = 13;
129
       else           PlatinenVersion = 11;
129
       else           PlatinenVersion = 11;
130
     }
130
     }
131
    else
131
    else
132
     {
132
     {
133
      if(PINB & 0x02) PlatinenVersion = 20;
133
      if(PINB & 0x02) PlatinenVersion = 20;
134
       else           PlatinenVersion = 10;
134
       else           PlatinenVersion = 10;
135
     }
135
     }
136
 
136
 
137
    DDRC  = 0x81; // SCL
137
    DDRC  = 0x81; // SCL
138
    DDRC  |=0x40; // HEF4017 Reset
138
    DDRC  |=0x40; // HEF4017 Reset
139
    PORTC = 0xff; // Pullup SDA
139
    PORTC = 0xff; // Pullup SDA
140
    DDRB  = 0x1B; // LEDs und Druckoffset
140
    DDRB  = 0x1B; // LEDs und Druckoffset
141
    PORTB = 0x01; // LED_Rot
141
    PORTB = 0x01; // LED_Rot
142
    DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
142
    DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
143
        PORTD = 0x47; // LED
143
        PORTD = 0x47; // LED
144
    HEF4017R_ON;
144
    HEF4017R_ON;
145
    MCUSR &=~(1<<WDRF);
145
    MCUSR &=~(1<<WDRF);
146
    WDTCSR |= (1<<WDCE)|(1<<WDE);
146
    WDTCSR |= (1<<WDCE)|(1<<WDE);
147
    WDTCSR = 0;
147
    WDTCSR = 0;
148
 
148
 
149
    beeptime = 2000;
149
    beeptime = 2000;
150
        StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0;
150
        StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0;
151
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
151
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
152
    ROT_OFF;
152
    ROT_OFF;
153
 
153
 
154
    Timer_Init();
154
    Timer_Init();
155
        TIMER2_Init();
155
        TIMER2_Init();
156
        UART_Init();
156
        UART_Init();
157
    rc_sum_init();
157
    rc_sum_init();
158
        ADC_Init();
158
        ADC_Init();
159
        i2c_init();
159
        i2c_init();
160
        SPI_MasterInit();
160
        SPI_MasterInit();
161
        Capacity_Init();
161
        Capacity_Init();
162
        LIBFC_Init();
162
        LIBFC_Init();
163
        GRN_ON;
163
        GRN_ON;
164
    sei();
164
    sei();
165
        ParamSet_Init();
165
        ParamSet_Init();
166
 
166
 
167
 
167
 
168
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
168
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
169
// + Check connected BL-Ctrls
169
// + Check connected BL-Ctrls
170
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
170
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171
    motorread = 0;   UpdateMotor = 0;   SendMotorData(); while(!UpdateMotor); motorread = 0;  // read the first I2C-Data
171
    motorread = 0;   UpdateMotor = 0;   SendMotorData(); while(!UpdateMotor); motorread = 0;  // read the first I2C-Data
172
        printf("\n\rFound BL-Ctrl: ");
172
        printf("\n\rFound BL-Ctrl: ");
173
    timer = SetDelay(4000);
173
    timer = SetDelay(4000);
174
 
174
 
175
        for(i=0; i < MAX_MOTORS; i++)
175
        for(i=0; i < MAX_MOTORS; i++)
176
        {
176
        {
177
                UpdateMotor = 0;
177
                UpdateMotor = 0;
178
                SendMotorData();
178
                SendMotorData();
179
                while(!UpdateMotor);
179
                while(!UpdateMotor);
180
                if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up
180
                if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up
181
                {
181
                {
182
                        while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);};
182
                        while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);};
183
                }
183
                }
184
                if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
184
                if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
185
                 {
185
                 {
186
                  printf("%d",i+1);
186
                  printf("%d",i+1);
187
                  if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new) "); else printf(" ");
187
                  if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new) "); else printf(" ");
188
                 }
188
                 }
189
        }
189
        }
190
        for(i=0; i < MAX_MOTORS; i++)
190
        for(i=0; i < MAX_MOTORS; i++)
191
        {
191
        {
192
                if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
192
                if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
193
                {
193
                {
194
                        printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
194
                        printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
195
                        ServoActive = 1; // just in case the FC would be used as camera-stabilizer
195
                        ServoActive = 1; // just in case the FC would be used as camera-stabilizer
196
                }
196
                }
197
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
197
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
198
        }
198
        }
199
        printf("\n\r===================================");
199
        printf("\n\r===================================");
200
    SendMotorData();
200
    SendMotorData();
-
 
201
    TransmitBlConfig = 1;
201
 
202
        motorread = 0;
202
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
203
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
203
        {
204
        {
204
                printf("\n\rCalibrating pressure sensor..");
205
                printf("\n\rCalibrating pressure sensor..");
205
                timer = SetDelay(1000);
206
                timer = SetDelay(1000);
206
                SucheLuftruckOffset();
207
                SucheLuftruckOffset();
207
                while (!CheckDelay(timer));
208
                while (!CheckDelay(timer));
208
                printf("OK\n\r");
209
                printf("OK\n\r");
209
        }
210
        }
210
 
211
 
211
        SetNeutral(0);
212
        SetNeutral(0);
212
 
213
 
213
        ROT_OFF;
214
        ROT_OFF;
214
 
215
 
215
    beeptime = 2000;
216
    beeptime = 2000;
216
    ExternControl.Digital[0] = 0x55;
217
    ExternControl.Digital[0] = 0x55;
217
 
218
 
218
 
219
 
219
        FlugMinuten = GetParamWord(PID_FLIGHT_MINUTES);
220
        FlugMinuten = GetParamWord(PID_FLIGHT_MINUTES);
220
        FlugMinutenGesamt = GetParamWord(PID_FLIGHT_MINUTES_TOTAL);
221
        FlugMinutenGesamt = GetParamWord(PID_FLIGHT_MINUTES_TOTAL);
221
 
222
 
222
        if( (FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF) )
223
        if( (FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF) )
223
        {
224
        {
224
                FlugMinuten = 0;
225
                FlugMinuten = 0;
225
                FlugMinutenGesamt = 0;
226
                FlugMinutenGesamt = 0;
226
        }
227
        }
227
    printf("\n\rFlight-time %u min  Total:%u min", FlugMinuten, FlugMinutenGesamt);
228
    printf("\n\rFlight-time %u min  Total:%u min", FlugMinuten, FlugMinutenGesamt);
228
 
229
 
229
        printf("\n\rControl: ");
230
        printf("\n\rControl: ");
230
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
231
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
231
        else printf("Normal (ACC-Mode)");
232
        else printf("Normal (ACC-Mode)");
232
 
233
 
233
    LcdClear();
234
    LcdClear();
234
    I2CTimeout = 5000;
235
    I2CTimeout = 5000;
235
    WinkelOut.Orientation = 1;
236
    WinkelOut.Orientation = 1;
236
    LipoDetection(1);
237
    LipoDetection(1);
237
 
238
 
238
        LIBFC_ReceiverInit(EE_Parameter.Receiver);
239
        LIBFC_ReceiverInit(EE_Parameter.Receiver);
239
 
240
 
240
        printf("\n\r===================================\n\r");
241
        printf("\n\r===================================\n\r");
241
        //SpektrumBinding();
242
        //SpektrumBinding();
242
    timer = SetDelay(2000);
243
    timer = SetDelay(2000);
243
        timerPolling = SetDelay(250);
244
        timerPolling = SetDelay(250);
244
       
245
       
245
        Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt);   // Note: this won't waste flash memory, if #DEBUG is not active
246
        Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt);   // Note: this won't waste flash memory, if #DEBUG is not active
246
       
247
       
247
        while (1)
248
        while (1)
248
        {
249
        {
249
 
-
 
250
        if(CheckDelay(timerPolling))
250
        if(CheckDelay(timerPolling))
251
        {
251
        {
252
          timerPolling = SetDelay(100);
252
          timerPolling = SetDelay(100);
253
          LIBFC_Polling();
253
          LIBFC_Polling();
254
        }
254
        }
255
 
-
 
256
        if(UpdateMotor && AdReady)      // ReglerIntervall
255
        if(UpdateMotor && AdReady)      // ReglerIntervall
257
            {
256
            {
258
                    UpdateMotor=0;
257
                    UpdateMotor=0;
-
 
258
J4High;
259
            if(WinkelOut.CalcState) CalMk3Mag();
259
            if(WinkelOut.CalcState) CalMk3Mag();
260
            else MotorRegler();
260
            else MotorRegler();
261
            SendMotorData();
261
            SendMotorData();
-
 
262
if(UpdateMotor) DebugOut.Analog[17]++;
-
 
263
J4Low;
262
            ROT_OFF;
264
            ROT_OFF;
263
            if(SenderOkay)  SenderOkay--;
265
            if(SenderOkay)  SenderOkay--;
264
                        else
266
                        else
265
                        {
267
                        {
266
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
268
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
267
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
269
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
268
                        }
270
                        }
269
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
271
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
270
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
272
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
271
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
273
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
272
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
274
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
273
 
275
 
274
            if(!--I2CTimeout || MissingMotor)
276
            if(!--I2CTimeout || MissingMotor)
275
                {
277
                {
276
                  if(!I2CTimeout)
278
                  if(!I2CTimeout)
277
                                   {
279
                                   {
278
                                    i2c_reset();
280
                                    i2c_reset();
279
                    I2CTimeout = 5;
281
                    I2CTimeout = 5;
280
                                        DebugOut.Analog[28]++; // I2C-Error
282
                                        DebugOut.Analog[28]++; // I2C-Error
281
                                        FCFlags |= FCFLAG_I2CERR;
283
                                        FCFlags |= FCFLAG_I2CERR;
282
                                   }
284
                                   }
283
                  if((BeepMuster == 0xffff) && MotorenEin)
285
                  if((BeepMuster == 0xffff) && MotorenEin)
284
                   {
286
                   {
285
                    beeptime = 10000;
287
                    beeptime = 10000;
286
                    BeepMuster = 0x0080;
288
                    BeepMuster = 0x0080;
287
                   }
289
                   }
288
                }
290
                }
289
            else
291
            else
290
                {
292
                {
291
                 ROT_OFF;
293
                 ROT_OFF;
292
                                 if(!beeptime) FCFlags &= ~FCFLAG_I2CERR;
294
                                 if(!beeptime) FCFlags &= ~FCFLAG_I2CERR;
293
                }
295
                }
294
            if(SIO_DEBUG && (!UpdateMotor || !MotorenEin))
296
          if(!UpdateMotor)
295
              {
297
                   {
296
               DatenUebertragung();
298
               DatenUebertragung();
297
               BearbeiteRxDaten();
299
               BearbeiteRxDaten();
298
              }
-
 
299
                        else BearbeiteRxDaten();
-
 
300
                        if(CheckDelay(timer))
300
                        if(CheckDelay(timer))
301
                        {
301
                        {
302
                                static unsigned char second;
302
                                static unsigned char second;
303
                                timer += 20; // 20 ms interval
303
                                timer += 20; // 20 ms interval
304
                                if(PcZugriff) PcZugriff--;
304
                                if(PcZugriff) PcZugriff--;
305
                                else
305
                                else
306
                                {
306
                                {
307
                                        ExternControl.Config = 0;
307
                                        ExternControl.Config = 0;
308
                                        ExternStickNick = 0;
308
                                        ExternStickNick = 0;
309
                                        ExternStickRoll = 0;
309
                                        ExternStickRoll = 0;
310
                                        ExternStickGier = 0;
310
                                        ExternStickGier = 0;
311
                                        if(BeepMuster == 0xffff && SenderOkay == 0)
311
                                        if(BeepMuster == 0xffff && SenderOkay == 0)
312
                                        {
312
                                        {
313
                                                beeptime = 15000;
313
                                                beeptime = 15000;
314
                                                BeepMuster = 0x0c00;
314
                                                BeepMuster = 0x0c00;
315
                                        }
315
                                        }
316
                                }
316
                                }
317
                                if(NaviDataOkay)
317
                                if(NaviDataOkay)
318
                                {
318
                                {
319
                                        NaviDataOkay--;
319
                                        NaviDataOkay--;
320
                                        FCFlags &= ~FCFLAG_SPI_RX_ERR;
320
                                        FCFlags &= ~FCFLAG_SPI_RX_ERR;
321
                                }
321
                                }
322
                                else
322
                                else
323
                                {
323
                                {
324
                                        GPS_Nick = 0;
324
                                        GPS_Nick = 0;
325
                                        GPS_Roll = 0;
325
                                        GPS_Roll = 0;
326
                                        if(!beeptime) FCFlags |= FCFLAG_SPI_RX_ERR;
326
                                        if(!beeptime) FCFlags |= FCFLAG_SPI_RX_ERR;
327
                                }
327
                                }
328
                           if(UBat < BattLowVoltageWarning)
328
                           if(UBat < BattLowVoltageWarning)
329
                                {
329
                                {
330
                                        FCFlags |= FCFLAG_LOWBAT;
330
                                        FCFlags |= FCFLAG_LOWBAT;
331
                                        if(BeepMuster == 0xffff)
331
                                        if(BeepMuster == 0xffff)
332
                                        {
332
                                        {
333
                                                beeptime = 6000;
333
                                                beeptime = 6000;
334
                                                BeepMuster = 0x0300;
334
                                                BeepMuster = 0x0300;
335
                                        }
335
                                        }
336
                                }
336
                                }
337
                                else if(!beeptime) FCFlags &= ~FCFLAG_LOWBAT;
337
                                else if(!beeptime) FCFlags &= ~FCFLAG_LOWBAT;
338
 
338
 
339
                                SPI_StartTransmitPacket();
339
                                SPI_StartTransmitPacket();
340
                                SendSPI = 4;
340
                                SendSPI = 4;
341
                                if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden
341
                                if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden
342
                                else
342
                                else
343
                if(++second == 49)
343
                if(++second == 49)
344
                                 {
344
                                 {
345
                                   second = 0;
345
                                   second = 0;
346
                                   FlugSekunden++;
346
                                   FlugSekunden++;
347
                                 }
347
                                 }
348
 
348
 
349
                                if(++timer2 == 2930)  // eine Minute
349
                                if(++timer2 == 2930)  // eine Minute
350
                                 {
350
                                 {
351
                                   timer2 = 0;
351
                                   timer2 = 0;
352
                   FlugMinuten++;
352
                   FlugMinuten++;
353
                       FlugMinutenGesamt++;
353
                       FlugMinutenGesamt++;
354
                       SetParamWord(PID_FLIGHT_MINUTES_TOTAL, FlugMinutenGesamt);
354
                       SetParamWord(PID_FLIGHT_MINUTES_TOTAL, FlugMinutenGesamt);
355
                                   SetParamWord(PID_FLIGHT_MINUTES, FlugMinuten);
355
                                   SetParamWord(PID_FLIGHT_MINUTES, FlugMinuten);
356
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
356
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
357
                             }
357
                             }
358
                        }
358
                        }
359
           LED_Update();
359
           LED_Update();
360
           Capacity_Update();
360
           Capacity_Update();
-
 
361
           }
361
          }
362
          }
362
     if(!SendSPI) { SPI_TransmitByte(); }
363
     if(!SendSPI) { SPI_TransmitByte(); }
363
    }
364
    }
364
 return (1);
365
 return (1);
365
}
366
}
366
 
367
 
367
 
368
 
368
 
369