Rev 757 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 757 | Rev 762 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
2 | // + Copyright (c) 04.2007 Holger Buss |
3 | // + Nur für den privaten Gebrauch |
3 | // + Nur für den privaten Gebrauch |
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 der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
24 | // + Die Portierung 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 to systems other than hardware from www.mikrokopter.de is not allowed |
39 | // + * porting to systems other than 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 <avr/boot.h> |
52 | #include <avr/boot.h> |
53 | 53 | ||
54 | #include <avr/io.h> |
54 | #include <avr/io.h> |
55 | #include <avr/interrupt.h> |
55 | #include <avr/interrupt.h> |
56 | 56 | ||
57 | #include "main.h" |
57 | #include "main.h" |
58 | #include "timer0.h" |
58 | #include "timer0.h" |
59 | #include "timer2.h" |
59 | #include "timer2.h" |
60 | #include "uart.h" |
60 | #include "uart.h" |
61 | #if defined (__AVR_ATmega644P__) |
61 | #if defined (__AVR_ATmega644P__) |
62 | #include "uart1.h" |
62 | #include "uart1.h" |
63 | #endif |
63 | #endif |
- | 64 | #include "led.h" |
|
64 | #include "menu.h" |
65 | #include "menu.h" |
65 | #include "ubx.h" |
66 | #include "ubx.h" |
66 | #include "fc.h" |
67 | #include "fc.h" |
67 | #include "rc.h" |
68 | #include "rc.h" |
68 | #include "analog.h" |
69 | #include "analog.h" |
69 | #include "printf_P.h" |
70 | #include "printf_P.h" |
70 | //#include "spi.h" |
71 | //#include "spi.h" |
71 | #ifdef USE_MM3 |
72 | #ifdef USE_MM3 |
72 | #include "mm3.h" |
73 | #include "mm3.h" |
73 | #endif |
74 | #endif |
74 | #ifdef USE_CMPS03 |
75 | #ifdef USE_CMPS03 |
75 | #include "cmps03.h" |
76 | #include "cmps03.h" |
76 | #endif |
77 | #endif |
77 | #include "twimaster.h" |
78 | #include "twimaster.h" |
78 | #include "eeprom.h" |
79 | #include "eeprom.h" |
79 | #include "_Settings.h" |
80 | #include "_Settings.h" |
80 | 81 | ||
81 | 82 | ||
82 | 83 | ||
83 | uint8_t BoardRelease = 10; |
84 | uint8_t BoardRelease = 10; |
84 | 85 | ||
85 | 86 | ||
86 | //############################################################################ |
87 | //############################################################################ |
87 | //Hauptprogramm |
88 | //Hauptprogramm |
88 | int main (void) |
89 | int main (void) |
89 | //############################################################################ |
90 | //############################################################################ |
90 | { |
91 | { |
91 | unsigned int timer; |
92 | unsigned int timer; |
92 | 93 | ||
93 | // disable interrupts global |
94 | // disable interrupts global |
94 | cli(); |
95 | cli(); |
95 | 96 | ||
96 | // get board release |
97 | // get board release |
97 | DDRB = 0x00; |
98 | DDRB = 0x00; |
98 | PORTB = 0x00; |
99 | PORTB = 0x00; |
99 | for(timer = 0; timer < 1000; timer++); // make some delay |
100 | for(timer = 0; timer < 1000; timer++); // make some delay |
100 | if(PINB & (1<<PINB0)) BoardRelease = 11; |
101 | if(PINB & (1<<PINB0)) BoardRelease = 11; |
101 | else BoardRelease = 10; |
102 | else BoardRelease = 10; |
102 | 103 | ||
103 | // set LED ports as output |
104 | // set LED ports as output |
104 | DDRB |= (1<<DDB1)|(1<<DDB0); |
105 | DDRB |= (1<<DDB1)|(1<<DDB0); |
105 | ROT_ON; |
106 | ROT_ON; |
106 | GRN_OFF; |
107 | GRN_OFF; |
107 | - | ||
108 | // set PC2 & PC3 as output (ctrl J16 & J17) |
- | |
109 | DDRC |= (1<<DDC2)|(1<<DDC3); |
- | |
110 | J16_OFF; |
- | |
111 | J17_OFF; |
- | |
112 | 108 | ||
113 | // disable watchdog |
109 | // disable watchdog |
114 | MCUSR &=~(1<<WDRF); |
110 | MCUSR &=~(1<<WDRF); |
115 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
111 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
116 | WDTCSR = 0; |
112 | WDTCSR = 0; |
117 | 113 | ||
118 | BeepTime = 2000; |
114 | BeepTime = 2000; |
119 | 115 | ||
120 | PPM_in[CH_THRUST] = 0; |
116 | PPM_in[CH_THRUST] = 0; |
121 | StickYaw = 0; |
117 | StickYaw = 0; |
122 | StickRoll = 0; |
118 | StickRoll = 0; |
123 | StickPitch = 0; |
119 | StickPitch = 0; |
124 | 120 | ||
125 | ROT_OFF; |
121 | ROT_OFF; |
126 | 122 | ||
127 | // initalize modules |
123 | // initalize modules |
- | 124 | LED_Init(); |
|
128 | TIMER0_Init(); |
125 | TIMER0_Init(); |
129 | TIMER2_Init(); |
126 | TIMER2_Init(); |
130 | USART0_Init(); |
127 | USART0_Init(); |
131 | 128 | ||
132 | #if defined (__AVR_ATmega644P__) |
129 | #if defined (__AVR_ATmega644P__) |
133 | if (BoardRelease == 11) USART1_Init(); |
130 | if (BoardRelease == 11) USART1_Init(); |
134 | #endif |
131 | #endif |
135 | 132 | ||
136 | RC_Init(); |
133 | RC_Init(); |
137 | ADC_Init(); |
134 | ADC_Init(); |
138 | I2C_Init(); |
135 | I2C_Init(); |
139 | 136 | ||
140 | #ifdef USE_MM3 |
137 | #ifdef USE_MM3 |
141 | MM3_Init(); |
138 | MM3_Init(); |
142 | #endif |
139 | #endif |
143 | #ifdef USE_CMPS03 |
140 | #ifdef USE_CMPS03 |
144 | CMPS03_Init(); |
141 | CMPS03_Init(); |
145 | #endif |
142 | #endif |
146 | //SPI_MasterInit(); |
143 | //SPI_MasterInit(); |
147 | 144 | ||
148 | // enable interrupts global |
145 | // enable interrupts global |
149 | sei(); |
146 | sei(); |
150 | 147 | ||
151 | VersionInfo.Major = VERSION_MAJOR; |
148 | VersionInfo.Major = VERSION_MAJOR; |
152 | VersionInfo.Minor = VERSION_MINOR; |
149 | VersionInfo.Minor = VERSION_MINOR; |
153 | VersionInfo.PCCompatible = VERSION_COMPATIBLE; |
150 | VersionInfo.PCCompatible = VERSION_COMPATIBLE; |
154 | 151 | ||
155 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",BoardRelease/10,BoardRelease%10, VERSION_MAJOR, VERSION_MINOR,VERSION_INDEX + 'a'); |
152 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",BoardRelease/10,BoardRelease%10, VERSION_MAJOR, VERSION_MINOR,VERSION_INDEX + 'a'); |
156 | printf("\n\r=============================="); |
153 | printf("\n\r=============================="); |
157 | GRN_ON; |
154 | GRN_ON; |
158 | 155 | ||
159 | // Parameter set handling |
156 | // Parameter set handling |
160 | ParamSet_Init(); |
157 | ParamSet_Init(); |
161 | 158 | ||
162 | if(GetParamWord(PID_ACC_PITCH) > 1023) |
159 | if(GetParamWord(PID_ACC_PITCH) > 1023) |
163 | { |
160 | { |
164 | printf("\n\rACC not calibrated!"); |
161 | printf("\n\rACC not calibrated!"); |
165 | } |
162 | } |
166 | 163 | ||
167 | //wait for a short time (otherwise the RC channel check won't work below) |
164 | //wait for a short time (otherwise the RC channel check won't work below) |
168 | timer = SetDelay(500); |
165 | timer = SetDelay(500); |
169 | while(!CheckDelay(timer)); |
166 | while(!CheckDelay(timer)); |
170 | 167 | ||
171 | 168 | ||
172 | #ifdef USE_MM3 |
169 | #ifdef USE_MM3 |
173 | printf("\n\rSupport for Compass Module MM3"); |
170 | printf("\n\rSupport for Compass Module MM3"); |
174 | //Compass calibration? |
171 | //Compass calibration? |
175 | if(PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] > 100 && PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 100) |
172 | if(PPM_in[ParamSet.ChannelAssignment[CH_THRUST]] > 100 && PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 100) |
176 | { |
173 | { |
177 | printf("\n\rCalibrating Compass"); |
174 | printf("\n\rCalibrating Compass"); |
178 | MM3_Calibrate(); |
175 | MM3_Calibrate(); |
179 | } |
176 | } |
180 | #endif |
177 | #endif |
181 | #ifdef USE_CMPS03 |
178 | #ifdef USE_CMPS03 |
182 | printf("\n\rSupport for Compass Module CMPS03"); |
179 | printf("\n\rSupport for Compass Module CMPS03"); |
183 | #endif |
180 | #endif |
184 | 181 | ||
185 | 182 | ||
186 | if(ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) |
183 | if(ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) |
187 | { |
184 | { |
188 | printf("\n\rCalibrating air pressure sensor.."); |
185 | printf("\n\rCalibrating air pressure sensor.."); |
189 | timer = SetDelay(1000); |
186 | timer = SetDelay(1000); |
190 | SearchAirPressureOffset(); |
187 | SearchAirPressureOffset(); |
191 | while (!CheckDelay(timer)); |
188 | while (!CheckDelay(timer)); |
192 | printf("OK\n\r"); |
189 | printf("OK\n\r"); |
193 | } |
190 | } |
194 | 191 | ||
195 | #if defined (__AVR_ATmega644P__) |
192 | #if defined (__AVR_ATmega644P__) |
196 | if(BoardRelease == 10) |
193 | if(BoardRelease == 10) |
197 | { |
194 | { |
198 | printf("\n\rSupport for GPS at 1st UART"); |
195 | printf("\n\rSupport for GPS at 1st UART"); |
199 | } |
196 | } |
200 | else |
197 | else |
201 | { |
198 | { |
202 | printf("\n\rSupport for GPS at 2nd UART"); |
199 | printf("\n\rSupport for GPS at 2nd UART"); |
203 | } |
200 | } |
204 | #else // (__AVR_ATmega644__) |
201 | #else // (__AVR_ATmega644__) |
205 | printf("\n\rSupport for GPS at 1st UART"); |
202 | printf("\n\rSupport for GPS at 1st UART"); |
206 | #endif |
203 | #endif |
207 | 204 | ||
208 | SetNeutral(); |
205 | SetNeutral(); |
209 | 206 | ||
210 | ROT_OFF; |
207 | ROT_OFF; |
211 | 208 | ||
212 | BeepTime = 2000; |
209 | BeepTime = 2000; |
213 | ExternControl.Digital[0] = 0x55; |
210 | ExternControl.Digital[0] = 0x55; |
214 | 211 | ||
215 | 212 | ||
216 | printf("\n\rControl: "); |
213 | printf("\n\rControl: "); |
217 | if (ParamSet.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
214 | if (ParamSet.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
218 | else printf("Neutral"); |
215 | else printf("Neutral"); |
219 | 216 | ||
220 | printf("\n\n\r"); |
217 | printf("\n\n\r"); |
221 | 218 | ||
222 | LCD_Clear(); |
219 | LCD_Clear(); |
223 | 220 | ||
224 | I2CTimeout = 5000; |
221 | I2CTimeout = 5000; |
225 | while (1) |
222 | while (1) |
226 | { |
223 | { |
227 | if(UpdateMotor) // control interval |
224 | if(UpdateMotor) // control interval |
228 | { |
225 | { |
229 | //SPI_TransmitByte(); //# |
226 | //SPI_TransmitByte(); //# |
230 | UpdateMotor=0; // reset Flag, is enabled every 2 ms by isr of timer0 |
227 | UpdateMotor=0; // reset Flag, is enabled every 2 ms by isr of timer0 |
231 | //PORTD |= (1<<PORTD4); |
228 | //PORTD |= (1<<PORTD4); |
232 | MotorControl(); |
229 | MotorControl(); |
233 | //PORTD &= ~(1<<PORTD4); |
230 | //PORTD &= ~(1<<PORTD4); |
234 | SendMotorData(); |
231 | SendMotorData(); |
235 | ROT_OFF; |
232 | ROT_OFF; |
236 | if(PcAccess) PcAccess--; |
233 | if(PcAccess) PcAccess--; |
237 | else |
234 | else |
238 | { |
235 | { |
239 | DubWiseKeys[0] = 0; |
236 | DubWiseKeys[0] = 0; |
240 | DubWiseKeys[1] = 0; |
237 | DubWiseKeys[1] = 0; |
241 | ExternControl.Config = 0; |
238 | ExternControl.Config = 0; |
242 | ExternStickPitch= 0; |
239 | ExternStickPitch= 0; |
243 | ExternStickRoll = 0; |
240 | ExternStickRoll = 0; |
244 | ExternStickYaw = 0; |
241 | ExternStickYaw = 0; |
245 | } |
242 | } |
246 | if(SenderOkay) SenderOkay--; |
243 | if(SenderOkay) SenderOkay--; |
247 | if(!I2CTimeout) |
244 | if(!I2CTimeout) |
248 | { |
245 | { |
249 | I2CTimeout = 5; |
246 | I2CTimeout = 5; |
250 | I2C_Reset(); |
247 | I2C_Reset(); |
251 | if((BeepModulation == 0xFFFF) && MotorsOn) |
248 | if((BeepModulation == 0xFFFF) && MotorsOn) |
252 | { |
249 | { |
253 | BeepTime = 10000; // 1 second |
250 | BeepTime = 10000; // 1 second |
254 | BeepModulation = 0x0080; |
251 | BeepModulation = 0x0080; |
255 | } |
252 | } |
256 | } |
253 | } |
257 | else |
254 | else |
258 | { |
255 | { |
259 | I2CTimeout--; |
256 | I2CTimeout--; |
260 | ROT_OFF; |
257 | ROT_OFF; |
261 | } |
258 | } |
262 | if(SIO_DEBUG && !UpdateMotor) |
259 | if(SIO_DEBUG && !UpdateMotor) |
263 | { |
260 | { |
264 | TransmitTxData(); |
261 | TransmitTxData(); |
265 | ProcessRxData(); |
262 | ProcessRxData(); |
266 | } |
263 | } |
267 | else ProcessRxData(); |
264 | else ProcessRxData(); |
268 | if(CheckDelay(timer)) |
265 | if(CheckDelay(timer)) |
269 | { |
266 | { |
270 | if(UBat < ParamSet.LowVoltageWarning) |
267 | if(UBat < ParamSet.LowVoltageWarning) |
271 | { |
268 | { |
272 | if(BeepModulation == 0xFFFF) |
269 | if(BeepModulation == 0xFFFF) |
273 | { |
270 | { |
274 | BeepTime = 6000; // 0.6 seconds |
271 | BeepTime = 6000; // 0.6 seconds |
275 | } |
272 | } |
276 | } |
273 | } |
277 | //SPI_StartTransmitPacket();//# |
274 | //SPI_StartTransmitPacket();//# |
278 | timer = SetDelay(100); |
275 | timer = SetDelay(100); |
279 | } |
276 | } |
280 | } |
277 | } |
281 | } |
278 | } |
282 | return (1); |
279 | return (1); |
283 | } |
280 | } |
284 | 281 | ||
285 | 282 |