Subversion Repositories FlightCtrl

Rev

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

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