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