Subversion Repositories FlightCtrl

Rev

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

Rev 1643 Rev 1644
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
 
-
 
67
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
66
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
68
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
67
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
69
  {
68
  {
70
   stick = 1;
69
   stick = 1;
71
   WinkelOut.CalcState++;
70
   WinkelOut.CalcState++;
72
   if(WinkelOut.CalcState > 4)
71
   if(WinkelOut.CalcState > 4)
73
    {
72
    {
74
//     WinkelOut.CalcState = 0; // in Uart.c
73
//     WinkelOut.CalcState = 0; // in Uart.c
75
     beeptime = 1000;
74
     beeptime = 1000;
76
    }
75
    }
77
   else Piep(WinkelOut.CalcState,150);
76
   else Piep(WinkelOut.CalcState,150);
78
  }
77
  }
79
  DebugOut.Analog[19] = WinkelOut.CalcState;
78
  DebugOut.Analog[19] = WinkelOut.CalcState;
80
}
79
}
81
 
80
 
82
 
81
 
83
 
82
 
84
void LipoDetection(unsigned char print)
83
void LipoDetection(unsigned char print)
85
{
84
{
86
   unsigned int timer;
85
   unsigned int timer;
87
   if(print) printf("\n\rBatt:");
86
   if(print) printf("\n\rBatt:");
88
   if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung
87
   if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung
89
    {
88
    {
90
         timer = SetDelay(500);
89
         timer = SetDelay(500);
91
         if(print) while (!CheckDelay(timer));
90
         if(print) while (!CheckDelay(timer));
92
         if(UBat < 130)
91
         if(UBat < 130)
93
          {
92
          {
94
           BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung;
93
           BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung;
95
           if(print)
94
           if(print)
96
            {
95
            {
97
                 Piep(3,200);
96
                 Piep(3,200);
98
             printf(" 3 Cells  ");
97
             printf(" 3 Cells  ");
99
                }
98
                }
100
          }
99
          }
101
         else
100
         else
102
          {
101
          {
103
           BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung;
102
           BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung;
104
           if(print)
103
           if(print)
105
            {
104
            {
106
                 Piep(4,200);
105
                 Piep(4,200);
107
             printf(" 4 Cells  ");
106
             printf(" 4 Cells  ");
108
                }
107
                }
109
          }
108
          }
110
    }
109
    }
111
    else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
110
    else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
112
//      if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93;
111
//      if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93;
113
   if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
112
   if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
114
}
113
}
115
 
114
 
116
//############################################################################
115
//############################################################################
117
//Hauptprogramm
116
//Hauptprogramm
118
int main (void)
117
int main (void)
119
//############################################################################
118
//############################################################################
120
{
119
{
121
        unsigned int timer,i,timer2 = 0, timerPolling;
120
        unsigned int timer,i,timer2 = 0, timerPolling;
122
 
121
 
123
    DDRB  = 0x00;
122
    DDRB  = 0x00;
124
    PORTB = 0x00;
123
    PORTB = 0x00;
125
    for(timer = 0; timer < 1000; timer++); // verzögern
124
    for(timer = 0; timer < 1000; timer++); // verzögern
126
    if(PINB & 0x01)
125
    if(PINB & 0x01)
127
     {
126
     {
128
      if(PINB & 0x02) PlatinenVersion = 13;
127
      if(PINB & 0x02) PlatinenVersion = 13;
129
       else           PlatinenVersion = 11;
128
       else           PlatinenVersion = 11;
130
     }
129
     }
131
    else
130
    else
132
     {
131
     {
133
      if(PINB & 0x02) PlatinenVersion = 20;
132
      if(PINB & 0x02) PlatinenVersion = 20;
134
       else           PlatinenVersion = 10;
133
       else           PlatinenVersion = 10;
135
     }
134
     }
136
 
135
 
137
    DDRC  = 0x81; // SCL
136
    DDRC  = 0x81; // SCL
138
    DDRC  |=0x40; // HEF4017 Reset
137
    DDRC  |=0x40; // HEF4017 Reset
139
    PORTC = 0xff; // Pullup SDA
138
    PORTC = 0xff; // Pullup SDA
140
    DDRB  = 0x1B; // LEDs und Druckoffset
139
    DDRB  = 0x1B; // LEDs und Druckoffset
141
    PORTB = 0x01; // LED_Rot
140
    PORTB = 0x01; // LED_Rot
142
    DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
141
    DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
143
        PORTD = 0x47; // LED
142
        PORTD = 0x47; // LED
144
    HEF4017R_ON;
143
    HEF4017R_ON;
145
    MCUSR &=~(1<<WDRF);
144
    MCUSR &=~(1<<WDRF);
146
    WDTCSR |= (1<<WDCE)|(1<<WDE);
145
    WDTCSR |= (1<<WDCE)|(1<<WDE);
147
    WDTCSR = 0;
146
    WDTCSR = 0;
148
 
147
 
149
    beeptime = 2000;
148
    beeptime = 2000;
150
        StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0;
149
        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
150
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
152
    ROT_OFF;
151
    ROT_OFF;
153
 
152
 
154
    Timer_Init();
153
    Timer_Init();
155
        TIMER2_Init();
154
        TIMER2_Init();
156
        UART_Init();
155
        UART_Init();
157
    rc_sum_init();
156
    rc_sum_init();
158
        ADC_Init();
157
        ADC_Init();
159
        i2c_init();
158
        i2c_init();
160
        SPI_MasterInit();
159
        SPI_MasterInit();
161
        Capacity_Init();
160
        Capacity_Init();
162
        LIBFC_Init();
161
        LIBFC_Init();
163
        GRN_ON;
162
        GRN_ON;
164
    sei();
163
    sei();
165
        ParamSet_Init();
164
        ParamSet_Init();
166
 
165
 
167
 
166
 
168
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
167
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
169
// + Check connected BL-Ctrls
168
// + Check connected BL-Ctrls
170
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
169
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171
    motorread = 0;   UpdateMotor = 0;   SendMotorData(); while(!UpdateMotor); motorread = 0;  // read the first I2C-Data
170
    motorread = 0;   UpdateMotor = 0;   SendMotorData(); while(!UpdateMotor); motorread = 0;  // read the first I2C-Data
172
        printf("\n\rFound BL-Ctrl: ");
171
        printf("\n\rFound BL-Ctrl: ");
173
    timer = SetDelay(4000);
172
    timer = SetDelay(4000);
174
 
173
 
175
        for(i=0; i < MAX_MOTORS; i++)
174
        for(i=0; i < MAX_MOTORS; i++)
176
        {
175
        {
177
                UpdateMotor = 0;
176
                UpdateMotor = 0;
178
                SendMotorData();
177
                SendMotorData();
179
                while(!UpdateMotor);
178
                while(!UpdateMotor);
180
                if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up
179
                if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up
181
                {
180
                {
182
                        while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);};
181
                        while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);};
183
                }
182
                }
184
                if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
183
                if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
185
                 {
184
                 {
186
                  printf("%d",i+1);
185
                  printf("%d",i+1);
187
                  if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new) "); else printf(" ");
186
                  if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new) "); else printf(" ");
188
                 }
187
                 }
189
        }
188
        }
190
        for(i=0; i < MAX_MOTORS; i++)
189
        for(i=0; i < MAX_MOTORS; i++)
191
        {
190
        {
192
                if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
191
                if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
193
                {
192
                {
194
                        printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
193
                        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
194
                        ServoActive = 1; // just in case the FC would be used as camera-stabilizer
196
                }
195
                }
197
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
196
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
198
        }
197
        }
199
        printf("\n\r===================================");
198
        printf("\n\r===================================");
200
    SendMotorData();
199
    SendMotorData();
201
    TransmitBlConfig = 1;
200
    TransmitBlConfig = 1;
202
        motorread = 0;
201
        motorread = 0;
203
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
202
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
204
        {
203
        {
205
                printf("\n\rCalibrating pressure sensor..");
204
                printf("\n\rCalibrating pressure sensor..");
206
                timer = SetDelay(1000);
205
                timer = SetDelay(1000);
207
                SucheLuftruckOffset();
206
                SucheLuftruckOffset();
208
                while (!CheckDelay(timer));
207
                while (!CheckDelay(timer));
209
                printf("OK\n\r");
208
                printf("OK\n\r");
210
        }
209
        }
211
 
210
 
212
        SetNeutral(0);
211
        SetNeutral(0);
213
 
212
 
214
        ROT_OFF;
213
        ROT_OFF;
215
 
214
 
216
    beeptime = 2000;
215
    beeptime = 2000;
217
    ExternControl.Digital[0] = 0x55;
216
    ExternControl.Digital[0] = 0x55;
218
 
217
 
219
 
218
 
220
        FlugMinuten = GetParamWord(PID_FLIGHT_MINUTES);
219
        FlugMinuten = GetParamWord(PID_FLIGHT_MINUTES);
221
        FlugMinutenGesamt = GetParamWord(PID_FLIGHT_MINUTES_TOTAL);
220
        FlugMinutenGesamt = GetParamWord(PID_FLIGHT_MINUTES_TOTAL);
222
 
221
 
223
        if( (FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF) )
222
        if( (FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF) )
224
        {
223
        {
225
                FlugMinuten = 0;
224
                FlugMinuten = 0;
226
                FlugMinutenGesamt = 0;
225
                FlugMinutenGesamt = 0;
227
        }
226
        }
228
    printf("\n\rFlight-time %u min  Total:%u min", FlugMinuten, FlugMinutenGesamt);
227
    printf("\n\rFlight-time %u min  Total:%u min", FlugMinuten, FlugMinutenGesamt);
229
 
228
 
230
        printf("\n\rControl: ");
229
        printf("\n\rControl: ");
231
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
230
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
232
        else printf("Normal (ACC-Mode)");
231
        else printf("Normal (ACC-Mode)");
233
 
232
 
234
    LcdClear();
233
    LcdClear();
235
    I2CTimeout = 5000;
234
    I2CTimeout = 5000;
236
    WinkelOut.Orientation = 1;
235
    WinkelOut.Orientation = 1;
237
    LipoDetection(1);
236
    LipoDetection(1);
238
 
237
 
239
        LIBFC_ReceiverInit(EE_Parameter.Receiver);
238
        LIBFC_ReceiverInit(EE_Parameter.Receiver);
240
 
239
 
241
        printf("\n\r===================================\n\r");
240
        printf("\n\r===================================\n\r");
242
        //SpektrumBinding();
241
        //SpektrumBinding();
243
    timer = SetDelay(2000);
242
    timer = SetDelay(2000);
244
        timerPolling = SetDelay(250);
243
        timerPolling = SetDelay(250);
245
       
244
       
246
        Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt);   // Note: this won't waste flash memory, if #DEBUG is not active
245
        Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt);   // Note: this won't waste flash memory, if #DEBUG is not active
247
       
246
       
248
        while (1)
247
        while (1)
249
        {
248
        {
250
        if(CheckDelay(timerPolling))
249
        if(CheckDelay(timerPolling))
251
        {
250
        {
252
          timerPolling = SetDelay(100);
251
          timerPolling = SetDelay(100);
253
          LIBFC_Polling();
252
          LIBFC_Polling();
254
        }
253
        }
255
        if(UpdateMotor && AdReady)      // ReglerIntervall
254
        if(UpdateMotor && AdReady)      // ReglerIntervall
256
            {
255
            {
257
J3High;
256
J3High;
258
                    UpdateMotor=0;
257
                    UpdateMotor=0;
259
            if(WinkelOut.CalcState) CalMk3Mag();
258
            if(WinkelOut.CalcState) CalMk3Mag();
260
            else MotorRegler();
259
            else  MotorRegler();
261
            SendMotorData();
260
                        SendMotorData();
262
J3Low;
261
J3Low;
263
if(UpdateMotor) DebugOut.Analog[17]++;
262
if(UpdateMotor) DebugOut.Analog[17]++;
264
            ROT_OFF;
263
            ROT_OFF;
265
            if(SenderOkay)  SenderOkay--;
264
            if(SenderOkay)  SenderOkay--;
266
                        else
265
                        else
267
                        {
266
                        {
268
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
267
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
269
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
268
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
270
                        }
269
                        }
271
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
270
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
272
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
271
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
273
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
272
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
274
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
273
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
275
 
274
 
276
            if(!--I2CTimeout || MissingMotor)
275
            if(!--I2CTimeout || MissingMotor)
277
                {
276
                {
278
                  if(!I2CTimeout)
277
                  if(!I2CTimeout)
279
                                   {
278
                                   {
280
                                    i2c_reset();
279
                                    i2c_reset();
281
                    I2CTimeout = 5;
280
                    I2CTimeout = 5;
282
                                        DebugOut.Analog[28]++; // I2C-Error
281
                                        DebugOut.Analog[28]++; // I2C-Error
283
                                        FCFlags |= FCFLAG_I2CERR;
282
                                        FCFlags |= FCFLAG_I2CERR;
284
                                   }
283
                                   }
285
                  if((BeepMuster == 0xffff) && MotorenEin)
284
                  if((BeepMuster == 0xffff) && MotorenEin)
286
                   {
285
                   {
287
                    beeptime = 10000;
286
                    beeptime = 10000;
288
                    BeepMuster = 0x0080;
287
                    BeepMuster = 0x0080;
289
                   }
288
                   }
290
                }
289
                }
291
            else
290
            else
292
                {
291
                {
293
                 ROT_OFF;
292
                 ROT_OFF;
294
                                 if(!beeptime) FCFlags &= ~FCFLAG_I2CERR;
293
                                 if(!beeptime) FCFlags &= ~FCFLAG_I2CERR;
295
                }
294
                }
296
          if(!UpdateMotor)
295
          if(!UpdateMotor)
297
                   {
296
                   {
298
               DatenUebertragung();
297
               DatenUebertragung();
299
               BearbeiteRxDaten();
298
               BearbeiteRxDaten();
300
                        if(CheckDelay(timer))
299
                        if(CheckDelay(timer))
301
                        {
300
                        {
302
                                static unsigned char second;
301
                                static unsigned char second;
303
                                timer += 20; // 20 ms interval
302
                                timer += 20; // 20 ms interval
304
                                if(PcZugriff) PcZugriff--;
303
                                if(PcZugriff) PcZugriff--;
305
                                else
304
                                else
306
                                {
305
                                {
307
                                        ExternControl.Config = 0;
306
                                        ExternControl.Config = 0;
308
                                        ExternStickNick = 0;
307
                                        ExternStickNick = 0;
309
                                        ExternStickRoll = 0;
308
                                        ExternStickRoll = 0;
310
                                        ExternStickGier = 0;
309
                                        ExternStickGier = 0;
311
                                        if(BeepMuster == 0xffff && SenderOkay == 0)
310
                                        if(BeepMuster == 0xffff && SenderOkay == 0)
312
                                        {
311
                                        {
313
                                                beeptime = 15000;
312
                                                beeptime = 15000;
314
                                                BeepMuster = 0x0c00;
313
                                                BeepMuster = 0x0c00;
315
                                        }
314
                                        }
316
                                }
315
                                }
317
                                if(NaviDataOkay)
316
                                if(NaviDataOkay)
318
                                {
317
                                {
319
                                        NaviDataOkay--;
318
                                        NaviDataOkay--;
320
                                        FCFlags &= ~FCFLAG_SPI_RX_ERR;
319
                                        FCFlags &= ~FCFLAG_SPI_RX_ERR;
321
                                }
320
                                }
322
                                else
321
                                else
323
                                {
322
                                {
324
                                        GPS_Nick = 0;
323
                                        GPS_Nick = 0;
325
                                        GPS_Roll = 0;
324
                                        GPS_Roll = 0;
326
                                        if(!beeptime) FCFlags |= FCFLAG_SPI_RX_ERR;
325
                                        if(!beeptime) FCFlags |= FCFLAG_SPI_RX_ERR;
327
                                }
326
                                }
328
                           if(UBat < BattLowVoltageWarning)
327
                           if(UBat < BattLowVoltageWarning)
329
                                {
328
                                {
330
                                        FCFlags |= FCFLAG_LOWBAT;
329
                                        FCFlags |= FCFLAG_LOWBAT;
331
                                        if(BeepMuster == 0xffff)
330
                                        if(BeepMuster == 0xffff)
332
                                        {
331
                                        {
333
                                                beeptime = 6000;
332
                                                beeptime = 6000;
334
                                                BeepMuster = 0x0300;
333
                                                BeepMuster = 0x0300;
335
                                        }
334
                                        }
336
                                }
335
                                }
337
                                else if(!beeptime) FCFlags &= ~FCFLAG_LOWBAT;
336
                                else if(!beeptime) FCFlags &= ~FCFLAG_LOWBAT;
338
 
337
 
339
                                SPI_StartTransmitPacket();
338
                                SPI_StartTransmitPacket();
340
                                SendSPI = 4;
339
                                SendSPI = 4;
341
                                if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden
340
                                if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden
342
                                else
341
                                else
343
                if(++second == 49)
342
                if(++second == 49)
344
                                 {
343
                                 {
345
                                   second = 0;
344
                                   second = 0;
346
                                   FlugSekunden++;
345
                                   FlugSekunden++;
347
                                 }
346
                                 }
348
 
-
 
349
                                if(++timer2 == 2930)  // eine Minute
347
                                if(++timer2 == 2930)  // eine Minute
350
                                 {
348
                                 {
351
                                   timer2 = 0;
349
                                   timer2 = 0;
352
                   FlugMinuten++;
350
                   FlugMinuten++;
353
                       FlugMinutenGesamt++;
351
                       FlugMinutenGesamt++;
354
                       SetParamWord(PID_FLIGHT_MINUTES_TOTAL, FlugMinutenGesamt);
352
                       SetParamWord(PID_FLIGHT_MINUTES_TOTAL, FlugMinutenGesamt);
355
                                   SetParamWord(PID_FLIGHT_MINUTES, FlugMinuten);
353
                                   SetParamWord(PID_FLIGHT_MINUTES, FlugMinuten);
356
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
354
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
357
                             }
355
                             }
358
                        }
356
                        }
359
           LED_Update();
357
           LED_Update();
360
           Capacity_Update();
358
           Capacity_Update();
361
           }
359
           }
362
          }
360
          }
363
     if(!SendSPI) { SPI_TransmitByte(); }
361
     if(!SendSPI) { SPI_TransmitByte(); }
364
    }
362
    }
365
 return (1);
363
 return (1);
366
}
364
}
367
 
365
 
368
 
366
 
369
 
367