Subversion Repositories FlightCtrl

Rev

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

Rev 1912 Rev 1913
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
 
-
 
54
 
-
 
-
 
53
unsigned char DisableRcOffBeeping = 0;
55
unsigned char PlatinenVersion = 10;
54
unsigned char PlatinenVersion = 10;
56
unsigned char SendVersionToNavi = 1;
55
unsigned char SendVersionToNavi = 1;
57
unsigned char BattLowVoltageWarning = 94;
56
unsigned char BattLowVoltageWarning = 94;
58
unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0;
57
unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0;
59
unsigned int FlugSekunden = 0;
58
unsigned int FlugSekunden = 0;
60
pVoidFnct_pVoidFnctChar_const_fmt _printf_P;
59
pVoidFnct_pVoidFnctChar_const_fmt _printf_P;
61
unsigned char FoundMotors = 0;
60
unsigned char FoundMotors = 0;
62
unsigned char JetiBeep = 0; // to allow any Morse-Beeping of the Jeti-Box
61
unsigned char JetiBeep = 0; // to allow any Morse-Beeping of the Jeti-Box
63
 
62
 
64
void CalMk3Mag(void)
63
void CalMk3Mag(void)
65
{
64
{
66
 static unsigned char stick = 1;
65
 static unsigned char stick = 1;
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
void LipoDetection(unsigned char print)
82
void LipoDetection(unsigned char print)
84
{
83
{
85
        #define MAX_CELL_VOLTAGE 43 // max cell volatage for LiPO
84
        #define MAX_CELL_VOLTAGE 43 // max cell volatage for LiPO
86
        unsigned int timer, cells;
85
        unsigned int timer, cells;
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
                // up to 6s LiPo, less than 2s is technical impossible
91
                // up to 6s LiPo, less than 2s is technical impossible
93
                for(cells = 2; cells < 7; cells++)
92
                for(cells = 2; cells < 7; cells++)
94
                {
93
                {
95
                        if(UBat < cells * MAX_CELL_VOLTAGE) break;
94
                        if(UBat < cells * MAX_CELL_VOLTAGE) break;
96
                }
95
                }
97
 
96
 
98
                BattLowVoltageWarning = cells * EE_Parameter.UnterspannungsWarnung;
97
                BattLowVoltageWarning = cells * EE_Parameter.UnterspannungsWarnung;
99
                if(print)
98
                if(print)
100
                {
99
                {
101
                        Piep(cells, 200);
100
                        Piep(cells, 200);
102
                        printf(" %d Cells ", cells);
101
                        printf(" %d Cells ", cells);
103
                }
102
                }
104
        }
103
        }
105
        else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
104
        else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
106
        if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
105
        if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
107
}
106
}
108
 
107
 
109
//############################################################################
108
//############################################################################
110
//Hauptprogramm
109
//Hauptprogramm
111
int main (void)
110
int main (void)
112
//############################################################################
111
//############################################################################
113
{
112
{
114
        unsigned int timer,i,timer2 = 0, timerPolling;
113
        unsigned int timer,i,timer2 = 0, timerPolling;
115
 
114
 
116
    DDRB  = 0x00;
115
    DDRB  = 0x00;
117
    PORTB = 0x00;
116
    PORTB = 0x00;
118
    for(timer = 0; timer < 1000; timer++); // verzögern
117
    for(timer = 0; timer < 1000; timer++); // verzögern
119
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
118
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
120
        PlatinenVersion = 21;
119
        PlatinenVersion = 21;
121
#else
120
#else
122
        if(PINB & 0x01)
121
        if(PINB & 0x01)
123
     {
122
     {
124
      if(PINB & 0x02) PlatinenVersion = 13;
123
      if(PINB & 0x02) PlatinenVersion = 13;
125
       else           PlatinenVersion = 11;
124
       else           PlatinenVersion = 11;
126
     }
125
     }
127
    else
126
    else
128
     {
127
     {
129
      if(PINB & 0x02) PlatinenVersion = 20;
128
      if(PINB & 0x02) PlatinenVersion = 20;
130
       else           PlatinenVersion = 10;
129
       else           PlatinenVersion = 10;
131
     }
130
     }
132
#endif
131
#endif
133
    DDRC  = 0x81; // SCL
132
    DDRC  = 0x81; // SCL
134
    DDRC  |=0x40; // HEF4017 Reset
133
    DDRC  |=0x40; // HEF4017 Reset
135
    PORTC = 0xff; // Pullup SDA
134
    PORTC = 0xff; // Pullup SDA
136
    DDRB  = 0x1B; // LEDs und Druckoffset
135
    DDRB  = 0x1B; // LEDs und Druckoffset
137
    PORTB = 0x01; // LED_Rot
136
    PORTB = 0x01; // LED_Rot
138
    DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
137
    DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
139
        PORTD = 0x47; // LED
138
        PORTD = 0x47; // LED
140
    HEF4017R_ON;
139
    HEF4017R_ON;
141
    MCUSR &=~(1<<WDRF);
140
    MCUSR &=~(1<<WDRF);
142
    WDTCSR |= (1<<WDCE)|(1<<WDE);
141
    WDTCSR |= (1<<WDCE)|(1<<WDE);
143
    WDTCSR = 0;
142
    WDTCSR = 0;
144
 
143
 
145
    beeptime = 2500;
144
    beeptime = 2500;
146
        StickGier = 0; PPM_in[K_GAS] = 0; StickRoll = 0; StickNick = 0;
145
        StickGier = 0; PPM_in[K_GAS] = 0; StickRoll = 0; StickNick = 0;
147
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1220; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
146
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1220; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
148
    ROT_OFF;
147
    ROT_OFF;
149
 
148
 
150
    Timer_Init();
149
    Timer_Init();
151
        TIMER2_Init();
150
        TIMER2_Init();
152
        UART_Init();
151
        UART_Init();
153
    rc_sum_init();
152
    rc_sum_init();
154
        ADC_Init();
153
        ADC_Init();
155
        I2C_Init(1);
154
        I2C_Init(1);
156
        SPI_MasterInit();
155
        SPI_MasterInit();
157
        Capacity_Init();
156
        Capacity_Init();
158
        LIBFC_Init();
157
        LIBFC_Init();
159
        GRN_ON;
158
        GRN_ON;
160
    sei();
159
    sei();
161
        ParamSet_Init();
160
        ParamSet_Init();
162
 
161
 
163
 
162
 
164
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
163
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
165
// + Check connected BL-Ctrls
164
// + Check connected BL-Ctrls
166
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
165
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
167
        // Check connected BL-Ctrls
166
        // Check connected BL-Ctrls
168
        BLFlags |= BLFLAG_READ_VERSION;
167
        BLFlags |= BLFLAG_READ_VERSION;
169
        motor_read = 0;  // read the first I2C-Data
168
        motor_read = 0;  // read the first I2C-Data
170
        SendMotorData();
169
        SendMotorData();
171
        timer = SetDelay(500);
170
        timer = SetDelay(500);
172
        while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
171
        while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
173
 
172
 
174
    printf("\n\rFound BL-Ctrl: ");
173
    printf("\n\rFound BL-Ctrl: ");
175
    timer = SetDelay(4000);
174
    timer = SetDelay(4000);
176
        for(i=0; i < MAX_MOTORS; i++)
175
        for(i=0; i < MAX_MOTORS; i++)
177
        {
176
        {
178
                SendMotorData();
177
                SendMotorData();
179
                while(!(BLFlags & BLFLAG_TX_COMPLETE)  && !CheckDelay(timer)); //wait for complete transfer
178
                while(!(BLFlags & BLFLAG_TX_COMPLETE)  && !CheckDelay(timer)); //wait for complete transfer
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) )
181
                        while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) )
183
                        {
182
                        {
184
                                SendMotorData();
183
                                SendMotorData();
185
                                while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
184
                                while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
186
                        }
185
                        }
187
                }
186
                }
188
                if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
187
                if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
189
                {
188
                {
190
                        printf("%d",i+1);
189
                        printf("%d",i+1);
191
                        FoundMotors++;
190
                        FoundMotors++;
192
//                      if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new) ");
191
//                      if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new) ");
193
                }
192
                }
194
        }
193
        }
195
        for(i=0; i < MAX_MOTORS; i++)
194
        for(i=0; i < MAX_MOTORS; i++)
196
        {
195
        {
197
                if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
196
                if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
198
                {
197
                {
199
                        printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
198
                        printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
200
                        ServoActive = 2; // just in case the FC would be used as camera-stabilizer
199
                        ServoActive = 2; // just in case the FC would be used as camera-stabilizer
201
                }
200
                }
202
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
201
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
203
        }
202
        }
204
        printf("\n\r===================================");
203
        printf("\n\r===================================");
205
 
204
 
206
    if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER;
205
    if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER;
207
 
206
 
208
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
207
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
209
        {
208
        {
210
                printf("\n\rCalibrating pressure sensor..");
209
                printf("\n\rCalibrating pressure sensor..");
211
                timer = SetDelay(1000);
210
                timer = SetDelay(1000);
212
                SucheLuftruckOffset();
211
                SucheLuftruckOffset();
213
                while (!CheckDelay(timer));
212
                while (!CheckDelay(timer));
214
                printf("OK\n\r");
213
                printf("OK\n\r");
215
        }
214
        }
216
 
215
 
217
        SetNeutral(0);
216
        SetNeutral(0);
218
 
217
 
219
        ROT_OFF;
218
        ROT_OFF;
220
 
219
 
221
    beeptime = 2000;
220
    beeptime = 2000;
222
    ExternControl.Digital[0] = 0x55;
221
    ExternControl.Digital[0] = 0x55;
223
 
222
 
224
 
223
 
225
        FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1);
224
        FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1);
226
        FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1);
225
        FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1);
227
 
226
 
228
        if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF))
227
        if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF))
229
        {
228
        {
230
                FlugMinuten = 0;
229
                FlugMinuten = 0;
231
                FlugMinutenGesamt = 0;
230
                FlugMinutenGesamt = 0;
232
        }
231
        }
233
    printf("\n\rFlight-time %u min  Total:%u min", FlugMinuten, FlugMinutenGesamt);
232
    printf("\n\rFlight-time %u min  Total:%u min", FlugMinuten, FlugMinutenGesamt);
234
 
233
 
235
        printf("\n\rControl: ");
234
        printf("\n\rControl: ");
236
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
235
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
237
        else printf("Normal (ACC-Mode)");
236
        else printf("Normal (ACC-Mode)");
238
 
237
 
239
    LcdClear();
238
    LcdClear();
240
    I2CTimeout = 5000;
239
    I2CTimeout = 5000;
241
    WinkelOut.Orientation = 1;
240
    WinkelOut.Orientation = 1;
242
    LipoDetection(1);
241
    LipoDetection(1);
243
 
242
 
244
        LIBFC_ReceiverInit(EE_Parameter.Receiver);
243
        LIBFC_ReceiverInit(EE_Parameter.Receiver);
245
 
244
 
246
        printf("\n\r===================================\n\r");
245
        printf("\n\r===================================\n\r");
247
        //SpektrumBinding();
246
        //SpektrumBinding();
248
    timer = SetDelay(2000);
247
    timer = SetDelay(2000);
249
        timerPolling = SetDelay(250);
248
        timerPolling = SetDelay(250);
250
 
249
 
251
        Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt);   // Note: this won't waste flash memory, if #DEBUG is not active
250
        Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt);   // Note: this won't waste flash memory, if #DEBUG is not active
252
    DebugOut.Status[0] = 0x01 | 0x02;
251
    DebugOut.Status[0] = 0x01 | 0x02;
253
        JetiBeep = 0;
252
        JetiBeep = 0;
-
 
253
    if(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING)   DisableRcOffBeeping = 1;
254
        while (1)
254
        while (1)
255
        {
255
        {
256
       
256
       
257
        if (JetiUpdateModeActive) while (1);
257
        if (JetiUpdateModeActive) while (1);
258
 
258
 
259
       
259
       
260
        if(CheckDelay(timerPolling))
260
        if(CheckDelay(timerPolling))
261
        {
261
        {
262
          timerPolling = SetDelay(1);
262
          timerPolling = SetDelay(1);
263
          LIBFC_Polling();
263
          LIBFC_Polling();
264
        }
264
        }
265
        if(UpdateMotor && AdReady)      // ReglerIntervall
265
        if(UpdateMotor && AdReady)      // ReglerIntervall
266
            {
266
            {
267
                   
267
                   
268
                        UpdateMotor=0;    
268
                        UpdateMotor=0;    
269
            if(WinkelOut.CalcState) CalMk3Mag();
269
            if(WinkelOut.CalcState) CalMk3Mag();
270
            else  MotorRegler();
270
            else  MotorRegler();
271
                        SendMotorData();
271
                        SendMotorData();
272
            ROT_OFF;
272
            ROT_OFF;
273
            if(SenderOkay)  { SenderOkay--; VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM; }
273
            if(SenderOkay)  { SenderOkay--; VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM; }
274
                        else
274
                        else
275
                        {
275
                        {
276
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
276
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
277
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
277
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
278
                                VersionInfo.HardwareError[1] |= FC_ERROR1_PPM;
278
                                VersionInfo.HardwareError[1] |= FC_ERROR1_PPM;
279
                        }
279
                        }
280
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
280
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
281
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
281
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
282
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
282
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
283
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
283
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
284
            if(!--I2CTimeout || MissingMotor)
284
            if(!--I2CTimeout || MissingMotor)
285
                {
285
                {
286
                  if(!I2CTimeout)
286
                  if(!I2CTimeout)
287
                                   {
287
                                   {
288
                                    I2C_Reset();
288
                                    I2C_Reset();
289
                    I2CTimeout = 5;
289
                    I2CTimeout = 5;
290
                                        DebugOut.Analog[28]++; // I2C-Error
290
                                        DebugOut.Analog[28]++; // I2C-Error
291
                                        VersionInfo.HardwareError[1] |= FC_ERROR1_I2C;
291
                                        VersionInfo.HardwareError[1] |= FC_ERROR1_I2C;
292
                                        DebugOut.Status[1] |= 0x02; // BL-Error-Status
292
                                        DebugOut.Status[1] |= 0x02; // BL-Error-Status
293
                                   }
293
                                   }
294
                  if((BeepMuster == 0xffff) && MotorenEin)
294
                  if((BeepMuster == 0xffff) && MotorenEin)
295
                   {
295
                   {
296
                    beeptime = 10000;
296
                    beeptime = 10000;
297
                    BeepMuster = 0x0080;
297
                    BeepMuster = 0x0080;
298
                   }
298
                   }
299
                }
299
                }
300
            else
300
            else
301
                {
301
                {
302
                 ROT_OFF;
302
                 ROT_OFF;
303
                                 if(!beeptime)
303
                                 if(!beeptime)
304
                                  {
304
                                  {
305
                                   VersionInfo.HardwareError[1] &= ~FC_ERROR1_I2C;
305
                                   VersionInfo.HardwareError[1] &= ~FC_ERROR1_I2C;
306
                                  }
306
                                  }
307
                }
307
                }
308
          if(!UpdateMotor)
308
          if(!UpdateMotor)
309
                   {
309
                   {
310
                        if(CalculateServoSignals) CalculateServo();
310
                        if(CalculateServoSignals) CalculateServo();
311
                        DatenUebertragung();
311
                        DatenUebertragung();
312
                        BearbeiteRxDaten();
312
                        BearbeiteRxDaten();
313
                        if(CheckDelay(timer))
313
                        if(CheckDelay(timer))
314
                        {
314
                        {
315
                                static unsigned char second;
315
                                static unsigned char second;
316
                                timer += 20; // 20 ms interval
316
                                timer += 20; // 20 ms interval
317
                                if(MissingMotor)
317
                                if(MissingMotor)
318
                                 {
318
                                 {
319
                                  VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING;
319
                                  VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING;
320
                                  DebugOut.Status[1] |= 0x02; // BL-Error-Status
320
                                  DebugOut.Status[1] |= 0x02; // BL-Error-Status
321
                                 }
321
                                 }
322
                                 else
322
                                 else
323
                                 {
323
                                 {
324
                                   VersionInfo.HardwareError[1] &= ~FC_ERROR1_BL_MISSING;
324
                                   VersionInfo.HardwareError[1] &= ~FC_ERROR1_BL_MISSING;
325
                                   if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status
325
                                   if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status
326
                                 }
326
                                 }
327
 
327
 
328
                            if(I2CTimeout > 6) VersionInfo.HardwareError[1] &= ~FC_ERROR1_I2C;
328
                            if(I2CTimeout > 6) VersionInfo.HardwareError[1] &= ~FC_ERROR1_I2C;
329
 
329
 
330
                                if(PcZugriff) PcZugriff--;
330
                                if(PcZugriff) PcZugriff--;
331
                                else
331
                                else
332
                                {
332
                                {
333
                                        ExternControl.Config = 0;
333
                                        ExternControl.Config = 0;
334
                                        ExternStickNick = 0;
334
                                        ExternStickNick = 0;
335
                                        ExternStickRoll = 0;
335
                                        ExternStickRoll = 0;
336
                                        ExternStickGier = 0;
336
                                        ExternStickGier = 0;
337
                                        if(BeepMuster == 0xffff && SenderOkay == 0)
337
                                        if(!SenderOkay)
338
                                        {
338
                                        {
-
 
339
                                          if(BeepMuster == 0xffff && !DisableRcOffBeeping)
-
 
340
                                          {
339
                                                beeptime = 15000;
341
                                                  beeptime = 15000;
340
                                                BeepMuster = 0x0c00;
342
                                                  BeepMuster = 0x0c00;
341
                                        }
343
                                          }
-
 
344
                                        } else DisableRcOffBeeping = 0;
342
                                }
345
                                }
343
                                if(NaviDataOkay > 200)
346
                                if(NaviDataOkay > 200)
344
                                {
347
                                {
345
                                        NaviDataOkay--;
348
                                        NaviDataOkay--;
346
                                        VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX;
349
                                        VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX;
347
                                }
350
                                }
348
                                else
351
                                else
349
                                {
352
                                {
350
                                        if(NC_Version.Compatible)
353
                                        if(NC_Version.Compatible)
351
                                         {
354
                                         {
352
                                                VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX;
355
                                                VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX;
353
                       if(BeepMuster == 0xffff && MotorenEin)
356
                       if(BeepMuster == 0xffff && MotorenEin)
354
                                                {
357
                                                {
355
                                                        beeptime = 15000;
358
                                                        beeptime = 15000;
356
                                                        BeepMuster = 0xA800;
359
                                                        BeepMuster = 0xA800;
357
                                                }
360
                                                }
358
                                         }
361
                                         }
359
                                        GPS_Nick = 0;
362
                                        GPS_Nick = 0;
360
                                        GPS_Roll = 0;
363
                                        GPS_Roll = 0;
361
                                        GPS_AidMode = 0;
364
                                        GPS_AidMode = 0;
362
                                        //if(!beeptime)
365
                                        //if(!beeptime)
363
                    FromNaviCtrl.CompassValue = -1;
366
                    FromNaviCtrl.CompassValue = -1;
364
                    NaviDataOkay = 0;
367
                    NaviDataOkay = 0;
365
                                }
368
                                }
366
                           if(UBat < BattLowVoltageWarning)
369
                           if(UBat < BattLowVoltageWarning)
367
                                {
370
                                {
368
                                        FC_StatusFlags |= FC_STATUS_LOWBAT;
371
                                        FC_StatusFlags |= FC_STATUS_LOWBAT;
369
                                        if(BeepMuster == 0xffff)
372
                                        if(BeepMuster == 0xffff)
370
                                        {
373
                                        {
371
                                                beeptime = 6000;
374
                                                beeptime = 6000;
372
                                                BeepMuster = 0x0300;
375
                                                BeepMuster = 0x0300;
373
                                        }
376
                                        }
374
                                }
377
                                }
375
                                else if(!beeptime) FC_StatusFlags &= ~FC_STATUS_LOWBAT;
378
                                else if(!beeptime) FC_StatusFlags &= ~FC_STATUS_LOWBAT;
376
 
379
 
377
                                SPI_StartTransmitPacket();
380
                                SPI_StartTransmitPacket();
378
                                SendSPI = 4;
381
                                SendSPI = 4;
379
                                if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden
382
                                if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden
380
                                else
383
                                else
381
                if(++second == 49)
384
                if(++second == 49)
382
                                 {
385
                                 {
383
                                   second = 0;
386
                                   second = 0;
384
                                   FlugSekunden++;
387
                                   FlugSekunden++;
385
                                 }
388
                                 }
386
                                if(++timer2 == 2930)  // eine Minute
389
                                if(++timer2 == 2930)  // eine Minute
387
                                 {
390
                                 {
388
                                   timer2 = 0;
391
                                   timer2 = 0;
389
                   FlugMinuten++;
392
                   FlugMinuten++;
390
                       FlugMinutenGesamt++;
393
                       FlugMinutenGesamt++;
391
                   SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256);
394
                   SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256);
392
                   SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256);
395
                   SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256);
393
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256);
396
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256);
394
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256);
397
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256);
395
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
398
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
396
                             }
399
                             }
397
                        }
400
                        }
398
           LED_Update();
401
           LED_Update();
399
           Capacity_Update();
402
           Capacity_Update();
400
           } //else DebugOut.Analog[26]++;
403
           } //else DebugOut.Analog[26]++;
401
          }
404
          }
402
     if(!SendSPI) { SPI_TransmitByte(); }
405
     if(!SendSPI) { SPI_TransmitByte(); }
403
    }
406
    }
404
 return (1);
407
 return (1);
405
}
408
}
406
 
409
 
407
 
410
 
408
 
411