Rev 474 | Rev 489 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 474 | Rev 477 | ||
---|---|---|---|
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2009 by Claas Anders "CaScAdE" Rathje * |
2 | * Copyright (C) 2009 by Claas Anders "CaScAdE" Rathje * |
3 | * admiralcascade@gmail.com * |
3 | * admiralcascade@gmail.com * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
5 | * * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License. * |
8 | * the Free Software Foundation; either version 2 of the License. * |
9 | * * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
13 | * GNU General Public License for more details. * |
14 | * * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the * |
16 | * along with this program; if not, write to the * |
17 | * Free Software Foundation, Inc., * |
17 | * Free Software Foundation, Inc., * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | * * |
19 | * * |
20 | * * |
20 | * * |
21 | * Credits to: * |
21 | * Credits to: * |
22 | * Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
22 | * Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
23 | * Gregor "killagreg" Stobrawa for making the MK code readable * |
23 | * Gregor "killagreg" Stobrawa for making the MK code readable * |
24 | * Klaus "akku" Buettner for the hardware * |
24 | * Klaus "akku" Buettner for the hardware * |
25 | * Manuel "KeyOz" Schrape for explaining the MK protocol to me * |
25 | * Manuel "KeyOz" Schrape for explaining the MK protocol to me * |
26 | ****************************************************************************/ |
26 | ****************************************************************************/ |
27 | 27 | ||
28 | #include <avr/io.h> |
28 | #include <avr/io.h> |
29 | #include <avr/interrupt.h> |
29 | #include <avr/interrupt.h> |
30 | #include <util/delay.h> |
30 | #include <util/delay.h> |
31 | #include <avr/pgmspace.h> |
31 | #include <avr/pgmspace.h> |
32 | #include "main.h" |
32 | #include "main.h" |
33 | #include "max7456_software_spi.h" |
33 | #include "max7456_software_spi.h" |
34 | #include "usart1.h" |
34 | #include "usart1.h" |
35 | #include "osd_helpers.h" |
35 | #include "osd_helpers.h" |
36 | #include "config.h" |
36 | #include "config.h" |
37 | #include "spi.h" |
37 | #include "spi.h" |
38 | #include "buttons.h" |
38 | #include "buttons.h" |
- | 39 | #include "ppm.h" |
|
39 | 40 | ||
40 | /* TODO: |
41 | /* TODO: |
41 | * - verifiy correctness of values |
42 | * - verifiy correctness of values |
42 | * - clean up code :) |
43 | * - clean up code :) |
43 | */ |
44 | */ |
44 | 45 | ||
45 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
46 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
46 | // data structs not needed for character flashing |
47 | // data structs not needed for character flashing |
47 | #include "mk-data-structs.h" |
48 | #include "mk-data-structs.h" |
48 | 49 | ||
49 | /* ########################################################################## |
50 | /* ########################################################################## |
50 | * global definitions and global vars |
51 | * global definitions and global vars |
51 | * ##########################################################################*/ |
52 | * ##########################################################################*/ |
52 | 53 | ||
53 | volatile uint16_t setsReceived = 0; |
54 | volatile uint16_t setsReceived = 0; |
54 | 55 | ||
55 | volatile NaviData_t naviData; |
56 | volatile NaviData_t naviData; |
56 | volatile DebugOut_t debugData; |
57 | volatile DebugOut_t debugData; |
57 | 58 | ||
58 | // cache old vars for blinking attribute, checkup is faster than full |
59 | // cache old vars for blinking attribute, checkup is faster than full |
59 | // attribute write each time |
60 | // attribute write each time |
60 | volatile uint8_t last_UBat = 255; |
61 | volatile uint8_t last_UBat = 255; |
61 | volatile uint8_t last_RC_Quality = 255; |
62 | volatile uint8_t last_RC_Quality = 255; |
62 | 63 | ||
63 | // 16bit should be enough, normal LiPos don't last that long |
64 | // 16bit should be enough, normal LiPos don't last that long |
64 | volatile uint16_t uptime = 0; |
65 | volatile uint16_t uptime = 0; |
65 | volatile uint16_t timer = 0; |
66 | volatile uint16_t timer = 0; |
66 | 67 | ||
67 | // remember last time data was received |
68 | // remember last time data was received |
68 | volatile uint8_t seconds_since_last_data = 0; |
69 | volatile uint8_t seconds_since_last_data = 0; |
69 | 70 | ||
70 | // store stats description in progmem to save space |
71 | // store stats description in progmem to save space |
71 | char stats_item_0[] PROGMEM = "max Altitude:"; |
72 | char stats_item_0[] PROGMEM = "max Altitude:"; |
72 | char stats_item_1[] PROGMEM = "max Speed :"; |
73 | char stats_item_1[] PROGMEM = "max Speed :"; |
73 | char stats_item_2[] PROGMEM = "max Distance:"; |
74 | char stats_item_2[] PROGMEM = "max Distance:"; |
74 | char stats_item_3[] PROGMEM = "min voltage :"; |
75 | char stats_item_3[] PROGMEM = "min voltage :"; |
75 | char stats_item_4[] PROGMEM = "max time :"; |
76 | char stats_item_4[] PROGMEM = "max time :"; |
76 | char stats_item_5[] PROGMEM = "longitude :"; |
77 | char stats_item_5[] PROGMEM = "longitude :"; |
77 | char stats_item_6[] PROGMEM = "latitude :"; |
78 | char stats_item_6[] PROGMEM = "latitude :"; |
78 | char stats_item_7[] PROGMEM = "max current :"; |
79 | char stats_item_7[] PROGMEM = "max current :"; |
79 | char* stats_item_pointers[] PROGMEM = {stats_item_0, stats_item_1, stats_item_2, |
80 | char* stats_item_pointers[] PROGMEM = {stats_item_0, stats_item_1, stats_item_2, |
80 | stats_item_3, stats_item_4, stats_item_5, stats_item_6, stats_item_7}; |
81 | stats_item_3, stats_item_4, stats_item_5, stats_item_6, stats_item_7}; |
81 | 82 | ||
82 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
83 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
83 | 84 | ||
84 | // general PAL|NTSC distingiusch stuff |
85 | // general PAL|NTSC distingiusch stuff |
85 | uint8_t top_line = 1; |
86 | uint8_t top_line = 1; |
86 | uint8_t bottom_line = 14; |
87 | uint8_t bottom_line = 14; |
87 | 88 | ||
88 | // battery voltages |
89 | // battery voltages |
89 | uint8_t min_voltage = 0; |
90 | uint8_t min_voltage = 0; |
90 | uint8_t max_voltage = 0; |
91 | uint8_t max_voltage = 0; |
91 | 92 | ||
92 | // Flags |
93 | // Flags |
93 | uint8_t COSD_FLAGS = 0, COSD_FLAGS2 = 0; |
94 | uint8_t COSD_FLAGS = 0, COSD_FLAGS2 = 0; |
94 | 95 | ||
95 | /* ########################################################################## |
96 | /* ########################################################################## |
96 | * Interrupt handler |
97 | * Interrupt handler |
97 | * ##########################################################################*/ |
98 | * ##########################################################################*/ |
98 | 99 | ||
99 | /** |
100 | /** |
100 | * handler for undefined Interrupts |
101 | * handler for undefined Interrupts |
101 | * if not defined AVR will reset in case any unhandled interrupts occur |
102 | * if not defined AVR will reset in case any unhandled interrupts occur |
102 | */ |
103 | */ |
103 | ISR(__vector_default) { |
104 | ISR(__vector_default) { |
104 | asm("nop"); |
105 | asm("nop"); |
105 | } |
106 | } |
106 | 107 | ||
107 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
108 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
108 | /* ########################################################################## |
109 | /* ########################################################################## |
109 | * timer stuff |
110 | * timer stuff |
110 | * ##########################################################################*/ |
111 | * ##########################################################################*/ |
111 | 112 | ||
112 | /** |
113 | /** |
113 | * timer kicks in every 1000uS ^= 1ms |
114 | * timer kicks in every 1000uS ^= 1ms |
114 | */ |
115 | */ |
115 | ISR(TIMER0_OVF_vect) { |
116 | ISR(TIMER0_OVF_vect) { |
116 | OCR0 = 15; // preload |
117 | OCR0 = 15; // preload |
117 | if (!timer--) { |
118 | if (!timer--) { |
118 | uptime++; |
119 | uptime++; |
119 | timer = 999; |
120 | timer = 999; |
120 | seconds_since_last_data++; |
121 | seconds_since_last_data++; |
121 | } |
122 | } |
122 | // in case there is still some spi data to send do it now |
123 | // in case there is still some spi data to send do it now |
123 | if (spi_ready && icnt) { |
124 | if (spi_ready && icnt) { |
124 | SPDR = *iptr; |
125 | SPDR = *iptr; |
125 | } |
126 | } |
126 | } |
127 | } |
127 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
128 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
128 | 129 | ||
129 | /* ########################################################################## |
130 | /* ########################################################################## |
130 | * MAIN |
131 | * MAIN |
131 | * ##########################################################################*/ |
132 | * ##########################################################################*/ |
132 | int main(void) { |
133 | int main(void) { |
133 | 134 | ||
134 | // set up FLAGS, compiler should flatten this one |
135 | // set up FLAGS, compiler should flatten this one |
135 | COSD_FLAGS = (NTSC << 0); |
136 | COSD_FLAGS = (NTSC << 0); |
136 | COSD_FLAGS |= (HUD << 1); |
137 | COSD_FLAGS |= (HUD << 1); |
137 | COSD_FLAGS |= (ARTHORIZON << 2); |
138 | COSD_FLAGS |= (ARTHORIZON << 2); |
138 | COSD_FLAGS |= (BIGVARIO << 3); |
139 | COSD_FLAGS |= (BIGVARIO << 3); |
139 | COSD_FLAGS |= (STATS << 4); |
140 | COSD_FLAGS |= (STATS << 4); |
140 | COSD_FLAGS |= (WARNINGS << 5); |
141 | COSD_FLAGS |= (WARNINGS << 5); |
141 | 142 | ||
142 | // set up Atmega162 Ports |
143 | // set up Atmega162 Ports |
143 | DDRA |= (1 << PA1); // PA1 output (/CS) |
144 | DDRA |= (1 << PA1); // PA1 output (/CS) |
144 | MAX_CS_HIGH |
145 | MAX_CS_HIGH |
145 | DDRA |= (1 << PA2); // PA2 output (SDIN) |
146 | DDRA |= (1 << PA2); // PA2 output (SDIN) |
146 | MAX_SDIN_LOW |
147 | MAX_SDIN_LOW |
147 | DDRA |= (1 << PA3); // PA3 output (SCLK) |
148 | DDRA |= (1 << PA3); // PA3 output (SCLK) |
148 | MAX_SCLK_LOW |
149 | MAX_SCLK_LOW |
149 | DDRA |= (1 << PA5); // PA5 output (RESET) |
150 | DDRA |= (1 << PA5); // PA5 output (RESET) |
150 | MAX_RESET_HIGH |
151 | MAX_RESET_HIGH |
151 | 152 | ||
152 | DDRC |= (1 << PC0); // PC0 output (LED1 gn) |
153 | DDRC |= (1 << PC0); // PC0 output (LED1 gn) |
153 | LED1_OFF |
154 | LED1_OFF |
154 | DDRC |= (1 << PC1); // PC1 output (LED2 rt) |
155 | DDRC |= (1 << PC1); // PC1 output (LED2 rt) |
155 | LED2_OFF |
156 | LED2_OFF |
156 | DDRC |= (1 << PC2); // PC2 output (LED3 gn) |
157 | DDRC |= (1 << PC2); // PC2 output (LED3 gn) |
157 | LED3_OFF |
158 | LED3_OFF |
158 | DDRC |= (1 << PC3); // PC3 output (LED4 rt) |
159 | DDRC |= (1 << PC3); // PC3 output (LED4 rt) |
159 | LED4_OFF |
160 | LED4_OFF |
160 | 161 | ||
161 | DDRC &= ~(1 << PC4); // PC4 input (MODE) |
162 | DDRC &= ~(1 << PC4); // PC4 input (MODE) |
162 | PORTC |= (1 << PC4); // pullup |
163 | PORTC |= (1 << PC4); // pullup |
163 | DDRC &= ~(1 << PC5); // PC5 input (SET) |
164 | DDRC &= ~(1 << PC5); // PC5 input (SET) |
164 | PORTC |= (1 << PC5); // pullup |
165 | PORTC |= (1 << PC5); // pullup |
165 | 166 | ||
166 | // reset the MAX7456 to be sure any undefined states do no harm |
167 | // reset the MAX7456 to be sure any undefined states do no harm |
167 | MAX_RESET_LOW |
168 | MAX_RESET_LOW |
168 | MAX_RESET_HIGH |
169 | MAX_RESET_HIGH |
169 | 170 | ||
170 | // give the FC/NC and the maxim time to come up |
171 | // give the FC/NC and the maxim time to come up |
171 | LED4_ON |
172 | LED4_ON |
172 | _delay_ms(2000); |
173 | _delay_ms(2000); |
173 | LED4_OFF |
174 | LED4_OFF |
174 | 175 | ||
175 | //Pushing NEW chars to the MAX7456 |
176 | //Pushing NEW chars to the MAX7456 |
176 | #if (WRITECHARS != -1) |
177 | #if (WRITECHARS != -1) |
177 | // DISABLE display (VM0) |
178 | // DISABLE display (VM0) |
178 | spi_send_byte(0x00, 0b00000000); |
179 | spi_send_byte(0x00, 0b00000000); |
179 | #include "characters.c" |
180 | #include "characters.c" |
180 | #else |
181 | #else |
181 | // read out config for NTSC/PAL distinguishing |
182 | // read out config for NTSC/PAL distinguishing |
182 | get_eeprom(0); |
183 | get_eeprom(0); |
183 | #endif |
184 | #endif |
184 | 185 | ||
185 | // Setup Video Mode |
186 | // Setup Video Mode |
186 | if (COSD_FLAGS & COSD_FLAG_NTSC) { |
187 | if (COSD_FLAGS & COSD_FLAG_NTSC) { |
187 | // NTSC + enable display immediately (VM0) |
188 | // NTSC + enable display immediately (VM0) |
188 | spi_send_byte(0x00, 0b00001000); |
189 | spi_send_byte(0x00, 0b00001000); |
189 | 190 | ||
190 | bottom_line = 12; |
191 | bottom_line = 12; |
191 | } else { |
192 | } else { |
192 | // PAL + enable display immediately (VM0) |
193 | // PAL + enable display immediately (VM0) |
193 | spi_send_byte(0x00, 0b01001000); |
194 | spi_send_byte(0x00, 0b01001000); |
194 | 195 | ||
195 | bottom_line = 14; |
196 | bottom_line = 14; |
196 | } |
197 | } |
197 | 198 | ||
198 | /*// clear all display-mem (DMM) |
199 | /*// clear all display-mem (DMM) |
199 | spi_send_byte(0x04, 0b00000100); |
200 | spi_send_byte(0x04, 0b00000100); |
200 | 201 | ||
201 | // clearing takes 12uS according to maxim so lets wait longer |
202 | // clearing takes 12uS according to maxim so lets wait longer |
202 | _delay_us(120); |
203 | _delay_us(120); |
203 | 204 | ||
204 | // 8bit mode |
205 | // 8bit mode |
205 | spi_send_byte(0x04, 0b01000000);*/ |
206 | spi_send_byte(0x04, 0b01000000);*/ |
206 | 207 | ||
207 | // clear display memory and set to 8bit mode |
208 | // clear display memory and set to 8bit mode |
208 | clear(); |
209 | clear(); |
209 | 210 | ||
210 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
211 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
211 | // init usart |
212 | // init usart |
212 | usart1_init(); |
213 | usart1_init(); |
213 | 214 | ||
214 | // set up timer |
215 | // set up timer |
215 | TCCR0 |= (1 << CS00) | (1 << CS01); // timer0 prescaler 64 |
216 | TCCR0 |= (1 << CS00) | (1 << CS01); // timer0 prescaler 64 |
216 | OCR0 = 15; // preload |
217 | OCR0 = 15; // preload |
217 | TIMSK |= (1 << TOIE0); // enable overflow timer0 |
218 | TIMSK |= (1 << TOIE0); // enable overflow timer0 |
- | 219 | ||
218 | 220 | // SPI setup |
|
219 | DDRD |= (1 << PD2); // PD2 output (INT0) |
221 | DDRD |= (1 << PD2); // PD2 output (INT0) |
220 | SpiMasterInit(); |
222 | SpiMasterInit(); |
- | 223 | ||
- | 224 | // PPM detection setup |
|
- | 225 | ppm_init(); |
|
221 | 226 | ||
222 | // enable interrupts |
- | |
- | 227 | // enable interrupts |
|
223 | sei(); |
228 | |
224 | 229 | sei(); |
|
225 | #endif |
230 | #endif |
226 | 231 | ||
227 | //write_ascii_string(2, 7, " CaScAdE "); |
232 | //write_ascii_string(2, 7, " CaScAdE "); |
228 | //write_ascii_string(2, 8, "is TESTING his open source"); |
233 | //write_ascii_string(2, 8, "is TESTING his open source"); |
229 | //write_ascii_string(2, 9, " EPi OSD Firmware"); |
234 | //write_ascii_string(2, 9, " EPi OSD Firmware"); |
230 | 235 | ||
231 | // we are ready |
236 | // we are ready |
232 | LED3_ON |
237 | LED3_ON |
233 | 238 | ||
234 | #if ALLCHARSDEBUG | (WRITECHARS != -1) |
239 | #if ALLCHARSDEBUG | (WRITECHARS != -1) |
235 | clear(); |
240 | clear(); |
236 | write_all_chars(); |
241 | write_all_chars(); |
237 | #else |
242 | #else |
- | 243 | ||
238 | // clear serial screen |
244 | // clear serial screen |
239 | //usart1_puts("\x1B[2J\x1B[H"); |
245 | //usart1_puts("\x1B[2J\x1B[H"); |
240 | //usart1_puts("hello world!\r\n"); |
246 | //usart1_puts("hello world!123\r\n"); |
- | 247 | ||
241 | #if FCONLY |
248 | #if FCONLY |
242 | // request data ever 100ms from FC; |
249 | // request data ever 100ms from FC; |
243 | usart1_request_mk_data(0, 'd', 100); |
250 | usart1_request_mk_data(0, 'd', 100); |
244 | #else |
251 | #else |
245 | // request OSD Data from NC every 100ms |
252 | // request OSD Data from NC every 100ms |
246 | usart1_request_mk_data(1, 'o', 100); |
253 | usart1_request_mk_data(1, 'o', 100); |
247 | 254 | ||
248 | // and disable debug... |
255 | // and disable debug... |
249 | usart1_request_mk_data(0, 'd', 0); |
256 | usart1_request_mk_data(0, 'd', 0); |
250 | #endif |
257 | #endif |
251 | 258 | ||
252 | // stats for after flight |
259 | // stats for after flight |
253 | int16_t max_Altimeter = 0; |
260 | int16_t max_Altimeter = 0; |
254 | uint8_t min_UBat = 255; |
261 | uint8_t min_UBat = 255; |
255 | #if !(FCONLY) |
262 | #if !(FCONLY) |
256 | uint16_t max_GroundSpeed = 0; |
263 | uint16_t max_GroundSpeed = 0; |
257 | int16_t max_Distance = 0; |
264 | int16_t max_Distance = 0; |
258 | uint16_t max_FlyingTime = 0; |
265 | uint16_t max_FlyingTime = 0; |
259 | 266 | ||
260 | // flags from last round to check for changes |
267 | // flags from last round to check for changes |
261 | uint8_t old_MKFlags = 0; |
268 | uint8_t old_MKFlags = 0; |
262 | 269 | ||
263 | char* directions[8] = {"NE", "E ", "SE", "S ", "SW", "W ", "NW", "N "}; |
270 | char* directions[8] = {"NE", "E ", "SE", "S ", "SW", "W ", "NW", "N "}; |
264 | //char arrowdir[8] = {218, 217, 224, 223, 222, 221, 220, 219}; |
271 | //char arrowdir[8] = {218, 217, 224, 223, 222, 221, 220, 219}; |
265 | #endif |
272 | #endif |
266 | 273 | ||
267 | while (1) { |
274 | while (1) { |
268 | // in case SPI is ready and there is nothing to send right now |
275 | // in case SPI is ready and there is nothing to send right now |
269 | if (!icnt && spi_ready) { |
276 | if (!icnt && spi_ready) { |
270 | // correct transfer ends with d (done) |
277 | // correct transfer ends with d (done) |
271 | if (spi_cmd_buffer[0] == 'd') { |
278 | if (spi_cmd_buffer[0] == 'd') { |
272 | ampere = spi_cmd_buffer[1] << 8; |
279 | ampere = spi_cmd_buffer[1] << 8; |
273 | ampere |= spi_cmd_buffer[2]; |
280 | ampere |= spi_cmd_buffer[2]; |
274 | ampere_wasted = spi_cmd_buffer[3]; |
281 | ampere_wasted = spi_cmd_buffer[3]; |
275 | ampere_wasted = ampere_wasted << 8; |
282 | ampere_wasted = ampere_wasted << 8; |
276 | ampere_wasted |= spi_cmd_buffer[4]; |
283 | ampere_wasted |= spi_cmd_buffer[4]; |
277 | ampere_wasted = ampere_wasted << 8; |
284 | ampere_wasted = ampere_wasted << 8; |
278 | ampere_wasted |= spi_cmd_buffer[5]; |
285 | ampere_wasted |= spi_cmd_buffer[5]; |
279 | ampere_wasted = ampere_wasted << 8; |
286 | ampere_wasted = ampere_wasted << 8; |
280 | ampere_wasted |= spi_cmd_buffer[6]; |
287 | ampere_wasted |= spi_cmd_buffer[6]; |
281 | //ampere = *((int16_t *) spi_cmd_buffer + 1); |
288 | //ampere = *((int16_t *) spi_cmd_buffer + 1); |
282 | //ampere_wasted = *((int32_t *) &spi_cmd_buffer + 3); |
289 | //ampere_wasted = *((int32_t *) &spi_cmd_buffer + 3); |
283 | // if this is the first receival we should print the small A |
290 | // if this is the first receival we should print the small A |
284 | if (!(COSD_FLAGS2 & COSD_FLAG_STROMREC)) { |
291 | if (!(COSD_FLAGS2 & COSD_FLAG_STROMREC)) { |
285 | clear(); |
292 | clear(); |
286 | COSD_FLAGS2 &= ~COSD_ICONS_WRITTEN; |
293 | COSD_FLAGS2 &= ~COSD_ICONS_WRITTEN; |
287 | // update this flag |
294 | // update this flag |
288 | COSD_FLAGS2 |= COSD_FLAG_STROMREC; |
295 | COSD_FLAGS2 |= COSD_FLAG_STROMREC; |
289 | } |
296 | } |
290 | //write_ascii_char(8+4*30, 'v'); // valid |
297 | //write_ascii_char(8+4*30, 'v'); // valid |
291 | } else { |
298 | } else { |
292 | // update flags |
299 | // update flags |
293 | COSD_FLAGS2 &= ~COSD_FLAG_STROMREC; |
300 | COSD_FLAGS2 &= ~COSD_FLAG_STROMREC; |
294 | //write_ascii_char(8+4*30, 'i'); // invalid |
301 | //write_ascii_char(8+4*30, 'i'); // invalid |
295 | } |
302 | } |
296 | spi_cmd_buffer[0] = 'A'; |
303 | spi_cmd_buffer[0] = 'A'; |
297 | spi_cmd_buffer[1] = 'B'; |
304 | spi_cmd_buffer[1] = 'B'; |
298 | spi_cmd_buffer[2] = 'C'; |
305 | spi_cmd_buffer[2] = 'C'; |
299 | spi_cmd_buffer[3] = 'D'; |
306 | spi_cmd_buffer[3] = 'D'; |
300 | spi_cmd_buffer[4] = 'E'; |
307 | spi_cmd_buffer[4] = 'E'; |
301 | spi_cmd_buffer[5] = 'F'; |
308 | spi_cmd_buffer[5] = 'F'; |
302 | spi_cmd_buffer[6] = 'G'; |
309 | spi_cmd_buffer[6] = 'G'; |
303 | StartTransfer((unsigned char*) spi_cmd_buffer, 7); |
310 | StartTransfer((unsigned char*) spi_cmd_buffer, 7); |
304 | } |
311 | } |
305 | if (rxd_buffer_locked) { |
312 | if (rxd_buffer_locked) { |
306 | #if FCONLY |
313 | #if FCONLY |
307 | if (rxd_buffer[2] == 'D') { // FC Data |
314 | if (rxd_buffer[2] == 'D') { // FC Data |
308 | Decode64(); |
315 | Decode64(); |
309 | debugData = *((DebugOut_t*) pRxData); |
316 | debugData = *((DebugOut_t*) pRxData); |
310 | 317 | ||
311 | // init on first data retrival, distinguished by last battery :) |
318 | // init on first data retrival, distinguished by last battery :) |
312 | if (last_UBat == 255) { |
319 | if (last_UBat == 255) { |
313 | // fix for min_UBat |
320 | // fix for min_UBat |
314 | min_UBat = debugData.Analog[9]; |
321 | min_UBat = debugData.Analog[9]; |
315 | init_cosd(debugData.Analog[9]); |
322 | init_cosd(debugData.Analog[9]); |
316 | } |
323 | } |
317 | #include "osd_fcmode_default.c" |
324 | #include "osd_fcmode_default.c" |
318 | } |
325 | } |
319 | #else |
326 | #else |
320 | if (rxd_buffer[2] == 'O') { // NC OSD Data |
327 | if (rxd_buffer[2] == 'O') { // NC OSD Data |
321 | Decode64(); |
328 | Decode64(); |
322 | naviData = *((NaviData_t*) pRxData); |
329 | naviData = *((NaviData_t*) pRxData); |
323 | 330 | ||
324 | // init on first data retrival, distinguished by last battery :) |
331 | // init on first data retrival, distinguished by last battery :) |
325 | if (last_UBat == 255) { |
332 | if (last_UBat == 255) { |
326 | // fix for min_UBat |
333 | // fix for min_UBat |
327 | min_UBat = naviData.UBat; |
334 | min_UBat = naviData.UBat; |
328 | init_cosd(naviData.UBat); |
335 | init_cosd(naviData.UBat); |
329 | } |
336 | } |
330 | #include "osd_ncmode_default.c" |
337 | #include "osd_ncmode_default.c" |
331 | } |
338 | } |
332 | #endif |
339 | #endif |
333 | rxd_buffer_locked = 0; |
340 | rxd_buffer_locked = 0; |
334 | } |
341 | } |
335 | // handle keypress |
342 | // handle keypress |
336 | if (s1_pressed()) { |
343 | if (s1_pressed()) { |
337 | config_menu(); |
344 | config_menu(); |
338 | } |
345 | } |
339 | if (seconds_since_last_data > 2) { |
346 | if (seconds_since_last_data > 2) { |
340 | #if FCONLY |
347 | #if FCONLY |
341 | // request data ever 100ms from FC; |
348 | // request data ever 100ms from FC; |
342 | usart1_request_mk_data(0, 'd', 100); |
349 | usart1_request_mk_data(0, 'd', 100); |
343 | #else |
350 | #else |
344 | // request OSD Data from NC every 100ms |
351 | // request OSD Data from NC every 100ms |
345 | usart1_request_mk_data(1, 'o', 100); |
352 | usart1_request_mk_data(1, 'o', 100); |
346 | 353 | ||
347 | // and disable debug... |
354 | // and disable debug... |
348 | usart1_request_mk_data(0, 'd', 0); |
355 | usart1_request_mk_data(0, 'd', 0); |
- | 356 | ||
- | 357 | // reset last time counter |
|
- | 358 | seconds_since_last_data = 0; |
|
349 | #endif |
359 | #endif |
350 | } |
360 | } |
351 | } |
361 | } |
352 | #endif |
362 | #endif |
353 | return 0; |
363 | return 0; |
354 | } |
364 | } |
355 | 365 |