Rev 942 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
886 | killagreg | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 2 | // + Copyright (c) 04.2007 Holger Buss |
3 | // + only for non-profit use |
||
4 | // + www.MikroKopter.com |
||
5 | // + see the File "License.txt" for further Informations |
||
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
7 | |||
886 | killagreg | 8 | #include <avr/io.h> |
9 | #include <avr/interrupt.h> |
||
10 | #include <avr/wdt.h> |
||
11 | |||
12 | #include "eeprom.h" |
||
1 | ingob | 13 | #include "main.h" |
886 | killagreg | 14 | #include "menu.h" |
15 | #include "timer0.h" |
||
1 | ingob | 16 | #include "uart.h" |
886 | killagreg | 17 | #include "fc.h" |
18 | #include "_Settings.h" |
||
19 | #include "rc.h" |
||
908 | killagreg | 20 | #if defined (USE_KILLAGREG) || defined (USE_MK3MAG) |
886 | killagreg | 21 | #include "ubx.h" |
22 | #endif |
||
908 | killagreg | 23 | #ifdef USE_MK3MAG |
886 | killagreg | 24 | #include "mk3mag.h" |
25 | #endif |
||
1 | ingob | 26 | |
27 | |||
693 | hbuss | 28 | |
886 | killagreg | 29 | #define FALSE 0 |
30 | #define TRUE 1 |
||
31 | |||
32 | //int8_t test __attribute__ ((section (".noinit"))); |
||
33 | uint8_t RequestVerInfo = FALSE; |
||
34 | uint8_t RequestExternalControl = FALSE; |
||
35 | uint8_t RequestDisplay = FALSE; |
||
36 | uint8_t RequestDebugData = FALSE; |
||
37 | uint8_t RequestDebugLabel = 255; |
||
38 | uint8_t RequestChannelOnly = FALSE; |
||
39 | uint8_t RemotePollDisplayLine = 0; |
||
40 | |||
41 | volatile uint8_t txd_buffer[TXD_BUFFER_LEN]; |
||
42 | volatile uint8_t rxd_buffer_locked = FALSE; |
||
43 | volatile uint8_t rxd_buffer[RXD_BUFFER_LEN]; |
||
44 | volatile uint8_t txd_complete = TRUE; |
||
45 | volatile uint8_t ReceivedBytes = 0; |
||
46 | |||
47 | |||
48 | uint8_t PcAccess = 100; |
||
49 | uint8_t MotorTest[4] = {0,0,0,0}; |
||
50 | uint8_t DubWiseKeys[4] = {0,0,0,0}; |
||
51 | uint8_t MySlaveAddr = 0; |
||
52 | uint8_t ConfirmFrame; |
||
53 | |||
54 | DebugOut_t DebugOut; |
||
55 | ExternControl_t ExternControl; |
||
56 | VersionInfo_t VersionInfo; |
||
57 | |||
58 | int16_t Debug_Timer; |
||
59 | |||
908 | killagreg | 60 | #ifdef USE_MK3MAG |
886 | killagreg | 61 | int16_t Compass_Timer; |
62 | #endif |
||
63 | |||
64 | |||
65 | const uint8_t ANALOG_LABEL[32][16] = |
||
499 | hbuss | 66 | { |
886 | killagreg | 67 | //1234567890123456 |
911 | killagreg | 68 | "IntegralNick ", //0 |
499 | hbuss | 69 | "IntegralRoll ", |
911 | killagreg | 70 | "AccNick ", |
499 | hbuss | 71 | "AccRoll ", |
886 | killagreg | 72 | "GyroYaw ", |
73 | "ReadingHeight ", //5 |
||
499 | hbuss | 74 | "AccZ ", |
911 | killagreg | 75 | "Gas ", |
943 | pangu | 76 | "Receiver Level ", |
886 | killagreg | 77 | "Voltage ", |
943 | pangu | 78 | #ifdef HEXAKOPTER |
79 | "Motor FrontLeft ", //10 |
||
80 | "Motor FrontRight", |
||
81 | "Motor RearLeft ", |
||
82 | "Motor RearRight ", |
||
83 | "Motor Right ", |
||
84 | "Motor Left ", //15 |
||
85 | #else |
||
86 | "Motor FrontLeft ", //10 |
||
87 | "Motor FrontRight", |
||
88 | "Motor_RearLeft ", |
||
89 | "Motor_RearRight ", |
||
886 | killagreg | 90 | "Motor_Right ", |
91 | "Motor_Left ", //15 |
||
943 | pangu | 92 | #endif |
93 | "Acc_Z ", |
||
886 | killagreg | 94 | "SPI Error ", |
95 | "SPI Ok ", |
||
96 | " ", |
||
854 | hbuss | 97 | "Servo ", //20 |
911 | killagreg | 98 | "Nick ", |
854 | hbuss | 99 | "Roll ", |
720 | ingob | 100 | " ", |
101 | " ", |
||
102 | " ", //25 |
||
103 | " ", |
||
104 | " ", |
||
105 | " ", |
||
106 | " ", |
||
911 | killagreg | 107 | "GPS_Nick ", //30 |
720 | ingob | 108 | "GPS_Roll " |
499 | hbuss | 109 | }; |
110 | |||
111 | |||
112 | |||
886 | killagreg | 113 | /****************************************************************/ |
114 | /* Initialization of the USART0 */ |
||
115 | /****************************************************************/ |
||
116 | void USART0_Init (void) |
||
1 | ingob | 117 | { |
886 | killagreg | 118 | uint8_t sreg = SREG; |
119 | uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * USART0_BAUD) - 1); |
||
120 | |||
121 | // disable all interrupts before configuration |
||
122 | cli(); |
||
123 | |||
124 | // disable RX-Interrupt |
||
125 | UCSR0B &= ~(1 << RXCIE0); |
||
126 | // disable TX-Interrupt |
||
127 | UCSR0B &= ~(1 << TXCIE0); |
||
128 | |||
129 | // set direction of RXD0 and TXD0 pins |
||
130 | // set RXD0 (PD0) as an input pin |
||
131 | PORTD |= (1 << PORTD0); |
||
132 | DDRD &= ~(1 << DDD0); |
||
133 | // set TXD0 (PD1) as an output pin |
||
134 | PORTD |= (1 << PORTD1); |
||
135 | DDRD |= (1 << DDD1); |
||
136 | |||
137 | // USART0 Baud Rate Register |
||
138 | // set clock divider |
||
139 | UBRR0H = (uint8_t)(ubrr >> 8); |
||
140 | UBRR0L = (uint8_t)ubrr; |
||
141 | |||
142 | // USART0 Control and Status Register A, B, C |
||
143 | |||
144 | // enable double speed operation in |
||
145 | UCSR0A |= (1 << U2X0); |
||
146 | // enable receiver and transmitter in |
||
147 | UCSR0B = (1 << TXEN0) | (1 << RXEN0); |
||
148 | // set asynchronous mode |
||
149 | UCSR0C &= ~(1 << UMSEL01); |
||
150 | UCSR0C &= ~(1 << UMSEL00); |
||
151 | // no parity |
||
152 | UCSR0C &= ~(1 << UPM01); |
||
153 | UCSR0C &= ~(1 << UPM00); |
||
154 | // 1 stop bit |
||
155 | UCSR0C &= ~(1 << USBS0); |
||
156 | // 8-bit |
||
157 | UCSR0B &= ~(1 << UCSZ02); |
||
158 | UCSR0C |= (1 << UCSZ01); |
||
159 | UCSR0C |= (1 << UCSZ00); |
||
160 | |||
161 | // flush receive buffer |
||
162 | while ( UCSR0A & (1<<RXC0) ) UDR0; |
||
163 | |||
164 | // enable interrupts at the end |
||
165 | // enable RX-Interrupt |
||
166 | UCSR0B |= (1 << RXCIE0); |
||
167 | // enable TX-Interrupt |
||
168 | UCSR0B |= (1 << TXCIE0); |
||
169 | |||
170 | rxd_buffer_locked = FALSE; |
||
171 | txd_complete = TRUE; |
||
172 | |||
173 | Debug_Timer = SetDelay(200); |
||
174 | |||
908 | killagreg | 175 | #ifdef USE_MK3MAG |
886 | killagreg | 176 | Compass_Timer = SetDelay(220); |
177 | #endif |
||
178 | |||
179 | // restore global interrupt flags |
||
180 | SREG = sreg; |
||
1 | ingob | 181 | } |
182 | |||
886 | killagreg | 183 | /****************************************************************/ |
184 | /* USART0 transmitter ISR */ |
||
185 | /****************************************************************/ |
||
186 | ISR(USART0_TX_vect) |
||
1 | ingob | 187 | { |
886 | killagreg | 188 | static uint16_t ptr_txd_buffer = 0; |
189 | uint8_t tmp_tx; |
||
190 | if(!txd_complete) // transmission not completed |
||
191 | { |
||
192 | ptr_txd_buffer++; // die [0] wurde schon gesendet |
||
193 | tmp_tx = txd_buffer[ptr_txd_buffer]; |
||
194 | // if terminating character or end of txd buffer was reached |
||
195 | if((tmp_tx == '\r') || (ptr_txd_buffer == TXD_BUFFER_LEN)) |
||
196 | { |
||
197 | ptr_txd_buffer = 0; // reset txd pointer |
||
198 | txd_complete = 1; // stop transmission |
||
199 | } |
||
200 | UDR0 = tmp_tx; // send current byte will trigger this ISR again |
||
201 | } |
||
202 | // transmission completed |
||
203 | else ptr_txd_buffer = 0; |
||
204 | } |
||
1 | ingob | 205 | |
886 | killagreg | 206 | /****************************************************************/ |
207 | /* USART0 receiver ISR */ |
||
208 | /****************************************************************/ |
||
209 | ISR(USART0_RX_vect) |
||
210 | { |
||
211 | static uint16_t crc; |
||
212 | static uint8_t ptr_rxd_buffer = 0; |
||
213 | uint8_t crc1, crc2; |
||
214 | uint8_t c; |
||
215 | |||
216 | c = UDR0; // catch the received byte |
||
217 | |||
908 | killagreg | 218 | #if defined (USE_KILLAGREG) || defined (USE_MK3MAG) |
886 | killagreg | 219 | // If the FC 1.0 cpu is used the ublox module should be conneced to rxd of the 1st uart. |
220 | // The FC 1.1 /1.2 has the ATMEGA644p cpu with a 2nd uart to which the ublox should be connected. |
||
221 | #if defined (__AVR_ATmega644P__) |
||
222 | if(BoardRelease == 10) ubx_parser(c); |
||
223 | #else |
||
224 | ubx_parser(c); |
||
225 | #endif |
||
908 | killagreg | 226 | #endif |
886 | killagreg | 227 | |
228 | if(rxd_buffer_locked) return; // if rxd buffer is locked immediately return |
||
229 | |||
230 | // the rxd buffer is unlocked |
||
231 | if((ptr_rxd_buffer == 0) && (c == '#')) // if rxd buffer is empty and syncronisation character is received |
||
232 | { |
||
233 | rxd_buffer[ptr_rxd_buffer++] = c; // copy 1st byte to buffer |
||
234 | crc = c; // init crc |
||
235 | } |
||
236 | #if 0 |
||
237 | else if (ptr_rxd_buffer == 1) // handle address |
||
238 | { |
||
239 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
||
240 | crc += c; // update crc |
||
241 | } |
||
242 | #endif |
||
243 | else if (ptr_rxd_buffer < RXD_BUFFER_LEN) // collect incomming bytes |
||
244 | { |
||
245 | if(c != '\r') // no termination character |
||
246 | { |
||
247 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
||
248 | crc += c; // update crc |
||
249 | } |
||
250 | else // termination character was received |
||
251 | { |
||
252 | // the last 2 bytes are no subject for checksum calculation |
||
253 | // they are the checksum itself |
||
254 | crc -= rxd_buffer[ptr_rxd_buffer-2]; |
||
255 | crc -= rxd_buffer[ptr_rxd_buffer-1]; |
||
256 | // calculate checksum from transmitted data |
||
257 | crc %= 4096; |
||
258 | crc1 = '=' + crc / 64; |
||
259 | crc2 = '=' + crc % 64; |
||
260 | // compare checksum to transmitted checksum bytes |
||
261 | if((crc1 == rxd_buffer[ptr_rxd_buffer-2]) && (crc2 == rxd_buffer[ptr_rxd_buffer-1])) |
||
262 | { // checksum valid |
||
263 | rxd_buffer_locked = TRUE; // lock the rxd buffer |
||
264 | ReceivedBytes = ptr_rxd_buffer; // store number of received bytes |
||
265 | rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character |
||
266 | // if 2nd byte is an 'R' enable watchdog that will result in an reset |
||
267 | if(rxd_buffer[2] == 'R') {wdt_enable(WDTO_250MS);} // Reset-Commando |
||
268 | } |
||
269 | else |
||
270 | { // checksum invalid |
||
271 | rxd_buffer_locked = FALSE; // unlock rxd buffer |
||
272 | } |
||
273 | ptr_rxd_buffer = 0; // reset rxd buffer pointer |
||
274 | } |
||
275 | } |
||
276 | else // rxd buffer overrun |
||
277 | { |
||
278 | ptr_rxd_buffer = 0; // reset rxd buffer |
||
279 | rxd_buffer_locked = FALSE; // unlock rxd buffer |
||
280 | } |
||
281 | |||
1 | ingob | 282 | } |
283 | |||
284 | |||
285 | // -------------------------------------------------------------------------- |
||
886 | killagreg | 286 | void AddCRC(uint16_t datalen) |
1 | ingob | 287 | { |
886 | killagreg | 288 | uint16_t tmpCRC = 0, i; |
289 | for(i = 0; i < datalen; i++) |
||
290 | { |
||
291 | tmpCRC += txd_buffer[i]; |
||
292 | } |
||
293 | tmpCRC %= 4096; |
||
294 | txd_buffer[i++] = '=' + tmpCRC / 64; |
||
295 | txd_buffer[i++] = '=' + tmpCRC % 64; |
||
296 | txd_buffer[i++] = '\r'; |
||
297 | txd_complete = FALSE; |
||
298 | UDR0 = txd_buffer[0]; // initiates the transmittion (continued in the TXD ISR) |
||
1 | ingob | 299 | } |
300 | |||
301 | |||
302 | |||
303 | // -------------------------------------------------------------------------- |
||
886 | killagreg | 304 | void SendOutData(uint8_t cmd,uint8_t module, uint8_t *snd, uint8_t len) |
1 | ingob | 305 | { |
886 | killagreg | 306 | uint16_t pt = 0; |
307 | uint8_t a,b,c; |
||
308 | uint8_t ptr = 0; |
||
1 | ingob | 309 | |
886 | killagreg | 310 | txd_buffer[pt++] = '#'; // Start character |
311 | txd_buffer[pt++] = module; // Address (a=0; b=1,...) |
||
312 | txd_buffer[pt++] = cmd; // Command |
||
1 | ingob | 313 | |
886 | killagreg | 314 | while(len) |
315 | { |
||
316 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
||
317 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
||
318 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
||
319 | txd_buffer[pt++] = '=' + (a >> 2); |
||
320 | txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
||
321 | txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
||
322 | txd_buffer[pt++] = '=' + ( c & 0x3f); |
||
323 | } |
||
324 | AddCRC(pt); // add checksum after data block and initates the transmission |
||
1 | ingob | 325 | } |
326 | |||
327 | |||
328 | // -------------------------------------------------------------------------- |
||
886 | killagreg | 329 | void Decode64(uint8_t *ptrOut, uint8_t len, uint8_t ptrIn, uint8_t max) |
1 | ingob | 330 | { |
886 | killagreg | 331 | uint8_t a,b,c,d; |
332 | uint8_t ptr = 0; |
||
333 | uint8_t x,y,z; |
||
334 | while(len) |
||
335 | { |
||
336 | a = rxd_buffer[ptrIn++] - '='; |
||
337 | b = rxd_buffer[ptrIn++] - '='; |
||
338 | c = rxd_buffer[ptrIn++] - '='; |
||
339 | d = rxd_buffer[ptrIn++] - '='; |
||
340 | if(ptrIn > max - 2) break; |
||
1 | ingob | 341 | |
886 | killagreg | 342 | x = (a << 2) | (b >> 4); |
343 | y = ((b & 0x0f) << 4) | (c >> 2); |
||
344 | z = ((c & 0x03) << 6) | d; |
||
1 | ingob | 345 | |
886 | killagreg | 346 | if(len--) ptrOut[ptr++] = x; else break; |
347 | if(len--) ptrOut[ptr++] = y; else break; |
||
348 | if(len--) ptrOut[ptr++] = z; else break; |
||
349 | } |
||
1 | ingob | 350 | } |
351 | |||
886 | killagreg | 352 | |
1 | ingob | 353 | // -------------------------------------------------------------------------- |
886 | killagreg | 354 | void USART0_ProcessRxData(void) |
1 | ingob | 355 | { |
886 | killagreg | 356 | // if data in the rxd buffer are not locked immediately return |
357 | if(!rxd_buffer_locked) return; |
||
1 | ingob | 358 | |
886 | killagreg | 359 | #if !defined (USE_KILLAGREG) && !defined (USE_NAVICTRL) |
360 | uint16_t tmp_int_arr1[1]; // local int buffer |
||
361 | #endif |
||
362 | uint8_t tmp_char_arr2[2]; // local char buffer |
||
363 | |||
364 | |||
365 | switch(rxd_buffer[2]) |
||
366 | { |
||
908 | killagreg | 367 | #ifdef USE_MK3MAG |
886 | killagreg | 368 | case 'K':// Compass value |
369 | Decode64((uint8_t *) &tmp_int_arr1[0], sizeof(tmp_int_arr1), 3, ReceivedBytes); |
||
370 | CompassHeading = tmp_int_arr1[0]; |
||
371 | CompassOffCourse = ((540 + CompassHeading - CompassCourse) % 360) - 180; |
||
693 | hbuss | 372 | break; |
886 | killagreg | 373 | #endif |
374 | case 'a':// Labels of the Analog Debug outputs |
||
375 | Decode64((uint8_t *) &tmp_char_arr2[0], sizeof(tmp_char_arr2), 3, ReceivedBytes); |
||
376 | RequestDebugLabel = tmp_char_arr2[0]; |
||
377 | PcAccess = 255; |
||
499 | hbuss | 378 | break; |
886 | killagreg | 379 | case 'b': // extern control |
380 | Decode64((uint8_t *) &ExternControl,sizeof(ExternControl), 3, ReceivedBytes); |
||
381 | RemoteButtons |= ExternControl.RemoteButtons; |
||
382 | ConfirmFrame = ExternControl.Frame; |
||
936 | killagreg | 383 | PcAccess = 255; |
1 | ingob | 384 | break; |
886 | killagreg | 385 | case 'c': // extern control with debug request |
386 | Decode64((uint8_t *) &ExternControl,sizeof(ExternControl),3,ReceivedBytes); |
||
387 | RemoteButtons |= ExternControl.RemoteButtons; |
||
388 | ConfirmFrame = ExternControl.Frame; |
||
389 | RequestDebugData = TRUE; |
||
390 | PcAccess = 255; |
||
1 | ingob | 391 | break; |
886 | killagreg | 392 | case 'h':// x-1 display columns |
393 | Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,ReceivedBytes); |
||
394 | RemoteButtons |= tmp_char_arr2[0]; |
||
395 | if(tmp_char_arr2[1] == 255) RequestChannelOnly = TRUE; |
||
396 | else RequestChannelOnly = FALSE; // keine Displaydaten |
||
397 | RequestDisplay = TRUE; |
||
398 | break; |
||
399 | case 't':// motor test |
||
400 | Decode64((uint8_t *) &MotorTest[0],sizeof(MotorTest),3,ReceivedBytes); |
||
401 | PcAccess = 255; |
||
402 | break; |
||
403 | case 'k':// keys from DubWise |
||
404 | Decode64((uint8_t *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,ReceivedBytes); |
||
595 | hbuss | 405 | ConfirmFrame = DubWiseKeys[3]; |
886 | killagreg | 406 | PcAccess = 255; |
492 | hbuss | 407 | break; |
886 | killagreg | 408 | case 'v': // get version and board release |
409 | RequestVerInfo = TRUE; |
||
410 | break; |
||
411 | case 'g':// get external control data |
||
412 | RequestExternalControl = TRUE; |
||
413 | break; |
||
414 | case 'q':// get settings |
||
415 | Decode64((uint8_t *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,ReceivedBytes); |
||
416 | while(!txd_complete); |
||
417 | if(tmp_char_arr2[0] != 0xff) |
||
418 | { |
||
419 | if(tmp_char_arr2[0] > 5) tmp_char_arr2[0] = 5; // limit to 5 |
||
420 | // load requested parameter set |
||
421 | ParamSet_ReadFromEEProm(tmp_char_arr2[0]); |
||
422 | SendOutData('L' + tmp_char_arr2[0] -1,MySlaveAddr,(uint8_t *) &ParamSet.ChannelAssignment[0],PARAMSET_STRUCT_LEN); |
||
423 | } |
||
424 | else // send active parameter set |
||
425 | SendOutData('L' + GetParamByte(PID_ACTIVE_SET)-1,MySlaveAddr,(uint8_t *) &ParamSet.ChannelAssignment[0],PARAMSET_STRUCT_LEN); |
||
426 | |||
427 | break; |
||
428 | |||
429 | case 'l': |
||
430 | case 'm': |
||
431 | case 'n': |
||
432 | case 'o': |
||
433 | case 'p': // save parameterset |
||
434 | Decode64((uint8_t *) &ParamSet.ChannelAssignment[0],PARAMSET_STRUCT_LEN,3,ReceivedBytes); |
||
435 | ParamSet_WriteToEEProm(rxd_buffer[2] - 'l' + 1); |
||
911 | killagreg | 436 | TurnOver180Nick = (int32_t) ParamSet.AngleTurnOverNick * 2500L; |
886 | killagreg | 437 | TurnOver180Roll = (int32_t) ParamSet.AngleTurnOverRoll * 2500L; |
438 | Beep(GetActiveParamSet()); |
||
439 | break; |
||
440 | |||
441 | |||
442 | } |
||
443 | // unlock the rxd buffer after processing |
||
444 | rxd_buffer_locked = FALSE; |
||
1 | ingob | 445 | } |
446 | |||
447 | //############################################################################ |
||
448 | //Routine für die Serielle Ausgabe |
||
886 | killagreg | 449 | int16_t uart_putchar (int8_t c) |
1 | ingob | 450 | //############################################################################ |
451 | { |
||
452 | if (c == '\n') |
||
453 | uart_putchar('\r'); |
||
886 | killagreg | 454 | // wait until previous character was send |
455 | loop_until_bit_is_set(UCSR0A, UDRE0); |
||
1 | ingob | 456 | //Ausgabe des Zeichens |
886 | killagreg | 457 | UDR0 = c; |
1 | ingob | 458 | return (0); |
459 | } |
||
460 | |||
461 | |||
886 | killagreg | 462 | //--------------------------------------------------------------------------------------------- |
463 | void USART0_TransmitTxData(void) |
||
1 | ingob | 464 | { |
886 | killagreg | 465 | if(!txd_complete) return; |
1 | ingob | 466 | |
886 | killagreg | 467 | if(RequestExternalControl && txd_complete) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
468 | { |
||
469 | SendOutData('G',MySlaveAddr,(uint8_t *) &ExternControl,sizeof(ExternControl)); |
||
470 | RequestExternalControl = FALSE; |
||
471 | } |
||
1 | ingob | 472 | |
908 | killagreg | 473 | #ifdef USE_MK3MAG |
886 | killagreg | 474 | if((CheckDelay(Compass_Timer)) && txd_complete) |
475 | { |
||
911 | killagreg | 476 | ToMk3Mag.Attitude[0] = (int16_t) (IntegralNick / 108); // approx. 0,1 Deg |
886 | killagreg | 477 | ToMk3Mag.Attitude[1] = (int16_t) (IntegralRoll / 108); // approx. 0,1 Deg |
478 | ToMk3Mag.UserParam[0] = FCParam.UserParam1; |
||
479 | ToMk3Mag.UserParam[1] = FCParam.UserParam2; |
||
480 | ToMk3Mag.CalState = CompassCalState; |
||
481 | SendOutData('w',MySlaveAddr,(uint8_t *) &ToMk3Mag,sizeof(ToMk3Mag)); |
||
482 | // the last state is 5 and should be send only once to avoid multiple flash writing |
||
483 | if(CompassCalState > 4) CompassCalState = 0; |
||
484 | Compass_Timer = SetDelay(99); |
||
485 | } |
||
486 | #endif |
||
1 | ingob | 487 | |
886 | killagreg | 488 | if((CheckDelay(Debug_Timer) || RequestDebugData) && txd_complete) |
489 | { |
||
490 | SendOutData('D',MySlaveAddr,(uint8_t *) &DebugOut,sizeof(DebugOut)); |
||
491 | RequestDebugData = FALSE; |
||
492 | Debug_Timer = SetDelay(MIN_DEBUG_INTERVALL); |
||
493 | } |
||
1 | ingob | 494 | |
886 | killagreg | 495 | if(RequestDebugLabel != 255) // Texte für die Analogdaten |
499 | hbuss | 496 | { |
886 | killagreg | 497 | SendOutData('A',RequestDebugLabel + '0',(uint8_t *) ANALOG_LABEL[RequestDebugLabel],16); |
498 | RequestDebugLabel = 255; |
||
499 | hbuss | 499 | } |
886 | killagreg | 500 | if(ConfirmFrame && txd_complete) // Datensatz ohne CRC bestätigen |
595 | hbuss | 501 | { |
886 | killagreg | 502 | txd_buffer[0] = '#'; |
503 | txd_buffer[1] = ConfirmFrame; |
||
504 | txd_buffer[2] = '\r'; |
||
505 | txd_complete = 0; |
||
595 | hbuss | 506 | ConfirmFrame = 0; |
886 | killagreg | 507 | UDR0 = txd_buffer[0]; |
595 | hbuss | 508 | } |
886 | killagreg | 509 | if(RequestDisplay && txd_complete) |
1 | ingob | 510 | { |
886 | killagreg | 511 | LCD_PrintMenu(); |
512 | RequestDisplay = FALSE; |
||
513 | if(++RemotePollDisplayLine == 4 || RequestChannelOnly) |
||
173 | holgerb | 514 | { |
886 | killagreg | 515 | SendOutData('4',0,(uint8_t *)&PPM_in,sizeof(PPM_in)); // DisplayZeile übertragen |
499 | hbuss | 516 | RemotePollDisplayLine = -1; |
886 | killagreg | 517 | } |
518 | else SendOutData('0' + RemotePollDisplayLine,0,(uint8_t *)&DisplayBuff[20 * RemotePollDisplayLine],20); // DisplayZeile übertragen |
||
519 | } |
||
520 | if(RequestVerInfo && txd_complete) |
||
521 | { |
||
522 | SendOutData('V',MySlaveAddr,(uint8_t *) &VersionInfo,sizeof(VersionInfo)); |
||
523 | RequestVerInfo = FALSE; |
||
1 | ingob | 524 | } |
525 | |||
526 | } |
||
527 |