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