Subversion Repositories FlightCtrl

Rev

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

Rev 1636 Rev 1638
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) printf("%d ",i+1);
184
                if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
-
 
185
                 {
-
 
186
                  printf("%d",i+1);
-
 
187
                  if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new) "); else printf(" ");
-
 
188
                 }
185
        }
189
        }
186
        for(i=0; i < MAX_MOTORS; i++)
190
        for(i=0; i < MAX_MOTORS; i++)
187
        {
191
        {
188
                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)
189
                {
193
                {
190
                        printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
194
                        printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
191
                        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
192
                }
196
                }
193
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
197
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
194
        }
198
        }
195
        printf("\n\r===================================");
199
        printf("\n\r===================================");
196
    SendMotorData();
200
    SendMotorData();
197
 
201
 
198
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
202
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
199
        {
203
        {
200
                printf("\n\rCalibrating pressure sensor..");
204
                printf("\n\rCalibrating pressure sensor..");
201
                timer = SetDelay(1000);
205
                timer = SetDelay(1000);
202
                SucheLuftruckOffset();
206
                SucheLuftruckOffset();
203
                while (!CheckDelay(timer));
207
                while (!CheckDelay(timer));
204
                printf("OK\n\r");
208
                printf("OK\n\r");
205
        }
209
        }
206
 
210
 
207
        SetNeutral(0);
211
        SetNeutral(0);
208
 
212
 
209
        ROT_OFF;
213
        ROT_OFF;
210
 
214
 
211
    beeptime = 2000;
215
    beeptime = 2000;
212
    ExternControl.Digital[0] = 0x55;
216
    ExternControl.Digital[0] = 0x55;
213
 
217
 
214
 
218
 
215
        FlugMinuten = GetParamWord(PID_FLIGHT_MINUTES);
219
        FlugMinuten = GetParamWord(PID_FLIGHT_MINUTES);
216
        FlugMinutenGesamt = GetParamWord(PID_FLIGHT_MINUTES_TOTAL);
220
        FlugMinutenGesamt = GetParamWord(PID_FLIGHT_MINUTES_TOTAL);
217
 
221
 
218
        if( (FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF) )
222
        if( (FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF) )
219
        {
223
        {
220
                FlugMinuten = 0;
224
                FlugMinuten = 0;
221
                FlugMinutenGesamt = 0;
225
                FlugMinutenGesamt = 0;
222
        }
226
        }
223
    printf("\n\rFlight-time %u min  Total:%u min", FlugMinuten, FlugMinutenGesamt);
227
    printf("\n\rFlight-time %u min  Total:%u min", FlugMinuten, FlugMinutenGesamt);
224
 
-
 
225
 
228
 
226
        printf("\n\rControl: ");
229
        printf("\n\rControl: ");
227
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
230
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
228
        else printf("Normal (ACC-Mode)");
231
        else printf("Normal (ACC-Mode)");
229
 
232
 
230
    LcdClear();
233
    LcdClear();
231
    I2CTimeout = 5000;
234
    I2CTimeout = 5000;
232
    WinkelOut.Orientation = 1;
235
    WinkelOut.Orientation = 1;
233
    LipoDetection(1);
236
    LipoDetection(1);
234
 
237
 
235
        LIBFC_ReceiverInit(EE_Parameter.Receiver);
238
        LIBFC_ReceiverInit(EE_Parameter.Receiver);
236
 
239
 
237
        printf("\n\r===================================\n\r");
240
        printf("\n\r===================================\n\r");
238
        //SpektrumBinding();
241
        //SpektrumBinding();
239
    timer = SetDelay(2000);
242
    timer = SetDelay(2000);
240
        timerPolling = SetDelay(250);
243
        timerPolling = SetDelay(250);
241
       
244
       
242
        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
243
       
246
       
244
        while (1)
247
        while (1)
245
        {
248
        {
246
 
249
 
247
        if(CheckDelay(timerPolling))
250
        if(CheckDelay(timerPolling))
248
        {
251
        {
249
          timerPolling = SetDelay(100);
252
          timerPolling = SetDelay(100);
250
          LIBFC_Polling();
253
          LIBFC_Polling();
251
        }
254
        }
252
 
255
 
253
        if(UpdateMotor && AdReady)      // ReglerIntervall
256
        if(UpdateMotor && AdReady)      // ReglerIntervall
254
            {
257
            {
255
                    UpdateMotor=0;
258
                    UpdateMotor=0;
256
            if(WinkelOut.CalcState) CalMk3Mag();
259
            if(WinkelOut.CalcState) CalMk3Mag();
257
            else MotorRegler();
260
            else MotorRegler();
258
            SendMotorData();
261
            SendMotorData();
259
            ROT_OFF;
262
            ROT_OFF;
260
            if(SenderOkay)  SenderOkay--;
263
            if(SenderOkay)  SenderOkay--;
261
                        else
264
                        else
262
                        {
265
                        {
263
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
266
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
264
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
267
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
265
                        }
268
                        }
266
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
269
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
267
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
270
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
268
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
271
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
269
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
272
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
270
 
273
 
271
            if(!--I2CTimeout || MissingMotor)
274
            if(!--I2CTimeout || MissingMotor)
272
                {
275
                {
273
                  if(!I2CTimeout)
276
                  if(!I2CTimeout)
274
                                   {
277
                                   {
275
                                    i2c_reset();
278
                                    i2c_reset();
276
                    I2CTimeout = 5;
279
                    I2CTimeout = 5;
277
                                        DebugOut.Analog[28]++; // I2C-Error
280
                                        DebugOut.Analog[28]++; // I2C-Error
278
                                        FCFlags |= FCFLAG_I2CERR;
281
                                        FCFlags |= FCFLAG_I2CERR;
279
                                   }
282
                                   }
280
                  if((BeepMuster == 0xffff) && MotorenEin)
283
                  if((BeepMuster == 0xffff) && MotorenEin)
281
                   {
284
                   {
282
                    beeptime = 10000;
285
                    beeptime = 10000;
283
                    BeepMuster = 0x0080;
286
                    BeepMuster = 0x0080;
284
                   }
287
                   }
285
                }
288
                }
286
            else
289
            else
287
                {
290
                {
288
                 ROT_OFF;
291
                 ROT_OFF;
289
                                 if(!beeptime) FCFlags &= ~FCFLAG_I2CERR;
292
                                 if(!beeptime) FCFlags &= ~FCFLAG_I2CERR;
290
                }
293
                }
291
            if(SIO_DEBUG && (!UpdateMotor || !MotorenEin))
294
            if(SIO_DEBUG && (!UpdateMotor || !MotorenEin))
292
              {
295
              {
293
               DatenUebertragung();
296
               DatenUebertragung();
294
               BearbeiteRxDaten();
297
               BearbeiteRxDaten();
295
              }
298
              }
296
                        else BearbeiteRxDaten();
299
                        else BearbeiteRxDaten();
297
                        if(CheckDelay(timer))
300
                        if(CheckDelay(timer))
298
                        {
301
                        {
299
                                static unsigned char second;
302
                                static unsigned char second;
300
                                timer += 20; // 20 ms interval
303
                                timer += 20; // 20 ms interval
301
                                if(PcZugriff) PcZugriff--;
304
                                if(PcZugriff) PcZugriff--;
302
                                else
305
                                else
303
                                {
306
                                {
304
                                        ExternControl.Config = 0;
307
                                        ExternControl.Config = 0;
305
                                        ExternStickNick = 0;
308
                                        ExternStickNick = 0;
306
                                        ExternStickRoll = 0;
309
                                        ExternStickRoll = 0;
307
                                        ExternStickGier = 0;
310
                                        ExternStickGier = 0;
308
                                        if(BeepMuster == 0xffff && SenderOkay == 0)
311
                                        if(BeepMuster == 0xffff && SenderOkay == 0)
309
                                        {
312
                                        {
310
                                                beeptime = 15000;
313
                                                beeptime = 15000;
311
                                                BeepMuster = 0x0c00;
314
                                                BeepMuster = 0x0c00;
312
                                        }
315
                                        }
313
                                }
316
                                }
314
                                if(NaviDataOkay)
317
                                if(NaviDataOkay)
315
                                {
318
                                {
316
                                        NaviDataOkay--;
319
                                        NaviDataOkay--;
317
                                        FCFlags &= ~FCFLAG_SPI_RX_ERR;
320
                                        FCFlags &= ~FCFLAG_SPI_RX_ERR;
318
                                }
321
                                }
319
                                else
322
                                else
320
                                {
323
                                {
321
                                        GPS_Nick = 0;
324
                                        GPS_Nick = 0;
322
                                        GPS_Roll = 0;
325
                                        GPS_Roll = 0;
323
                                        if(!beeptime) FCFlags |= FCFLAG_SPI_RX_ERR;
326
                                        if(!beeptime) FCFlags |= FCFLAG_SPI_RX_ERR;
324
                                }
327
                                }
325
                           if(UBat < BattLowVoltageWarning)
328
                           if(UBat < BattLowVoltageWarning)
326
                                {
329
                                {
327
                                        FCFlags |= FCFLAG_LOWBAT;
330
                                        FCFlags |= FCFLAG_LOWBAT;
328
                                        if(BeepMuster == 0xffff)
331
                                        if(BeepMuster == 0xffff)
329
                                        {
332
                                        {
330
                                                beeptime = 6000;
333
                                                beeptime = 6000;
331
                                                BeepMuster = 0x0300;
334
                                                BeepMuster = 0x0300;
332
                                        }
335
                                        }
333
                                }
336
                                }
334
                                else if(!beeptime) FCFlags &= ~FCFLAG_LOWBAT;
337
                                else if(!beeptime) FCFlags &= ~FCFLAG_LOWBAT;
335
 
338
 
336
                                SPI_StartTransmitPacket();
339
                                SPI_StartTransmitPacket();
337
                                SendSPI = 4;
340
                                SendSPI = 4;
338
                                if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden
341
                                if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden
339
                                else
342
                                else
340
                if(++second == 49)
343
                if(++second == 49)
341
                                 {
344
                                 {
342
                                   second = 0;
345
                                   second = 0;
343
                                   FlugSekunden++;
346
                                   FlugSekunden++;
344
                                 }
347
                                 }
345
 
348
 
346
                                if(++timer2 == 2930)  // eine Minute
349
                                if(++timer2 == 2930)  // eine Minute
347
                                 {
350
                                 {
348
                                   timer2 = 0;
351
                                   timer2 = 0;
349
                   FlugMinuten++;
352
                   FlugMinuten++;
350
                       FlugMinutenGesamt++;
353
                       FlugMinutenGesamt++;
351
                       SetParamWord(PID_FLIGHT_MINUTES_TOTAL, FlugMinutenGesamt);
354
                       SetParamWord(PID_FLIGHT_MINUTES_TOTAL, FlugMinutenGesamt);
352
                                   SetParamWord(PID_FLIGHT_MINUTES, FlugMinuten);
355
                                   SetParamWord(PID_FLIGHT_MINUTES, FlugMinuten);
353
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
356
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
354
                             }
357
                             }
355
                        }
358
                        }
356
           LED_Update();
359
           LED_Update();
357
           Capacity_Update();
360
           Capacity_Update();
358
          }
361
          }
359
     if(!SendSPI) { SPI_TransmitByte(); }
362
     if(!SendSPI) { SPI_TransmitByte(); }
360
    }
363
    }
361
 return (1);
364
 return (1);
362
}
365
}
363
 
366
 
364
 
367
 
365
 
368