Rev 1435 | Rev 1440 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1435 | Rev 1438 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) Holger Buss, Ingo Busker |
2 | // + Copyright (c) Holger Buss, Ingo Busker |
3 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
3 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
4 | // + www.MikroKopter.com |
4 | // + www.MikroKopter.com |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist. |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist. |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
17 | // + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
17 | // + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
21 | // + Benutzung auf eigene Gefahr |
21 | // + Benutzung auf eigene Gefahr |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
24 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
25 | // + mit unserer Zustimmung zulässig |
25 | // + mit unserer Zustimmung zulässig |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
30 | // + this list of conditions and the following disclaimer. |
30 | // + this list of conditions and the following disclaimer. |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
32 | // + from this software without specific prior written permission. |
32 | // + from this software without specific prior written permission. |
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
34 | // + for non-commercial use (directly or indirectly) |
34 | // + for non-commercial use (directly or indirectly) |
35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
36 | // + with our written permission |
36 | // + with our written permission |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
38 | // + clearly linked as origin |
38 | // + clearly linked as origin |
39 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
39 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
48 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
48 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | #include "main.h" |
52 | #include "main.h" |
- | 53 | ||
53 | 54 | ||
54 | unsigned char EEPromArray[E2END+1] EEMEM; |
55 | unsigned char EEPromArray[E2END+1] EEMEM; |
55 | unsigned char PlatinenVersion = 10; |
56 | unsigned char PlatinenVersion = 10; |
56 | unsigned char SendVersionToNavi = 1; |
57 | unsigned char SendVersionToNavi = 1; |
57 | unsigned char BattLowVoltageWarning = 94; |
58 | unsigned char BattLowVoltageWarning = 94; |
58 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
59 | unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0; |
59 | // -- Parametersatz aus EEPROM lesen --- |
60 | // -- Parametersatz aus EEPROM lesen --- |
60 | // number [1..5] |
61 | // number [1..5] |
61 | void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
62 | void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
62 | { |
63 | { |
63 | if((number > 5)||(number < 1)) number = 3; |
64 | if((number > 5)||(number < 1)) number = 3; |
64 | eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
65 | eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
65 | LED_Init(); |
66 | LED_Init(); |
66 | } |
67 | } |
67 | 68 | ||
68 | // -- Parametersatz ins EEPROM schreiben --- |
69 | // -- Parametersatz ins EEPROM schreiben --- |
69 | // number [1..5] |
70 | // number [1..5] |
70 | void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
71 | void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
71 | { |
72 | { |
72 | if(number > 5) number = 5; |
73 | if(number > 5) number = 5; |
73 | if(number < 1) return; |
74 | if(number < 1) return; |
74 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
75 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * (number - 1)], length); |
75 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_LENGTH], length); // Länge der Datensätze merken |
76 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_LENGTH], length); // Länge der Datensätze merken |
76 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_CHANNELS], 12); // 12 Kanäle merken |
77 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_CHANNELS], 12); // 12 Kanäle merken |
77 | SetActiveParamSetNumber(number); |
78 | SetActiveParamSetNumber(number); |
78 | LED_Init(); |
79 | LED_Init(); |
79 | } |
80 | } |
80 | 81 | ||
81 | unsigned char GetActiveParamSetNumber(void) |
82 | unsigned char GetActiveParamSetNumber(void) |
82 | { |
83 | { |
83 | unsigned char set; |
84 | unsigned char set; |
84 | set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
85 | set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
85 | if((set > 5) || (set < 1)) |
86 | if((set > 5) || (set < 1)) |
86 | { |
87 | { |
87 | set = 3; |
88 | set = 3; |
88 | SetActiveParamSetNumber(set); // diesen Parametersatz als aktuell merken |
89 | SetActiveParamSetNumber(set); // diesen Parametersatz als aktuell merken |
89 | } |
90 | } |
90 | return(set); |
91 | return(set); |
91 | } |
92 | } |
92 | 93 | ||
93 | void SetActiveParamSetNumber(unsigned char number) |
94 | void SetActiveParamSetNumber(unsigned char number) |
94 | { |
95 | { |
95 | if(number > 5) number = 5; |
96 | if(number > 5) number = 5; |
96 | if(number < 1) return; |
97 | if(number < 1) return; |
97 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
98 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
98 | } |
99 | } |
99 | 100 | ||
100 | 101 | ||
101 | void CalMk3Mag(void) |
102 | void CalMk3Mag(void) |
102 | { |
103 | { |
103 | static unsigned char stick = 1; |
104 | static unsigned char stick = 1; |
104 | 105 | ||
105 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
106 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0; |
106 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
107 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick) |
107 | { |
108 | { |
108 | stick = 1; |
109 | stick = 1; |
109 | WinkelOut.CalcState++; |
110 | WinkelOut.CalcState++; |
110 | if(WinkelOut.CalcState > 4) |
111 | if(WinkelOut.CalcState > 4) |
111 | { |
112 | { |
112 | // WinkelOut.CalcState = 0; // in Uart.c |
113 | // WinkelOut.CalcState = 0; // in Uart.c |
113 | beeptime = 1000; |
114 | beeptime = 1000; |
114 | } |
115 | } |
115 | else Piep(WinkelOut.CalcState,150); |
116 | else Piep(WinkelOut.CalcState,150); |
116 | } |
117 | } |
117 | DebugOut.Analog[19] = WinkelOut.CalcState; |
118 | DebugOut.Analog[19] = WinkelOut.CalcState; |
118 | } |
119 | } |
- | 120 | ||
- | 121 | ||
119 | 122 | ||
120 | void LipoDetection(unsigned char print) |
123 | void LipoDetection(unsigned char print) |
121 | { |
124 | { |
122 | unsigned int timer; |
125 | unsigned int timer; |
123 | if(print) printf("\n\rBatt:"); |
126 | if(print) printf("\n\rBatt:"); |
124 | if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung |
127 | if(EE_Parameter.UnterspannungsWarnung < 50) // automatische Zellenerkennung |
125 | { |
128 | { |
126 | timer = SetDelay(500); |
129 | timer = SetDelay(500); |
127 | if(print) while (!CheckDelay(timer)); |
130 | if(print) while (!CheckDelay(timer)); |
128 | if(UBat < 130) |
131 | if(UBat < 130) |
129 | { |
132 | { |
130 | BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung; |
133 | BattLowVoltageWarning = 3 * EE_Parameter.UnterspannungsWarnung; |
131 | if(print) |
134 | if(print) |
132 | { |
135 | { |
133 | Piep(3,200); |
136 | Piep(3,200); |
134 | printf(" 3 Cells "); |
137 | printf(" 3 Cells "); |
135 | } |
138 | } |
136 | } |
139 | } |
137 | else |
140 | else |
138 | { |
141 | { |
139 | BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung; |
142 | BattLowVoltageWarning = 4 * EE_Parameter.UnterspannungsWarnung; |
140 | if(print) |
143 | if(print) |
141 | { |
144 | { |
142 | Piep(4,200); |
145 | Piep(4,200); |
143 | printf(" 4 Cells "); |
146 | printf(" 4 Cells "); |
144 | } |
147 | } |
145 | } |
148 | } |
146 | } |
149 | } |
147 | else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
150 | else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung; |
148 | // if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93; |
151 | // if(BattLowVoltageWarning < 93) BattLowVoltageWarning = 93; |
149 | if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
152 | if(print) printf(" Low warning level: %d.%d",BattLowVoltageWarning/10,BattLowVoltageWarning%10); |
150 | } |
153 | } |
151 | 154 | ||
152 | //############################################################################ |
155 | //############################################################################ |
153 | //Hauptprogramm |
156 | //Hauptprogramm |
154 | int main (void) |
157 | int main (void) |
155 | //############################################################################ |
158 | //############################################################################ |
156 | { |
159 | { |
157 | unsigned int timer,i,timer2 = 0, timerPolling; |
160 | unsigned int timer,i,timer2 = 0, timerPolling; |
158 | DDRB = 0x00; |
161 | DDRB = 0x00; |
159 | PORTB = 0x00; |
162 | PORTB = 0x00; |
160 | for(timer = 0; timer < 1000; timer++); // verzögern |
163 | for(timer = 0; timer < 1000; timer++); // verzögern |
161 | if(PINB & 0x01) |
164 | if(PINB & 0x01) |
162 | { |
165 | { |
163 | if(PINB & 0x02) PlatinenVersion = 13; |
166 | if(PINB & 0x02) PlatinenVersion = 13; |
164 | else PlatinenVersion = 11; |
167 | else PlatinenVersion = 11; |
165 | } |
168 | } |
166 | else |
169 | else |
167 | { |
170 | { |
168 | if(PINB & 0x02) PlatinenVersion = 20; |
171 | if(PINB & 0x02) PlatinenVersion = 20; |
169 | else PlatinenVersion = 10; |
172 | else PlatinenVersion = 10; |
170 | } |
173 | } |
171 | 174 | ||
172 | DDRC = 0x81; // SCL |
175 | DDRC = 0x81; // SCL |
173 | DDRC |=0x40; // HEF4017 Reset |
176 | DDRC |=0x40; // HEF4017 Reset |
174 | PORTC = 0xff; // Pullup SDA |
177 | PORTC = 0xff; // Pullup SDA |
175 | DDRB = 0x1B; // LEDs und Druckoffset |
178 | DDRB = 0x1B; // LEDs und Druckoffset |
176 | PORTB = 0x01; // LED_Rot |
179 | PORTB = 0x01; // LED_Rot |
177 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
180 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
178 | PORTD = 0x47; // LED |
181 | PORTD = 0x47; // LED |
179 | HEF4017R_ON; |
182 | HEF4017R_ON; |
180 | MCUSR &=~(1<<WDRF); |
183 | MCUSR &=~(1<<WDRF); |
181 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
184 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
182 | WDTCSR = 0; |
185 | WDTCSR = 0; |
183 | 186 | ||
184 | beeptime = 2000; |
187 | beeptime = 2000; |
185 | StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0; |
188 | StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0; |
186 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
189 | if(PlatinenVersion >= 20) GIER_GRAD_FAKTOR = 1160; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC |
187 | ROT_OFF; |
190 | ROT_OFF; |
188 | 191 | ||
189 | Timer_Init(); |
192 | Timer_Init(); |
190 | TIMER2_Init(); |
193 | TIMER2_Init(); |
191 | UART_Init(); |
194 | UART_Init(); |
192 | rc_sum_init(); |
195 | rc_sum_init(); |
193 | ADC_Init(); |
196 | ADC_Init(); |
194 | i2c_init(); |
197 | i2c_init(); |
195 | SPI_MasterInit(); |
198 | SPI_MasterInit(); |
196 | - | ||
197 | LIBFC_Init(); |
199 | LIBFC_Init(); |
198 | - | ||
199 | 200 | ||
200 | GRN_ON; |
201 | GRN_ON; |
201 | sei(); |
202 | sei(); |
202 | 203 | ||
203 | ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 13); // read only the first bytes |
204 | ReadParameterSet(3, (unsigned char *) &EE_Parameter.Kanalbelegung[0], 13); // read only the first bytes |
204 | 205 | ||
205 | 206 | ||
206 | if((eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == MIXER_REVISION) && // Check Revision in the first Byte |
207 | if((eeprom_read_byte(&EEPromArray[EEPROM_ADR_MIXER_TABLE]) == MIXER_REVISION) && // Check Revision in the first Byte |
207 | (eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != 0xff)) // Settings reset via Koptertool |
208 | (eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != 0xff)) // Settings reset via Koptertool |
208 | { |
209 | { |
209 | unsigned char i; |
210 | unsigned char i; |
210 | RequiredMotors = 0; |
211 | RequiredMotors = 0; |
211 | eeprom_read_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
212 | eeprom_read_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
212 | for(i=0; i<16;i++) { if(Mixer.Motor[i][0] > 0) RequiredMotors++;} |
213 | for(i=0; i<16;i++) { if(Mixer.Motor[i][0] > 0) RequiredMotors++;} |
213 | } |
214 | } |
214 | else // default |
215 | else // default |
215 | { |
216 | { |
216 | unsigned char i; |
217 | unsigned char i; |
217 | printf("\n\rGenerating default Mixer Table"); |
218 | printf("\n\rGenerating default Mixer Table"); |
218 | for(i=0; i<16;i++) { Mixer.Motor[i][0] = 0;Mixer.Motor[i][1] = 0;Mixer.Motor[i][2] = 0;Mixer.Motor[i][3] = 0;}; |
219 | for(i=0; i<16;i++) { Mixer.Motor[i][0] = 0;Mixer.Motor[i][1] = 0;Mixer.Motor[i][2] = 0;Mixer.Motor[i][3] = 0;}; |
219 | // default = Quadro |
220 | // default = Quadro |
220 | Mixer.Motor[0][0] = 64; Mixer.Motor[0][1] = +64; Mixer.Motor[0][2] = 0; Mixer.Motor[0][3] = +64; |
221 | Mixer.Motor[0][0] = 64; Mixer.Motor[0][1] = +64; Mixer.Motor[0][2] = 0; Mixer.Motor[0][3] = +64; |
221 | Mixer.Motor[1][0] = 64; Mixer.Motor[1][1] = -64; Mixer.Motor[1][2] = 0; Mixer.Motor[1][3] = +64; |
222 | Mixer.Motor[1][0] = 64; Mixer.Motor[1][1] = -64; Mixer.Motor[1][2] = 0; Mixer.Motor[1][3] = +64; |
222 | Mixer.Motor[2][0] = 64; Mixer.Motor[2][1] = 0; Mixer.Motor[2][2] = -64; Mixer.Motor[2][3] = -64; |
223 | Mixer.Motor[2][0] = 64; Mixer.Motor[2][1] = 0; Mixer.Motor[2][2] = -64; Mixer.Motor[2][3] = -64; |
223 | Mixer.Motor[3][0] = 64; Mixer.Motor[3][1] = 0; Mixer.Motor[3][2] = +64; Mixer.Motor[3][3] = -64; |
224 | Mixer.Motor[3][0] = 64; Mixer.Motor[3][1] = 0; Mixer.Motor[3][2] = +64; Mixer.Motor[3][3] = -64; |
224 | Mixer.Revision = MIXER_REVISION; |
225 | Mixer.Revision = MIXER_REVISION; |
225 | memcpy(Mixer.Name, "Quadro\0", 11); |
226 | memcpy(Mixer.Name, "Quadro\0", 11); |
226 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
227 | eeprom_write_block(&Mixer, &EEPromArray[EEPROM_ADR_MIXER_TABLE], sizeof(Mixer)); |
227 | } |
228 | } |
228 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors); |
229 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name,RequiredMotors); |
229 | 230 | ||
230 | 231 | ||
231 | 232 | ||
232 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
233 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
233 | // + Check connected BL-Ctrls |
234 | // + Check connected BL-Ctrls |
234 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
235 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 236 | printf("\n\r-->%d", MAX_EMPFANGS_BUFF); |
|
235 | printf("\n\rFound BL-Ctrl: "); |
237 | printf("\n\rFound BL-Ctrl: "); |
236 | motorread = 0; UpdateMotor = 0; SendMotorData(); while(!UpdateMotor); motorread = 0; // read the first I2C-Data |
238 | motorread = 0; UpdateMotor = 0; SendMotorData(); while(!UpdateMotor); motorread = 0; // read the first I2C-Data |
237 | timer = SetDelay(2000); |
239 | timer = SetDelay(2000); |
238 | 240 | ||
239 | 241 | ||
240 | for(i=0; i < MAX_MOTORS; i++) |
242 | for(i=0; i < MAX_MOTORS; i++) |
241 | { |
243 | { |
242 | UpdateMotor = 0; |
244 | UpdateMotor = 0; |
243 | SendMotorData(); |
245 | SendMotorData(); |
244 | while(!UpdateMotor); |
246 | while(!UpdateMotor); |
245 | if(Mixer.Motor[i][0] > 0) // wait max 2 sec for the BL-Ctrls to wake up |
247 | if(Mixer.Motor[i][0] > 0) // wait max 2 sec for the BL-Ctrls to wake up |
246 | { |
248 | { |
247 | while(!CheckDelay(timer) && !MotorPresent[i]) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);}; |
249 | while(!CheckDelay(timer) && !MotorPresent[i]) {UpdateMotor = 0; SendMotorData(); while(!UpdateMotor);}; |
248 | } |
250 | } |
249 | if(MotorPresent[i]) printf("%d ",i+1); |
251 | if(MotorPresent[i]) printf("%d ",i+1); |
250 | } |
252 | } |
251 | for(i=0; i < MAX_MOTORS; i++) |
253 | for(i=0; i < MAX_MOTORS; i++) |
252 | { |
254 | { |
253 | if(!MotorPresent[i] && Mixer.Motor[i][0] > 0) |
255 | if(!MotorPresent[i] && Mixer.Motor[i][0] > 0) |
254 | { |
256 | { |
255 | printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
257 | printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
256 | ServoActive = 1; // just in case the FC would be used as camera-stabilizer |
258 | ServoActive = 1; // just in case the FC would be used as camera-stabilizer |
257 | } |
259 | } |
258 | MotorError[i] = 0; |
260 | MotorError[i] = 0; |
259 | } |
261 | } |
260 | printf("\n\r==================================="); |
262 | printf("\n\r==================================="); |
261 | SendMotorData(); |
263 | SendMotorData(); |
262 | //printf("\n size: %u",STRUCT_PARAM_LAENGE); |
264 | //printf("\n size: %u",STRUCT_PARAM_LAENGE); |
263 | 265 | ||
264 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
266 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
265 | // + Check Settings |
267 | // + Check Settings |
266 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
268 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
267 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) |
269 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) |
268 | { |
270 | { |
269 | DefaultKonstanten1(); |
271 | DefaultKonstanten1(); |
270 | printf("\n\rInit. EEPROM"); |
272 | printf("\n\rInit. EEPROM"); |
271 | for (unsigned char i=1;i<6;i++) |
273 | for (unsigned char i=1;i<6;i++) |
272 | { |
274 | { |
273 | if(i==2) DefaultKonstanten2(); // Kamera |
275 | if(i==2) DefaultKonstanten2(); // Kamera |
274 | if(i==3) DefaultKonstanten3(); // Beginner |
276 | if(i==3) DefaultKonstanten3(); // Beginner |
275 | if(i>3) DefaultKonstanten2(); // Kamera |
277 | if(i>3) DefaultKonstanten2(); // Kamera |
276 | if(PlatinenVersion >= 20) |
278 | if(PlatinenVersion >= 20) |
277 | { |
279 | { |
278 | EE_Parameter.Gyro_D = 5; |
280 | EE_Parameter.Gyro_D = 5; |
279 | EE_Parameter.Driftkomp = 0; |
281 | EE_Parameter.Driftkomp = 0; |
280 | EE_Parameter.GyroAccFaktor = 27; |
282 | EE_Parameter.GyroAccFaktor = 27; |
281 | EE_Parameter.WinkelUmschlagNick = 78; |
283 | EE_Parameter.WinkelUmschlagNick = 78; |
282 | EE_Parameter.WinkelUmschlagRoll = 78; |
284 | EE_Parameter.WinkelUmschlagRoll = 78; |
283 | } |
285 | } |
284 | // valid Stick-Settings? |
286 | // valid Stick-Settings? |
285 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]) < 12) |
287 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]) < 12 && eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]) < 12) |
286 | { |
288 | { |
287 | EE_Parameter.Kanalbelegung[0] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]); |
289 | EE_Parameter.Kanalbelegung[0] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+0]); |
288 | EE_Parameter.Kanalbelegung[1] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]); |
290 | EE_Parameter.Kanalbelegung[1] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+1]); |
289 | EE_Parameter.Kanalbelegung[2] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]); |
291 | EE_Parameter.Kanalbelegung[2] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+2]); |
290 | EE_Parameter.Kanalbelegung[3] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]); |
292 | EE_Parameter.Kanalbelegung[3] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+3]); |
291 | EE_Parameter.Kanalbelegung[4] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+4]); |
293 | EE_Parameter.Kanalbelegung[4] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+4]); |
292 | EE_Parameter.Kanalbelegung[5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+5]); |
294 | EE_Parameter.Kanalbelegung[5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+5]); |
293 | EE_Parameter.Kanalbelegung[6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+6]); |
295 | EE_Parameter.Kanalbelegung[6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+6]); |
294 | EE_Parameter.Kanalbelegung[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]); |
296 | EE_Parameter.Kanalbelegung[7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+7]); |
295 | 297 | ||
296 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]) < 255) |
298 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]) < 255) |
297 | { |
299 | { |
298 | EE_Parameter.Kanalbelegung[K_POTI5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]); |
300 | EE_Parameter.Kanalbelegung[K_POTI5] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+8]); |
299 | EE_Parameter.Kanalbelegung[K_POTI6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+9]); |
301 | EE_Parameter.Kanalbelegung[K_POTI6] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+9]); |
300 | EE_Parameter.Kanalbelegung[K_POTI7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+10]); |
302 | EE_Parameter.Kanalbelegung[K_POTI7] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+10]); |
301 | EE_Parameter.Kanalbelegung[K_POTI8] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+11]); |
303 | EE_Parameter.Kanalbelegung[K_POTI8] = eeprom_read_byte(&EEPromArray[EEPROM_ADR_CHANNELS+11]); |
302 | } |
304 | } |
303 | else |
305 | else |
304 | { |
306 | { |
305 | EE_Parameter.Kanalbelegung[K_POTI5] = 9; |
307 | EE_Parameter.Kanalbelegung[K_POTI5] = 9; |
306 | EE_Parameter.Kanalbelegung[K_POTI6] = 10; |
308 | EE_Parameter.Kanalbelegung[K_POTI6] = 10; |
307 | EE_Parameter.Kanalbelegung[K_POTI7] = 11; |
309 | EE_Parameter.Kanalbelegung[K_POTI7] = 11; |
308 | EE_Parameter.Kanalbelegung[K_POTI8] = 12; |
310 | EE_Parameter.Kanalbelegung[K_POTI8] = 12; |
309 | } |
311 | } |
310 | if(i==1) printf(": Generating Default-Parameter using old Stick Settings"); |
312 | if(i==1) printf(": Generating Default-Parameter using old Stick Settings"); |
311 | } else DefaultStickMapping(); |
313 | } else DefaultStickMapping(); |
312 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
314 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
313 | } |
315 | } |
314 | SetActiveParamSetNumber(3); // default-Setting |
316 | SetActiveParamSetNumber(3); // default-Setting |
315 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
317 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
316 | } |
318 | } |
317 | 319 | ||
318 | 320 | ||
319 | 321 | ||
320 | FlugMinuten = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1]); |
322 | FlugMinuten = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1]); |
321 | FlugMinutenGesamt = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES+1]); |
323 | FlugMinutenGesamt = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_MINUTES+1]); |
322 | if(FlugMinutenGesamt == 0xffff || FlugMinuten == 0xffff) |
324 | if(FlugMinutenGesamt == 0xffff || FlugMinuten == 0xffff) |
323 | { |
325 | { |
324 | FlugMinuten = 0; |
326 | FlugMinuten = 0; |
325 | FlugMinutenGesamt = 0; |
327 | FlugMinutenGesamt = 0; |
326 | } |
328 | } |
327 | printf("\n\rFlight-time %u min Total:%u min" ,FlugMinuten,FlugMinutenGesamt); |
329 | printf("\n\rFlight-time %u min Total:%u min" ,FlugMinuten,FlugMinutenGesamt); |
328 | 330 | ||
329 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
331 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
330 | { |
332 | { |
331 | printf("\n\rACC not calibrated !"); |
333 | printf("\n\rACC not calibrated !"); |
332 | } |
334 | } |
333 | 335 | ||
334 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
336 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
335 | printf("\n\rUsing parameterset %d", GetActiveParamSetNumber()); |
337 | printf("\n\rUsing parameterset %d", GetActiveParamSetNumber()); |
336 | 338 | ||
337 | 339 | ||
338 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
340 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
339 | { |
341 | { |
340 | printf("\n\rCalibrating pressure sensor.."); |
342 | printf("\n\rCalibrating pressure sensor.."); |
341 | timer = SetDelay(1000); |
343 | timer = SetDelay(1000); |
342 | SucheLuftruckOffset(); |
344 | SucheLuftruckOffset(); |
343 | while (!CheckDelay(timer)); |
345 | while (!CheckDelay(timer)); |
344 | printf("OK\n\r"); |
346 | printf("OK\n\r"); |
345 | } |
347 | } |
346 | 348 | ||
347 | SetNeutral(); |
349 | SetNeutral(); |
348 | 350 | ||
349 | ROT_OFF; |
351 | ROT_OFF; |
350 | 352 | ||
351 | beeptime = 2000; |
353 | beeptime = 2000; |
352 | ExternControl.Digital[0] = 0x55; |
354 | ExternControl.Digital[0] = 0x55; |
353 | 355 | ||
354 | 356 | ||
355 | printf("\n\rControl: "); |
357 | printf("\n\rControl: "); |
356 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
358 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
357 | else printf("Normal (ACC-Mode)"); |
359 | else printf("Normal (ACC-Mode)"); |
358 | 360 | ||
359 | LcdClear(); |
361 | LcdClear(); |
360 | I2CTimeout = 5000; |
362 | I2CTimeout = 5000; |
361 | WinkelOut.Orientation = 1; |
363 | WinkelOut.Orientation = 1; |
362 | LipoDetection(1); |
364 | LipoDetection(1); |
363 | 365 | ||
364 | LIBFC_ReceiverInit(); |
366 | LIBFC_ReceiverInit(); |
365 | printf("\n\r===================================\n\r"); |
367 | printf("\n\r===================================\n\r"); |
366 | //SpektrumBinding(); |
368 | //SpektrumBinding(); |
367 | timer = SetDelay(2000); |
369 | timer = SetDelay(2000); |
368 | timerPolling = SetDelay(250); |
370 | timerPolling = SetDelay(250); |
369 | while (1) |
371 | while (1) |
370 | { |
372 | { |
371 | 373 | ||
372 | if(CheckDelay(timerPolling)) |
374 | if(CheckDelay(timerPolling)) |
373 | { |
375 | { |
374 | timerPolling = SetDelay(100); |
376 | timerPolling = SetDelay(100); |
375 | LIBFC_Polling(); |
377 | LIBFC_Polling(); |
376 | } |
378 | } |
377 | 379 | ||
378 | if(UpdateMotor && AdReady) // ReglerIntervall |
380 | if(UpdateMotor && AdReady) // ReglerIntervall |
379 | { |
381 | { |
380 | UpdateMotor=0; |
382 | UpdateMotor=0; |
381 | if(WinkelOut.CalcState) CalMk3Mag(); |
383 | if(WinkelOut.CalcState) CalMk3Mag(); |
382 | else MotorRegler(); |
384 | else MotorRegler(); |
383 | SendMotorData(); |
385 | SendMotorData(); |
384 | ROT_OFF; |
386 | ROT_OFF; |
385 | if(SenderOkay) SenderOkay--; |
387 | if(SenderOkay) SenderOkay--; |
386 | else TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
388 | else TIMSK1 |= _BV(ICIE1); // enable PPM-Input |
387 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
389 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
388 | if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
390 | if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160; |
389 | if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
391 | if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101; |
390 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
392 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
391 | 393 | ||
392 | if(!--I2CTimeout || MissingMotor) |
394 | if(!--I2CTimeout || MissingMotor) |
393 | { |
395 | { |
394 | if(!I2CTimeout) |
396 | if(!I2CTimeout) |
395 | { |
397 | { |
396 | i2c_reset(); |
398 | i2c_reset(); |
397 | I2CTimeout = 5; |
399 | I2CTimeout = 5; |
398 | DebugOut.Analog[28]++; // I2C-Error |
400 | DebugOut.Analog[28]++; // I2C-Error |
399 | FCFlags |= FCFLAG_I2CERR; |
401 | FCFlags |= FCFLAG_I2CERR; |
400 | } |
402 | } |
401 | if((BeepMuster == 0xffff) && MotorenEin) |
403 | if((BeepMuster == 0xffff) && MotorenEin) |
402 | { |
404 | { |
403 | beeptime = 10000; |
405 | beeptime = 10000; |
404 | BeepMuster = 0x0080; |
406 | BeepMuster = 0x0080; |
405 | } |
407 | } |
406 | } |
408 | } |
407 | else |
409 | else |
408 | { |
410 | { |
409 | ROT_OFF; |
411 | ROT_OFF; |
410 | if(!beeptime) FCFlags &= ~FCFLAG_I2CERR; |
412 | if(!beeptime) FCFlags &= ~FCFLAG_I2CERR; |
411 | } |
413 | } |
412 | if(SIO_DEBUG && (!UpdateMotor || !MotorenEin)) |
414 | if(SIO_DEBUG && (!UpdateMotor || !MotorenEin)) |
413 | { |
415 | { |
414 | DatenUebertragung(); |
416 | DatenUebertragung(); |
415 | BearbeiteRxDaten(); |
417 | BearbeiteRxDaten(); |
416 | } |
418 | } |
417 | else BearbeiteRxDaten(); |
419 | else BearbeiteRxDaten(); |
418 | if(CheckDelay(timer)) |
420 | if(CheckDelay(timer)) |
419 | { |
421 | { |
420 | timer += 20; // 20 ms interval |
422 | timer += 20; // 20 ms interval |
421 | if(PcZugriff) PcZugriff--; |
423 | if(PcZugriff) PcZugriff--; |
422 | else |
424 | else |
423 | { |
425 | { |
424 | ExternControl.Config = 0; |
426 | ExternControl.Config = 0; |
425 | ExternStickNick = 0; |
427 | ExternStickNick = 0; |
426 | ExternStickRoll = 0; |
428 | ExternStickRoll = 0; |
427 | ExternStickGier = 0; |
429 | ExternStickGier = 0; |
428 | if(BeepMuster == 0xffff && SenderOkay == 0) |
430 | if(BeepMuster == 0xffff && SenderOkay == 0) |
429 | { |
431 | { |
430 | beeptime = 15000; |
432 | beeptime = 15000; |
431 | BeepMuster = 0x0c00; |
433 | BeepMuster = 0x0c00; |
432 | } |
434 | } |
433 | } |
435 | } |
434 | if(NaviDataOkay) |
436 | if(NaviDataOkay) |
435 | { |
437 | { |
436 | NaviDataOkay--; |
438 | NaviDataOkay--; |
437 | FCFlags &= ~FCFLAG_SPI_RX_ERR; |
439 | FCFlags &= ~FCFLAG_SPI_RX_ERR; |
438 | } |
440 | } |
439 | else |
441 | else |
440 | { |
442 | { |
441 | GPS_Nick = 0; |
443 | GPS_Nick = 0; |
442 | GPS_Roll = 0; |
444 | GPS_Roll = 0; |
443 | if(!beeptime) FCFlags |= FCFLAG_SPI_RX_ERR; |
445 | if(!beeptime) FCFlags |= FCFLAG_SPI_RX_ERR; |
444 | } |
446 | } |
445 | if(UBat < BattLowVoltageWarning) |
447 | if(UBat < BattLowVoltageWarning) |
446 | { |
448 | { |
447 | FCFlags |= FCFLAG_LOWBAT; |
449 | FCFlags |= FCFLAG_LOWBAT; |
448 | if(BeepMuster == 0xffff) |
450 | if(BeepMuster == 0xffff) |
449 | { |
451 | { |
450 | beeptime = 6000; |
452 | beeptime = 6000; |
451 | BeepMuster = 0x0300; |
453 | BeepMuster = 0x0300; |
452 | } |
454 | } |
453 | } |
455 | } |
454 | else if(!beeptime) FCFlags &= ~FCFLAG_LOWBAT; |
456 | else if(!beeptime) FCFlags &= ~FCFLAG_LOWBAT; |
455 | 457 | ||
456 | SPI_StartTransmitPacket(); |
458 | SPI_StartTransmitPacket(); |
457 | SendSPI = 4; |
459 | SendSPI = 4; |
458 | 460 | ||
459 | if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden |
461 | if(!MotorenEin) timer2 = 1450; // 0,5 Minuten aufrunden |
460 | 462 | ||
461 | if(++timer2 == 2930) // eine Minute |
463 | if(++timer2 == 2930) // eine Minute |
462 | { |
464 | { |
463 | timer2 = 0; |
465 | timer2 = 0; |
464 | FlugMinuten++; |
466 | FlugMinuten++; |
465 | FlugMinutenGesamt++; |
467 | FlugMinutenGesamt++; |
466 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2],FlugMinuten / 256); |
468 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2],FlugMinuten / 256); |
467 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1],FlugMinuten % 256); |
469 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES2+1],FlugMinuten % 256); |
468 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES],FlugMinutenGesamt / 256); |
470 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES],FlugMinutenGesamt / 256); |
469 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES+1],FlugMinutenGesamt % 256); |
471 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_MINUTES+1],FlugMinutenGesamt % 256); |
470 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
472 | timer = SetDelay(20); // falls "timer += 20;" mal nicht geht |
471 | } |
473 | } |
472 | } |
474 | } |
473 | LED_Update(); |
475 | LED_Update(); |
474 | } |
476 | } |
475 | if(!SendSPI) { SPI_TransmitByte(); } |
477 | if(!SendSPI) { SPI_TransmitByte(); } |
476 | } |
478 | } |
477 | return (1); |
479 | return (1); |
478 | } |
480 | } |
479 | 481 | ||
480 | 482 | ||
481 | 483 |