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