Subversion Repositories FlightCtrl

Rev

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

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