Rev 2034 | Rev 2146 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2034 | Rev 2050 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) Holger Buss, Ingo Busker |
- | |
3 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
- | |
4 | // + www.MikroKopter.com |
2 | // + www.MikroKopter.com |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 4 | // + Software Nutzungsbedingungen (english version: see below) |
|
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
5 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist. |
6 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
7 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
8 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
9 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
- | |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
11 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
12 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
14 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
17 | // + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
15 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
16 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
18 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
21 | // + Benutzung auf eigene Gefahr |
19 | // + des Mitverschuldens offen. |
- | 20 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
|
- | 21 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
|
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
22 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
- | 23 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
|
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
24 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
25 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
25 | // + mit unserer Zustimmung zulässig |
26 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
- | 27 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
|
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
29 | // + Software LICENSING TERMS |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
31 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
30 | // + this list of conditions and the following disclaimer. |
32 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
33 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
32 | // + from this software without specific prior written permission. |
34 | // + The Software may only be used with the Licensor's products. |
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
35 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
34 | // + for non-commercial use (directly or indirectly) |
- | |
35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
36 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
36 | // + with our written permission |
37 | // + agreement shall be the property of the Licensor. |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
38 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
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 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
40 | // + The customer shall be responsible for taking reasonable precautions |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
41 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
42 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
43 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
44 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
45 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
46 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
47 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
48 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
48 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
49 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
50 | // + #### END OF LICENSING TERMS #### |
- | 51 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
|
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | #include "main.h" |
53 | #include "main.h" |
53 | unsigned char DisableRcOffBeeping = 0; |
54 | unsigned char DisableRcOffBeeping = 0; |
54 | unsigned char PlatinenVersion = 10; |
55 | unsigned char PlatinenVersion = 10; |
55 | unsigned char BattLowVoltageWarning = 94; |
56 | unsigned char BattLowVoltageWarning = 94; |
56 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
57 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
57 | unsigned int FlugSekunden = 0; |
58 | unsigned int FlugSekunden = 0; |
58 | pVoidFnct_pVoidFnctChar_const_fmt _printf_P; |
59 | pVoidFnct_pVoidFnctChar_const_fmt _printf_P; |
59 | unsigned char FoundMotors = 0; |
60 | unsigned char FoundMotors = 0; |
60 | unsigned char JetiBeep = 0; // to allow any Morse-Beeping of the Jeti-Box |
61 | unsigned char JetiBeep = 0; // to allow any Morse-Beeping of the Jeti-Box |
61 | 62 | ||
62 | void PrintLine(void) |
63 | void PrintLine(void) |
63 | { |
64 | { |
64 | printf("\n\r==================================="); |
65 | printf("\n\r==================================="); |
65 | } |
66 | } |
66 | 67 | ||
67 | 68 | ||
68 | void CalMk3Mag(void) |
69 | void CalMk3Mag(void) |
69 | { |
70 | { |
70 | static unsigned char stick = 1; |
71 | static unsigned char stick = 1; |
71 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
72 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
72 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
73 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
73 | { |
74 | { |
74 | stick = 1; |
75 | stick = 1; |
75 | WinkelOut.CalcState++; |
76 | WinkelOut.CalcState++; |
76 | if(WinkelOut.CalcState > 4) |
77 | if(WinkelOut.CalcState > 4) |
77 | { |
78 | { |
78 | // WinkelOut.CalcState = 0; // in Uart.c |
79 | // WinkelOut.CalcState = 0; // in Uart.c |
79 | beeptime = 1000; |
80 | beeptime = 1000; |
80 | } |
81 | } |
81 | else Piep(WinkelOut.CalcState,150); |
82 | else Piep(WinkelOut.CalcState,150); |
82 | } |
83 | } |
83 | DebugOut.Analog[19] = WinkelOut.CalcState; |
84 | DebugOut.Analog[19] = WinkelOut.CalcState; |
84 | } |
85 | } |
85 | 86 | ||
86 | 87 | ||
87 | void LipoDetection(unsigned char print) |
88 | void LipoDetection(unsigned char print) |
88 | { |
89 | { |
89 | #define MAX_CELL_VOLTAGE 43 // max cell volatage for LiPO |
90 | #define MAX_CELL_VOLTAGE 43 // max cell volatage for LiPO |
90 | unsigned int timer, cells; |
91 | unsigned int timer, cells; |
91 | if(print) printf("\n\rBatt:"); |
92 | if(print) printf("\n\rBatt:"); |
92 | if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung |
93 | if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung |
93 | { |
94 | { |
94 | timer = SetDelay(500); |
95 | timer = SetDelay(500); |
95 | if(print) while (!CheckDelay(timer)); |
96 | if(print) while (!CheckDelay(timer)); |
96 | // up to 6s LiPo, less than 2s is technical impossible |
97 | // up to 6s LiPo, less than 2s is technical impossible |
97 | for(cells = 2; cells < 7; cells++) |
98 | for(cells = 2; cells < 7; cells++) |
98 | { |
99 | { |
99 | if(UBat < cells * MAX_CELL_VOLTAGE) break; |
100 | if(UBat < cells * MAX_CELL_VOLTAGE) break; |
100 | } |
101 | } |
101 | 102 | ||
102 | BattLowVoltageWarning = cells * EE_Parameter.UnterspannungsWarnung; |
103 | BattLowVoltageWarning = cells * EE_Parameter.UnterspannungsWarnung; |
103 | if(print) |
104 | if(print) |
104 | { |
105 | { |
105 | Piep(cells, 200); |
106 | Piep(cells, 200); |
106 | printf(" %d Cells ", cells); |
107 | printf(" %d Cells ", cells); |
107 | } |
108 | } |
108 | } |
109 | } |
109 | else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
110 | else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
110 | if(print) printf(" Low warning: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
111 | if(print) printf(" Low warning: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
111 | } |
112 | } |
112 | 113 | ||
113 | //############################################################################ |
114 | //############################################################################ |
114 | //Hauptprogramm |
115 | //Hauptprogramm |
115 | int main (void) |
116 | int main (void) |
116 | //############################################################################ |
117 | //############################################################################ |
117 | { |
118 | { |
118 | unsigned int timer,i,timer2 = 0, timerPolling; |
119 | unsigned int timer,i,timer2 = 0, timerPolling; |
119 | 120 | ||
120 | DDRB = 0x00; |
121 | DDRB = 0x00; |
121 | PORTB = 0x00; |
122 | PORTB = 0x00; |
122 | for(timer = 0; timer < 1000; timer++); // verzögern |
123 | for(timer = 0; timer < 1000; timer++); // verzögern |
123 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
124 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
124 | PlatinenVersion = 21; |
125 | PlatinenVersion = 21; |
125 | #else |
126 | #else |
126 | if(PINB & 0x01) |
127 | if(PINB & 0x01) |
127 | { |
128 | { |
128 | if(PINB & 0x02) PlatinenVersion = 13; |
129 | if(PINB & 0x02) PlatinenVersion = 13; |
129 | else PlatinenVersion = 11; |
130 | else PlatinenVersion = 11; |
130 | } |
131 | } |
131 | else |
132 | else |
132 | { |
133 | { |
133 | if(PINB & 0x02) PlatinenVersion = 20; |
134 | if(PINB & 0x02) PlatinenVersion = 20; |
134 | else PlatinenVersion = 10; |
135 | else PlatinenVersion = 10; |
135 | } |
136 | } |
136 | #endif |
137 | #endif |
137 | DDRC = 0x81; // SCL |
138 | DDRC = 0x81; // SCL |
138 | DDRC |=0x40; // HEF4017 Reset |
139 | DDRC |=0x40; // HEF4017 Reset |
139 | PORTC = 0xff; // Pullup SDA |
140 | PORTC = 0xff; // Pullup SDA |
140 | DDRB = 0x1B; // LEDs und Druckoffset |
141 | DDRB = 0x1B; // LEDs und Druckoffset |
141 | PORTB = 0x01; // LED_Rot |
142 | PORTB = 0x01; // LED_Rot |
142 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
143 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
143 | PORTD = 0x47; // LED |
144 | PORTD = 0x47; // LED |
144 | HEF4017R_ON; |
145 | HEF4017R_ON; |
145 | MCUSR &=~(1<<WDRF); |
146 | MCUSR &=~(1<<WDRF); |
146 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
147 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
147 | WDTCSR = 0; |
148 | WDTCSR = 0; |
148 | 149 | ||
149 | beeptime = 2500; |
150 | beeptime = 2500; |
150 | StickGier = 0; PPM_in[K_GAS] = 0; StickRoll = 0; StickNick = 0; |
151 | StickGier = 0; PPM_in[K_GAS] = 0; StickRoll = 0; StickNick = 0; |
151 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1220; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
152 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1220; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
152 | ROT_OFF; |
153 | ROT_OFF; |
153 | 154 | ||
154 | Timer_Init(); |
155 | Timer_Init(); |
155 | TIMER2_Init(); |
156 | TIMER2_Init(); |
156 | UART_Init(); |
157 | UART_Init(); |
157 | rc_sum_init(); |
158 | rc_sum_init(); |
158 | ADC_Init(); |
159 | ADC_Init(); |
159 | I2C_Init(1); |
160 | I2C_Init(1); |
160 | SPI_MasterInit(); |
161 | SPI_MasterInit(); |
161 | Capacity_Init(); |
162 | Capacity_Init(); |
162 | LIBFC_Init(); |
163 | LIBFC_Init(); |
163 | GRN_ON; |
164 | GRN_ON; |
164 | sei(); |
165 | sei(); |
165 | ParamSet_Init(); |
166 | ParamSet_Init(); |
166 | 167 | ||
167 | 168 | ||
168 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
169 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
169 | // + Check connected BL-Ctrls |
170 | // + Check connected BL-Ctrls |
170 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
171 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
171 | // Check connected BL-Ctrls |
172 | // Check connected BL-Ctrls |
172 | BLFlags |= BLFLAG_READ_VERSION; |
173 | BLFlags |= BLFLAG_READ_VERSION; |
173 | motor_read = 0; // read the first I2C-Data |
174 | motor_read = 0; // read the first I2C-Data |
174 | SendMotorData(); |
175 | SendMotorData(); |
175 | timer = SetDelay(500); |
176 | timer = SetDelay(500); |
176 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
177 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
177 | 178 | ||
178 | printf("\n\rFound BL-Ctrl: "); |
179 | printf("\n\rFound BL-Ctrl: "); |
179 | timer = SetDelay(4000); |
180 | timer = SetDelay(4000); |
180 | for(i=0; i < MAX_MOTORS; i++) |
181 | for(i=0; i < MAX_MOTORS; i++) |
181 | { |
182 | { |
182 | SendMotorData(); |
183 | SendMotorData(); |
183 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
184 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
184 | if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up |
185 | if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up |
185 | { |
186 | { |
186 | while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) |
187 | while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) ) |
187 | { |
188 | { |
188 | SendMotorData(); |
189 | SendMotorData(); |
189 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
190 | while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer |
190 | } |
191 | } |
191 | } |
192 | } |
192 | if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) |
193 | if(Motor[i].State & MOTOR_STATE_PRESENT_MASK) |
193 | { |
194 | { |
194 | printf("%d",i+1); |
195 | printf("%d",i+1); |
195 | FoundMotors++; |
196 | FoundMotors++; |
196 | // if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new) "); |
197 | // if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new) "); |
197 | } |
198 | } |
198 | } |
199 | } |
199 | for(i=0; i < MAX_MOTORS; i++) |
200 | for(i=0; i < MAX_MOTORS; i++) |
200 | { |
201 | { |
201 | if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0) |
202 | if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0) |
202 | { |
203 | { |
203 | printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
204 | printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
204 | ServoActive = 2; // just in case the FC would be used as camera-stabilizer |
205 | ServoActive = 2; // just in case the FC would be used as camera-stabilizer |
205 | } |
206 | } |
206 | Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter |
207 | Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter |
207 | } |
208 | } |
208 | PrintLine();// ("\n\r==================================="); |
209 | PrintLine();// ("\n\r==================================="); |
209 | 210 | ||
210 | 211 | ||
211 | if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER; |
212 | if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER; |
212 | 213 | ||
213 | //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
214 | //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
214 | { |
215 | { |
215 | printf("\n\rCalibrating pressure sensor.."); |
216 | printf("\n\rCalibrating pressure sensor.."); |
216 | timer = SetDelay(1000); |
217 | timer = SetDelay(1000); |
217 | SucheLuftruckOffset(); |
218 | SucheLuftruckOffset(); |
218 | while (!CheckDelay(timer)); |
219 | while (!CheckDelay(timer)); |
219 | printf("OK\n\r"); |
220 | printf("OK\n\r"); |
220 | } |
221 | } |
221 | 222 | ||
222 | SetNeutral(0); |
223 | SetNeutral(0); |
223 | 224 | ||
224 | ROT_OFF; |
225 | ROT_OFF; |
225 | 226 | ||
226 | beeptime = 2000; |
227 | beeptime = 2000; |
227 | ExternControl.Digital[0] = 0x55; |
228 | ExternControl.Digital[0] = 0x55; |
228 | 229 | ||
229 | 230 | ||
230 | FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1); |
231 | FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1); |
231 | FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1); |
232 | FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1); |
232 | 233 | ||
233 | if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF)) |
234 | if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF)) |
234 | { |
235 | { |
235 | FlugMinuten = 0; |
236 | FlugMinuten = 0; |
236 | FlugMinutenGesamt = 0; |
237 | FlugMinutenGesamt = 0; |
237 | } |
238 | } |
238 | printf("\n\rFlight-time %u min Total:%u min", FlugMinuten, FlugMinutenGesamt); |
239 | printf("\n\rFlight-time %u min Total:%u min", FlugMinuten, FlugMinutenGesamt); |
239 | 240 | ||
240 | LcdClear(); |
241 | LcdClear(); |
241 | I2CTimeout = 5000; |
242 | I2CTimeout = 5000; |
242 | WinkelOut.Orientation = 1; |
243 | WinkelOut.Orientation = 1; |
243 | LipoDetection(1); |
244 | LipoDetection(1); |
244 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
245 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
245 | PrintLine();// ("\n\r==================================="); |
246 | PrintLine();// ("\n\r==================================="); |
246 | //SpektrumBinding(); |
247 | //SpektrumBinding(); |
247 | timer = SetDelay(2000); |
248 | timer = SetDelay(2000); |
248 | timerPolling = SetDelay(250); |
249 | timerPolling = SetDelay(250); |
249 | 250 | ||
250 | Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt); // Note: this won't waste flash memory, if #DEBUG is not active |
251 | Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt); // Note: this won't waste flash memory, if #DEBUG is not active |
251 | DebugOut.Status[0] = 0x01 | 0x02; |
252 | DebugOut.Status[0] = 0x01 | 0x02; |
252 | JetiBeep = 0; |
253 | JetiBeep = 0; |
253 | if(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING) DisableRcOffBeeping = 1; |
254 | if(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING) DisableRcOffBeeping = 1; |
254 | while (1) |
255 | while (1) |
255 | { |
256 | { |
256 | if(ReceiverUpdateModeActive) while (1) PORTC &= ~(1<<7); // Beeper off |
257 | if(ReceiverUpdateModeActive) while (1) PORTC &= ~(1<<7); // Beeper off |
257 | 258 | ||
258 | //GRN_ON; |
259 | //GRN_ON; |
259 | if(UpdateMotor && AdReady) // ReglerIntervall |
260 | if(UpdateMotor && AdReady) // ReglerIntervall |
260 | { |
261 | { |
261 | //GRN_OFF; |
262 | //GRN_OFF; |
262 | UpdateMotor=0; |
263 | UpdateMotor=0; |
263 | if(WinkelOut.CalcState) CalMk3Mag(); |
264 | if(WinkelOut.CalcState) CalMk3Mag(); |
264 | else MotorRegler(); |
265 | else MotorRegler(); |
265 | SendMotorData(); |
266 | SendMotorData(); |
266 | ROT_OFF; |
267 | ROT_OFF; |
267 | if(SenderOkay) { SenderOkay--; /*VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM;*/ } |
268 | if(SenderOkay) { SenderOkay--; /*VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM;*/ } |
268 | else |
269 | else |
269 | { |
270 | { |
270 | TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
271 | TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
271 | PPM_in[0] = 0; // set RSSI to zero on data timeout |
272 | PPM_in[0] = 0; // set RSSI to zero on data timeout |
272 | VersionInfo.HardwareError[1] |= FC_ERROR1_PPM; |
273 | VersionInfo.HardwareError[1] |= FC_ERROR1_PPM; |
273 | } |
274 | } |
274 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
275 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
275 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
276 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
276 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
277 | //if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
277 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
278 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
278 | if(!--I2CTimeout || MissingMotor) |
279 | if(!--I2CTimeout || MissingMotor) |
279 | { |
280 | { |
280 | if(!I2CTimeout) |
281 | if(!I2CTimeout) |
281 | { |
282 | { |
282 | I2C_Reset(); |
283 | I2C_Reset(); |
283 | I2CTimeout = 5; |
284 | I2CTimeout = 5; |
284 | DebugOut.Analog[28]++; // I2C-Error |
285 | DebugOut.Analog[28]++; // I2C-Error |
285 | VersionInfo.HardwareError[1] |= FC_ERROR1_I2C; |
286 | VersionInfo.HardwareError[1] |= FC_ERROR1_I2C; |
286 | DebugOut.Status[1] |= 0x02; // BL-Error-Status |
287 | DebugOut.Status[1] |= 0x02; // BL-Error-Status |
287 | } |
288 | } |
288 | if((BeepMuster == 0xffff) && MotorenEin) |
289 | if((BeepMuster == 0xffff) && MotorenEin) |
289 | { |
290 | { |
290 | beeptime = 25000; |
291 | beeptime = 25000; |
291 | BeepMuster = 0x0080; |
292 | BeepMuster = 0x0080; |
292 | } |
293 | } |
293 | } |
294 | } |
294 | else |
295 | else |
295 | { |
296 | { |
296 | ROT_OFF; |
297 | ROT_OFF; |
297 | } |
298 | } |
298 | LIBFC_Polling(); |
299 | LIBFC_Polling(); |
299 | 300 | ||
300 | if(!UpdateMotor) |
301 | if(!UpdateMotor) |
301 | { |
302 | { |
302 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
303 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
303 | if(NewSBusData) ProcessSBus(); |
304 | if(NewSBusData) ProcessSBus(); |
304 | else |
305 | else |
305 | #endif |
306 | #endif |
306 | { |
307 | { |
307 | if(CalculateServoSignals) CalculateServo(); |
308 | if(CalculateServoSignals) CalculateServo(); |
308 | DatenUebertragung(); |
309 | DatenUebertragung(); |
309 | BearbeiteRxDaten(); |
310 | BearbeiteRxDaten(); |
310 | if(CheckDelay(timer)) |
311 | if(CheckDelay(timer)) |
311 | { |
312 | { |
312 | static unsigned char second; |
313 | static unsigned char second; |
313 | timer += 20; // 20 ms interval |
314 | timer += 20; // 20 ms interval |
314 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
315 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
315 | if(EE_Parameter.Receiver == RECEIVER_HOTT) HoTT_Menu(); |
316 | if(EE_Parameter.Receiver == RECEIVER_HOTT) HoTT_Menu(); |
316 | #endif |
317 | #endif |
317 | if(MissingMotor) |
318 | if(MissingMotor) |
318 | { |
319 | { |
319 | VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING; |
320 | VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING; |
320 | DebugOut.Status[1] |= 0x02; // BL-Error-Status |
321 | DebugOut.Status[1] |= 0x02; // BL-Error-Status |
321 | } |
322 | } |
322 | else |
323 | else |
323 | { |
324 | { |
324 | if(!beeptime) |
325 | if(!beeptime) |
325 | { |
326 | { |
326 | if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status |
327 | if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status |
327 | } |
328 | } |
328 | } |
329 | } |
329 | if(DisableRcOffBeeping) if(SenderOkay > 150) { DisableRcOffBeeping = 0; beeptime = 5000;}; |
330 | if(DisableRcOffBeeping) if(SenderOkay > 150) { DisableRcOffBeeping = 0; beeptime = 5000;}; |
330 | if(PcZugriff) PcZugriff--; |
331 | if(PcZugriff) PcZugriff--; |
331 | else |
332 | else |
332 | { |
333 | { |
333 | ExternControl.Config = 0; |
334 | ExternControl.Config = 0; |
334 | ExternStickNick = 0; |
335 | ExternStickNick = 0; |
335 | ExternStickRoll = 0; |
336 | ExternStickRoll = 0; |
336 | ExternStickGier = 0; |
337 | ExternStickGier = 0; |
337 | if(!SenderOkay) |
338 | if(!SenderOkay) |
338 | { |
339 | { |
339 | if(BeepMuster == 0xffff && DisableRcOffBeeping != 2) |
340 | if(BeepMuster == 0xffff && DisableRcOffBeeping != 2) |
340 | { |
341 | { |
341 | beeptime = 15000; |
342 | beeptime = 15000; |
342 | BeepMuster = 0x0c00; |
343 | BeepMuster = 0x0c00; |
343 | if(DisableRcOffBeeping) DisableRcOffBeeping = 2; |
344 | if(DisableRcOffBeeping) DisableRcOffBeeping = 2; |
344 | } |
345 | } |
345 | } |
346 | } |
346 | } |
347 | } |
347 | if(NaviDataOkay > 200) |
348 | if(NaviDataOkay > 200) |
348 | { |
349 | { |
349 | NaviDataOkay--; |
350 | NaviDataOkay--; |
350 | VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX; |
351 | VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX; |
351 | } |
352 | } |
352 | else |
353 | else |
353 | { |
354 | { |
354 | if(NC_Version.Compatible) |
355 | if(NC_Version.Compatible) |
355 | { |
356 | { |
356 | VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX; |
357 | VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX; |
357 | NC_ErrorCode = 9; // "ERR: no NC communication" |
358 | NC_ErrorCode = 9; // "ERR: no NC communication" |
358 | if(BeepMuster == 0xffff && MotorenEin) |
359 | if(BeepMuster == 0xffff && MotorenEin) |
359 | { |
360 | { |
360 | beeptime = 15000; |
361 | beeptime = 15000; |
361 | BeepMuster = 0xA800; |
362 | BeepMuster = 0xA800; |
362 | } |
363 | } |
363 | } |
364 | } |
364 | GPS_Nick = 0; |
365 | GPS_Nick = 0; |
365 | GPS_Roll = 0; |
366 | GPS_Roll = 0; |
366 | GPS_Aid_StickMultiplikator = 0; |
367 | GPS_Aid_StickMultiplikator = 0; |
367 | GPSInfo.Flags = 0; |
368 | GPSInfo.Flags = 0; |
368 | FromNaviCtrl.AccErrorN = 0; |
369 | FromNaviCtrl.AccErrorN = 0; |
369 | FromNaviCtrl.AccErrorR = 0; |
370 | FromNaviCtrl.AccErrorR = 0; |
370 | FromNaviCtrl.CompassValue = -1; |
371 | FromNaviCtrl.CompassValue = -1; |
371 | NaviDataOkay = 0; |
372 | NaviDataOkay = 0; |
372 | } |
373 | } |
373 | if(UBat < BattLowVoltageWarning) |
374 | if(UBat < BattLowVoltageWarning) |
374 | { |
375 | { |
375 | FC_StatusFlags |= FC_STATUS_LOWBAT; |
376 | FC_StatusFlags |= FC_STATUS_LOWBAT; |
376 | if(BeepMuster == 0xffff) |
377 | if(BeepMuster == 0xffff) |
377 | { |
378 | { |
378 | beeptime = 6000; |
379 | beeptime = 6000; |
379 | BeepMuster = 0x0300; |
380 | BeepMuster = 0x0300; |
380 | } |
381 | } |
381 | } |
382 | } |
382 | else if(!beeptime) FC_StatusFlags &= ~FC_STATUS_LOWBAT; |
383 | else if(!beeptime) FC_StatusFlags &= ~FC_STATUS_LOWBAT; |
383 | 384 | ||
384 | SPI_StartTransmitPacket(); |
385 | SPI_StartTransmitPacket(); |
385 | SendSPI = 4; |
386 | SendSPI = 4; |
386 | // +++++++++++++++++++++++++++++++++ |
387 | // +++++++++++++++++++++++++++++++++ |
387 | // Sekundentakt |
388 | // Sekundentakt |
388 | if(++second == 49) |
389 | if(++second == 49) |
389 | { |
390 | { |
390 | second = 0; |
391 | second = 0; |
391 | if(FC_StatusFlags & FC_STATUS_FLY) FlugSekunden++; |
392 | if(FC_StatusFlags & FC_STATUS_FLY) FlugSekunden++; |
392 | else |
393 | else |
393 | { |
394 | { |
394 | timer2 = 1450; // 0,5 Minuten aufrunden |
395 | timer2 = 1450; // 0,5 Minuten aufrunden |
395 | if(StartLuftdruck < Luftdruck) StartLuftdruck++; |
396 | if(StartLuftdruck < Luftdruck) StartLuftdruck++; |
396 | else |
397 | else |
397 | if(StartLuftdruck > Luftdruck) StartLuftdruck--; |
398 | if(StartLuftdruck > Luftdruck) StartLuftdruck--; |
398 | } |
399 | } |
399 | } |
400 | } |
400 | // +++++++++++++++++++++++++++++++++ |
401 | // +++++++++++++++++++++++++++++++++ |
401 | if(++timer2 == 2930) // eine Minute |
402 | if(++timer2 == 2930) // eine Minute |
402 | { |
403 | { |
403 | timer2 = 0; |
404 | timer2 = 0; |
404 | FlugMinuten++; |
405 | FlugMinuten++; |
405 | FlugMinutenGesamt++; |
406 | FlugMinutenGesamt++; |
406 | SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256); |
407 | SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256); |
407 | SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256); |
408 | SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256); |
408 | SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256); |
409 | SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256); |
409 | SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256); |
410 | SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256); |
410 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
411 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
411 | } |
412 | } |
412 | } |
413 | } |
413 | LED_Update(); |
414 | LED_Update(); |
414 | Capacity_Update(); |
415 | Capacity_Update(); |
415 | } //else DebugOut.Analog[26]++; |
416 | } //else DebugOut.Analog[26]++; |
416 | } |
417 | } |
417 | } |
418 | } |
418 | if(!SendSPI) { SPI_TransmitByte(); } |
419 | if(!SendSPI) { SPI_TransmitByte(); } |
419 | } |
420 | } |
420 | return (1); |
421 | return (1); |
421 | } |
422 | } |
422 | //DebugOut.Analog[16] |
423 | //DebugOut.Analog[16] |
423 | 424 | ||
424 | 425 |