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