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