Rev 454 | Rev 457 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 454 | Rev 455 | ||
---|---|---|---|
Line 26... | Line 26... | ||
26 | ****************************************************************************/ |
26 | ****************************************************************************/ |
Line 27... | Line 27... | ||
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" |
Line 70... | Line 70... | ||
70 | char stats_item_2[] PROGMEM = "max Distance:"; |
70 | char stats_item_2[] PROGMEM = "max Distance:"; |
71 | char stats_item_3[] PROGMEM = "min voltage :"; |
71 | char stats_item_3[] PROGMEM = "min voltage :"; |
72 | char stats_item_4[] PROGMEM = "max time :"; |
72 | char stats_item_4[] PROGMEM = "max time :"; |
73 | char stats_item_5[] PROGMEM = "longitude :"; |
73 | char stats_item_5[] PROGMEM = "longitude :"; |
74 | char stats_item_6[] PROGMEM = "latitude :"; |
74 | char stats_item_6[] PROGMEM = "latitude :"; |
75 | char* stats_item_pointers[] PROGMEM = {stats_item_0, stats_item_1, stats_item_2, |
75 | char* stats_item_pointers[] PROGMEM = {stats_item_0, stats_item_1, stats_item_2, |
76 | stats_item_3, stats_item_4, stats_item_5, stats_item_6}; |
76 | stats_item_3, stats_item_4, stats_item_5, stats_item_6}; |
Line 77... | Line 77... | ||
77 | 77 | ||
78 | // store more fixed strings in progmen |
78 | // store more fixed strings in progmen |
79 | char ON[] PROGMEM = "ON "; |
79 | char ON[] PROGMEM = "ON "; |
Line 94... | Line 94... | ||
94 | 94 | ||
95 | /* ########################################################################## |
95 | /* ########################################################################## |
96 | * debounce buttons |
96 | * debounce buttons |
97 | * ##########################################################################*/ |
97 | * ##########################################################################*/ |
98 | int s1_pressed() { |
98 | int s1_pressed() { |
99 | if (S1_PRESSED) { |
99 | if (S1_PRESSED) { |
100 | _delay_ms(25); |
100 | _delay_ms(25); |
101 | if (S1_PRESSED) return 1; |
101 | if (S1_PRESSED) return 1; |
102 | } |
102 | } |
103 | return 0; |
103 | return 0; |
Line 104... | Line 104... | ||
104 | } |
104 | } |
105 | 105 | ||
106 | int s2_pressed() { |
106 | int s2_pressed() { |
107 | if (S2_PRESSED) { |
107 | if (S2_PRESSED) { |
108 | _delay_ms(25); |
108 | _delay_ms(25); |
109 | if (S2_PRESSED) return 1; |
109 | if (S2_PRESSED) return 1; |
110 | } |
110 | } |
Line 111... | Line 111... | ||
111 | return 0; |
111 | return 0; |
112 | } |
112 | } |
113 | 113 | ||
- | 114 | /* ########################################################################## |
|
114 | /* ########################################################################## |
115 | * Interrupt handler |
115 | * Interrupt handler |
116 | * ##########################################################################*/ |
116 | * ##########################################################################*/ |
117 | |
117 | /** |
118 | /** |
118 | * handler for undefined Interrupts |
119 | * handler for undefined Interrupts |
119 | * if not defined AVR will reset in case any unhandled interrupts occur |
120 | * if not defined AVR will reset in case any unhandled interrupts occur |
120 | */ |
121 | */ |
Line 121... | Line 122... | ||
121 | ISR(__vector_default) { |
122 | ISR(__vector_default) { |
122 | asm("nop"); |
123 | asm("nop"); |
123 | } |
124 | } |
124 | 125 | ||
- | 126 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
|
125 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
127 | /* ########################################################################## |
126 | /* ########################################################################## |
128 | * timer stuff |
127 | * timer stuff |
129 | * ##########################################################################*/ |
128 | * ##########################################################################*/ |
130 | |
129 | /** |
131 | /** |
130 | * timer kicks in every 1000uS ^= 1ms |
132 | * timer kicks in every 1000uS ^= 1ms |
131 | */ |
133 | */ |
132 | ISR(TIMER0_OVF_vect) { |
134 | ISR(TIMER0_OVF_vect) { |
133 | OCR0 = 15; // preload |
135 | OCR0 = 15; // preload |
134 | if (!timer--) { |
136 | if (!timer--) { |
135 | uptime++; |
137 | uptime++; |
Line 136... | Line 138... | ||
136 | timer = 999; |
138 | timer = 999; |
Line 152... | Line 154... | ||
152 | // draw current _cursor_ |
154 | // draw current _cursor_ |
153 | write_ascii_string(3, chosen + 5, ">"); |
155 | write_ascii_string(3, chosen + 5, ">"); |
154 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
156 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
155 | write_ascii_string_pgm(23, 5, ON); |
157 | write_ascii_string_pgm(23, 5, ON); |
156 | } else { |
158 | } else { |
157 | write_ascii_string_pgm(23, 5, OFF); |
159 | write_ascii_string_pgm(23, 5, OFF); |
158 | } |
160 | } |
159 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
161 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
160 | write_ascii_string_pgm(23, 6, ON); |
162 | write_ascii_string_pgm(23, 6, ON); |
161 | } else { |
163 | } else { |
162 | write_ascii_string_pgm(23, 6, OFF); |
164 | write_ascii_string_pgm(23, 6, OFF); |
163 | } |
165 | } |
164 | if (COSD_FLAGS & COSD_FLAG_BIGVARIO) { |
166 | if (COSD_FLAGS & COSD_FLAG_BIGVARIO) { |
165 | write_ascii_string_pgm(23, 7, ON); |
167 | write_ascii_string_pgm(23, 7, ON); |
166 | } else { |
168 | } else { |
167 | write_ascii_string_pgm(23, 7, OFF); |
169 | write_ascii_string_pgm(23, 7, OFF); |
168 | } |
170 | } |
169 | if (COSD_FLAGS & COSD_FLAG_STATS) { |
171 | if (COSD_FLAGS & COSD_FLAG_STATS) { |
170 | write_ascii_string_pgm(23, 8, ON); |
172 | write_ascii_string_pgm(23, 8, ON); |
171 | } else { |
173 | } else { |
172 | write_ascii_string_pgm(23, 8, OFF); |
174 | write_ascii_string_pgm(23, 8, OFF); |
173 | } |
175 | } |
174 | if (COSD_FLAGS & COSD_FLAG_WARNINGS) { |
176 | if (COSD_FLAGS & COSD_FLAG_WARNINGS) { |
Line 180... | Line 182... | ||
180 | 182 | ||
181 | /** |
183 | /** |
182 | * some sort of clicking response in the menu |
184 | * some sort of clicking response in the menu |
183 | */ |
185 | */ |
184 | void config_menu_doclick(uint8_t chosen, char** menu) { |
186 | void config_menu_doclick(uint8_t chosen, char** menu) { |
185 | write_ascii_string(4, chosen + 5, "DONE "); |
187 | write_ascii_string(4, chosen + 5, "DONE "); |
186 | _delay_ms(1000); |
188 | _delay_ms(1000); |
187 | write_ascii_string(4, chosen + 5, menu[chosen]); |
189 | write_ascii_string(4, chosen + 5, menu[chosen]); |
Line 188... | Line 190... | ||
188 | } |
190 | } |
189 | 191 | ||
190 | /** |
192 | /** |
191 | * a simple config menu tryout |
193 | * a simple config menu tryout |
192 | */ |
194 | */ |
193 | void config_menu(void) { |
195 | void config_menu(void) { |
- | 196 | // disable interrupts (makes the menu more smoothely) |
|
- | 197 | cli(); |
|
- | 198 | ||
Line 194... | Line -... | ||
194 | // disable interrupts (makes the menu more smoothely) |
- | |
195 | cli(); |
- | |
196 | - | ||
197 | // clear screen |
199 | // clear screen |
198 | clear(); |
200 | clear(); |
199 | 201 | ||
200 | char* menu[9] = {"Full HUD", |
202 | char* menu[9] = {"Full HUD", |
201 | "Art.Horizon in HUD", |
203 | "Art.Horizon in HUD", |
202 | "Big Vario bar", |
204 | "Big Vario bar", |
203 | "Statistics", |
205 | "Statistics", |
204 | "Warnings", // TODO: do it! |
206 | "Warnings", // TODO: do it! |
205 | "Reset uptime", |
207 | "Reset uptime", |
206 | "Request OSD-data", |
208 | "Request OSD-data", |
207 | "Disable Debug-data", |
209 | "Disable Debug-data", |
208 | "EXIT"}; |
210 | "EXIT"}; |
209 | 211 | ||
210 | uint8_t inmenu = 1; |
212 | uint8_t inmenu = 1; |
211 | uint8_t chosen = 0; |
213 | uint8_t chosen = 0; |
212 | write_ascii_string(6, 2, "C-OSD Config Menu"); |
214 | write_ascii_string(6, 2, "C-OSD Config Menu"); |
213 | 215 | ||
214 | // wait a bit before doing stuff so user has chance to release button |
216 | // wait a bit before doing stuff so user has chance to release button |
215 | _delay_ms(250); |
217 | _delay_ms(250); |
216 | 218 | ||
217 | write_ascii_string(4, 5, menu[0]); |
219 | write_ascii_string(4, 5, menu[0]); |
218 | write_ascii_string(4, 6, menu[1]); |
220 | write_ascii_string(4, 6, menu[1]); |
219 | write_ascii_string(4, 7, menu[2]); |
221 | write_ascii_string(4, 7, menu[2]); |
220 | write_ascii_string(4, 8, menu[3]); |
222 | write_ascii_string(4, 8, menu[3]); |
221 | write_ascii_string(4, 9, menu[4]); |
223 | write_ascii_string(4, 9, menu[4]); |
222 | write_ascii_string(4, 10, menu[5]); |
224 | write_ascii_string(4, 10, menu[5]); |
223 | write_ascii_string(4, 11, menu[6]); |
225 | write_ascii_string(4, 11, menu[6]); |
224 | write_ascii_string(4, 12, menu[7]); |
226 | write_ascii_string(4, 12, menu[7]); |
225 | write_ascii_string(4, 13, menu[8]); |
227 | write_ascii_string(4, 13, menu[8]); |
226 | 228 | ||
227 | config_menu_drawings(chosen); |
229 | config_menu_drawings(chosen); |
228 | 230 | ||
229 | while (inmenu) { |
231 | while (inmenu) { |
230 | if (s2_pressed()) { |
232 | if (s2_pressed()) { |
231 | write_ascii_string(3, chosen+5, " "); |
233 | write_ascii_string(3, chosen + 5, " "); |
232 | chosen = (chosen + 1) % 9; |
234 | chosen = (chosen + 1) % 9; |
233 | write_ascii_string(3, chosen+5, ">"); |
235 | write_ascii_string(3, chosen + 5, ">"); |
234 | _delay_ms(500); |
236 | _delay_ms(500); |
235 | } else if (s1_pressed()) { |
237 | } else if (s1_pressed()) { |
236 | switch (chosen) { |
238 | switch (chosen) { |
237 | case 0: // full HUD |
239 | case 0: // full HUD |
238 | COSD_FLAGS ^= COSD_FLAG_HUD; |
240 | COSD_FLAGS ^= COSD_FLAG_HUD; |
239 | config_menu_drawings(chosen); |
241 | config_menu_drawings(chosen); |
240 | break; |
242 | break; |
241 | case 1: // art horizon |
243 | case 1: // art horizon |
242 | COSD_FLAGS ^= COSD_FLAG_ARTHORIZON; |
244 | COSD_FLAGS ^= COSD_FLAG_ARTHORIZON; |
243 | config_menu_drawings(chosen); |
245 | config_menu_drawings(chosen); |
244 | break; |
246 | break; |
245 | case 2: // big vario |
247 | case 2: // big vario |
246 | COSD_FLAGS ^= COSD_FLAG_BIGVARIO; |
248 | COSD_FLAGS ^= COSD_FLAG_BIGVARIO; |
247 | config_menu_drawings(chosen); |
249 | config_menu_drawings(chosen); |
248 | break; |
250 | break; |
249 | case 3: // statistics |
251 | case 3: // statistics |
250 | COSD_FLAGS ^= COSD_FLAG_STATS; |
252 | COSD_FLAGS ^= COSD_FLAG_STATS; |
251 | config_menu_drawings(chosen); |
253 | config_menu_drawings(chosen); |
252 | break; |
254 | break; |
253 | case 4: // warnings |
255 | case 4: // warnings |
254 | COSD_FLAGS ^= COSD_FLAG_WARNINGS; |
256 | COSD_FLAGS ^= COSD_FLAG_WARNINGS; |
255 | config_menu_drawings(chosen); |
257 | config_menu_drawings(chosen); |
256 | break; |
258 | break; |
257 | case 5: // reset uptime |
259 | case 5: // reset uptime |
258 | uptime = 0; |
260 | uptime = 0; |
259 | config_menu_doclick(chosen, menu); |
261 | config_menu_doclick(chosen, menu); |
260 | break; |
262 | break; |
261 | case 6: // re-request OSD data |
263 | case 6: // re-request OSD data |
262 | #if FCONLY |
264 | #if FCONLY |
263 | // request data ever 100ms from FC; |
265 | // request data ever 100ms from FC; |
264 | usart1_request_mk_data(0, 'd', 100); |
266 | usart1_request_mk_data(0, 'd', 100); |
Line 265... | Line 267... | ||
265 | #else |
267 | #else |
266 | // request OSD Data from NC every 100ms |
268 | // request OSD Data from NC every 100ms |
267 | usart1_request_mk_data(1, 'o', 100); |
269 | usart1_request_mk_data(1, 'o', 100); |
268 | 270 | ||
269 | // and disable debug... |
271 | // and disable debug... |
270 | usart1_request_mk_data(0, 'd', 0); |
272 | usart1_request_mk_data(0, 'd', 0); |
271 | #endif |
273 | #endif |
272 | config_menu_doclick(chosen, menu); |
274 | config_menu_doclick(chosen, menu); |
273 | break; |
275 | break; |
274 | case 7: // disable debug data |
276 | case 7: // disable debug data |
275 | // disable sending of debug data |
277 | // disable sending of debug data |
276 | // may result in smoother ddata display |
278 | // may result in smoother ddata display |
277 | usart1_request_mk_data(0, 'd', 0); |
279 | usart1_request_mk_data(0, 'd', 0); |
278 | config_menu_doclick(chosen, menu); |
280 | config_menu_doclick(chosen, menu); |
279 | break; |
281 | break; |
280 | case 8: // exit |
282 | case 8: // exit |
281 | inmenu = 0; |
283 | inmenu = 0; |
282 | break; |
284 | break; |
Line 283... | Line 285... | ||
283 | } |
285 | } |
284 | _delay_ms(250); |
286 | _delay_ms(250); |
- | 287 | } |
|
- | 288 | } |
|
- | 289 | ||
Line 285... | Line 290... | ||
285 | } |
290 | // clear screen up again |
286 | } |
291 | clear(); |
- | 292 | ||
Line -... | Line 293... | ||
- | 293 | // update flags to paint display again if needed |
|
- | 294 | COSD_FLAGS &= ~COSD_ICONS_WRITTEN; |
|
- | 295 | ||
- | 296 | // enable interrupts again |
|
- | 297 | sei(); |
|
- | 298 | } |
|
- | 299 | ||
- | 300 | /** |
|
- | 301 | * auto config some stuff on startup, currently only battery cells |
|
- | 302 | * TODO: this is testing stuff, strings should go progmem and so on... |
|
- | 303 | */ |
|
- | 304 | void auto_config(uint8_t UBat, uint8_t* min_UBat) { |
|
- | 305 | clear(); |
|
- | 306 | // fix for min_bat glitch caused by data only gathered during motors up |
|
- | 307 | *min_UBat = UBat; |
|
- | 308 | write_ascii_string(2, 2, "C-OSD Initialisation"); |
|
- | 309 | #if FCONLY |
|
- | 310 | write_ascii_string(2, 3, "FC only Mode"); |
|
- | 311 | #else |
|
- | 312 | write_ascii_string(2, 3, "NaviCtrl Mode"); |
|
- | 313 | #endif |
|
287 | 314 | uint8_t cellnum = 0; |
|
- | 315 | if (CELL_NUM == -1) { |
|
- | 316 | write_ascii_string(2, 5, "Guessing Number of Cells"); |
|
- | 317 | do { |
|
- | 318 | cellnum++; |
|
- | 319 | } while (UBat > ((cellnum * CELL_VOLT_MAX) + 10)); |
|
- | 320 | } else { |
|
- | 321 | cellnum = CELL_NUM; |
|
- | 322 | } |
|
- | 323 | min_voltage = cellnum * CELL_VOLT_MIN; |
|
- | 324 | max_voltage = cellnum * CELL_VOLT_MAX; |
|
288 | // clear screen up again |
325 | write_ascii_string(2, 7, "Number of Cells:"); |
- | 326 | write_ndigit_number_u(21, 7, cellnum, 1, 0); |
|
- | 327 | write_ascii_string(2, 8, "Warn Voltage :"); |
|
289 | clear(); |
328 | write_ndigit_number_s_10th(20, 8, min_voltage, 100, 0); |
Line 290... | Line 329... | ||
290 | 329 | write_ascii_string(2, 9, "Max Voltage :"); |
|
- | 330 | write_ndigit_number_s_10th(20, 9, max_voltage, 100, 0); |
|
291 | // update flags to paint display again if needed |
331 | _delay_ms(200); |
292 | COSD_FLAGS &= ~COSD_ICONS_WRITTEN; |
332 | clear(); |
293 | 333 | // update flags to paint display again because of clear |
|
294 | // enable interrupts again |
334 | COSD_FLAGS &= ~COSD_ICONS_WRITTEN; |
295 | sei(); |
335 | } |
296 | } |
336 | |
297 | 337 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
|
298 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
338 | |
299 | /* ########################################################################## |
339 | /* ########################################################################## |
300 | * MAIN |
340 | * MAIN |
301 | * ##########################################################################*/ |
341 | * ##########################################################################*/ |
Line 302... | Line 342... | ||
302 | int main(void) { |
342 | int main(void) { |
303 | // set up FLAGS, compiler should flatten this one |
343 | // set up FLAGS, compiler should flatten this one |
304 | COSD_FLAGS = (NTSC << 0); |
344 | COSD_FLAGS = (NTSC << 0); |
Line 352... | Line 392... | ||
352 | 392 | ||
353 | //Pushing NEW chars to the MAX7456 |
393 | //Pushing NEW chars to the MAX7456 |
354 | #if (WRITECHARS != -1) |
394 | #if (WRITECHARS != -1) |
355 | // DISABLE display (VM0) |
395 | // DISABLE display (VM0) |
356 | spi_send_byte(0x00, 0b00000000); |
396 | spi_send_byte(0x00, 0b00000000); |
357 | #include "characters.c" |
- | |
358 | 397 | #include "characters.c" |
|
Line 359... | Line 398... | ||
359 | #endif |
398 | #endif |
360 | 399 | ||
361 | // Setup Video Mode |
400 | // Setup Video Mode |
362 | if (COSD_FLAGS & COSD_FLAG_NTSC) { |
401 | if (COSD_FLAGS & COSD_FLAG_NTSC) { |
Line 398... | Line 437... | ||
398 | 437 | ||
399 | // we are ready |
438 | // we are ready |
Line 400... | Line 439... | ||
400 | LED3_ON |
439 | LED3_ON |
401 | 440 | ||
402 | #if ALLCHARSDEBUG | (WRITECHARS != -1) |
441 | #if ALLCHARSDEBUG | (WRITECHARS != -1) |
403 | clear(); |
442 | clear(); |
404 | write_all_chars(); |
443 | write_all_chars(); |
405 | #else |
444 | #else |
406 | // clear serial screen |
445 | // clear serial screen |
407 | //usart1_puts("\x1B[2J\x1B[H"); |
- | |
408 | //usart1_puts("hello world!\r\n"); |
446 | //usart1_puts("\x1B[2J\x1B[H"); |
409 | 447 | //usart1_puts("hello world!\r\n"); |
|
410 | #if FCONLY |
448 | #if FCONLY |
411 | // request data ever 100ms from FC; |
449 | // request data ever 100ms from FC; |
412 | usart1_request_mk_data(0, 'd', 100); |
450 | usart1_request_mk_data(0, 'd', 100); |
413 | #else |
451 | #else |
Line 414... | Line 452... | ||
414 | // request OSD Data from NC every 100ms |
452 | // request OSD Data from NC every 100ms |
415 | usart1_request_mk_data(1, 'o', 100); |
453 | usart1_request_mk_data(1, 'o', 100); |
416 | 454 | ||
Line 417... | Line 455... | ||
417 | // and disable debug... |
455 | // and disable debug... |
418 | usart1_request_mk_data(0, 'd', 0); |
456 | usart1_request_mk_data(0, 'd', 0); |
419 | #endif |
457 | #endif |
Line 433... | Line 471... | ||
433 | 471 | ||
434 | while (1) { |
472 | while (1) { |
435 | // write icons at init or after menu/mode-switch |
473 | // write icons at init or after menu/mode-switch |
436 | if (!(COSD_FLAGS & COSD_ICONS_WRITTEN) && (COSD_FLAGS & COSD_FLAG_HUD)) { |
474 | if (!(COSD_FLAGS & COSD_ICONS_WRITTEN) && (COSD_FLAGS & COSD_FLAG_HUD)) { |
437 | #if FCONLY |
475 | #if FCONLY |
438 | // FC Mode ICONS |
476 | // FC Mode ICONS |
439 | write_char_xy(10, top_line, 0xCA); // RC-transmitter |
477 | write_char_xy(10, top_line, 0xCA); // RC-transmitter |
440 | write_char_xy(27, top_line, 0xCC); // small meters m height |
478 | write_char_xy(27, top_line, 0xCC); // small meters m height |
441 | write_char_xy(7, bottom_line, 0x9E); // small v |
479 | write_char_xy(7, bottom_line, 0x9E); // small v |
442 | #else |
480 | #else |
443 | // NAVI Mode ICONS |
481 | // NAVI Mode ICONS |
444 | write_char_xy(5, top_line, 0xCB); // km/h |
482 | write_char_xy(5, top_line, 0xCB); // km/h |
445 | write_char_xy(10, top_line, 0xCA); // RC-transmitter |
483 | write_char_xy(10, top_line, 0xCA); // RC-transmitter |
446 | write_char_xy(16, top_line, 0xD0); // degree symbol |
484 | write_char_xy(16, top_line, 0xD0); // degree symbol |
447 | write_char_xy(27, top_line, 0xCC); // small meters m height |
485 | write_char_xy(27, top_line, 0xCC); // small meters m height |
448 | write_char_xy(20, top_line+1, 0xB0); // left circle |
486 | write_char_xy(20, top_line + 1, 0xB0); // left circle |
449 | write_char_xy(22, top_line+1, 0xB2); // right circle |
487 | write_char_xy(22, top_line + 1, 0xB2); // right circle |
450 | write_char_xy(27, top_line+1, 0xCC); // small meters m home |
488 | write_char_xy(27, top_line + 1, 0xCC); // small meters m home |
451 | write_char_xy(7, bottom_line, 0x9E); // small v |
489 | write_char_xy(7, bottom_line, 0x9E); // small v |
452 | write_char_xy(14, bottom_line, 0xD1); // on clock |
490 | write_char_xy(14, bottom_line, 0xD1); // on clock |
453 | write_char_xy(21, bottom_line, 0xD2); // fly clock |
491 | write_char_xy(21, bottom_line, 0xD2); // fly clock |
454 | write_char_xy(26, bottom_line, 0xC8); // sat1 |
492 | write_char_xy(26, bottom_line, 0xC8); // sat1 |
455 | write_char_xy(27, bottom_line, 0xC9); // sat2 |
493 | write_char_xy(27, bottom_line, 0xC9); // sat2 |
Line 460... | Line 498... | ||
460 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
498 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
461 | #if FCONLY |
499 | #if FCONLY |
462 | if (rxd_buffer[2] == 'D') { // FC Data |
500 | if (rxd_buffer[2] == 'D') { // FC Data |
463 | Decode64(); |
501 | Decode64(); |
464 | debugData = *((DebugOut_t*) pRxData); |
502 | debugData = *((DebugOut_t*) pRxData); |
465 | write_ascii_string(2, 2, "FCONLY MODE"); |
- | |
Line -... | Line 503... | ||
- | 503 | ||
- | 504 | // init on first data retrival, distinguished by last battery :) |
|
- | 505 | if (last_UBat == 255) { |
|
- | 506 | auto_config(debugData.Analog[9], &min_UBat); |
|
- | 507 | } |
|
466 | 508 | ||
467 | write_ndigit_number_u(7, top_line, debugData.Analog[10], 100, 0); |
509 | write_ndigit_number_u(7, top_line, debugData.Analog[10], 100, 0); |
468 | if (debugData.Analog[10] <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) { |
510 | if (debugData.Analog[10] <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) { |
469 | for (uint8_t x = 0; x < 4; x++) |
511 | for (uint8_t x = 0; x < 4; x++) |
470 | write_char_att_xy(7 + x, top_line, BLINK); |
512 | write_char_att_xy(7 + x, top_line, BLINK); |
471 | } else if (debugData.Analog[10] > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) { |
513 | } else if (debugData.Analog[10] > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) { |
472 | for (uint8_t x = 0; x < 4; x++) |
514 | for (uint8_t x = 0; x < 4; x++) |
473 | write_char_att_xy(7 + x, top_line, 0); |
515 | write_char_att_xy(7 + x, top_line, 0); |
474 | } |
516 | } |
475 | last_RC_Quality = debugData.Analog[10]; |
- | |
476 | 517 | last_RC_Quality = debugData.Analog[10]; |
|
477 | - | ||
478 | if (debugData.Analog[5] > 300 || debugData.Analog[5] < -300) { |
- | |
479 | // above 10m only write full meters |
- | |
480 | write_ndigit_number_s(23, top_line, debugData.Analog[5] / 30, 1000, 0); |
- | |
481 | } else { |
- | |
482 | // up to 10m write meters.dm |
- | |
483 | write_ndigit_number_s_10th(23, top_line, debugData.Analog[5] / 3, 100, 0); |
- | |
Line -... | Line 518... | ||
- | 518 | ||
- | 519 | ||
- | 520 | if (debugData.Analog[5] > 300 || debugData.Analog[5] < -300) { |
|
- | 521 | // above 10m only write full meters |
|
- | 522 | write_ndigit_number_s(23, top_line, debugData.Analog[5] / 30, 1000, 0); |
|
- | 523 | } else { |
|
- | 524 | // up to 10m write meters.dm |
|
- | 525 | write_ndigit_number_s_10th(23, top_line, debugData.Analog[5] / 3, 100, 0); |
|
- | 526 | } |
|
- | 527 | ||
- | 528 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
|
- | 529 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
|
484 | } |
530 | } |
485 | 531 | ||
486 | draw_battery(2, bottom_line, min_voltage, debugData.Analog[9], max_voltage); |
532 | draw_battery(2, bottom_line, min_voltage, debugData.Analog[9], max_voltage); |
487 | write_ndigit_number_u_10th(3, bottom_line, debugData.Analog[9], 100, 0); |
533 | write_ndigit_number_u_10th(3, bottom_line, debugData.Analog[9], 100, 0); |
488 | if (debugData.Analog[9] <= min_voltage && last_UBat > min_voltage) { |
534 | if (debugData.Analog[9] <= min_voltage && last_UBat > min_voltage) { |
489 | for (uint8_t x = 2; x < 8; x++) |
535 | for (uint8_t x = 2; x < 8; x++) |
490 | write_char_att_xy(x, bottom_line, BLINK); |
536 | write_char_att_xy(x, bottom_line, BLINK); |
491 | } else if (debugData.Analog[9] > min_voltage && last_UBat < min_voltage) { |
537 | } else if (debugData.Analog[9] > min_voltage && last_UBat < min_voltage) { |
492 | for (uint8_t x = 2; x < 8; x++) |
538 | for (uint8_t x = 2; x < 8; x++) |
493 | write_char_att_xy(x, bottom_line, 0); |
539 | write_char_att_xy(x, bottom_line, 0); |
494 | } |
540 | } |
Line 495... | Line 541... | ||
495 | // remember last values |
541 | // remember last values |
496 | last_UBat = debugData.Analog[9]; |
542 | last_UBat = debugData.Analog[9]; |
497 | 543 | ||
498 | /* |
544 | /* |
499 | debugData.Analog[0]); // AngleNick |
545 | debugData.Analog[0]); // AngleNick |
500 | debugData.Analog[1]); // AngleRoll |
546 | debugData.Analog[1]); // AngleRoll |
501 | debugData.Analog[5]); // Height |
547 | debugData.Analog[5]); // Height |
502 | debugData.Analog[9]); // Voltage |
548 | debugData.Analog[9]); // Voltage |
503 | debugData.Analog[10]);// RC Signal |
549 | debugData.Analog[10]);// RC Signal |
504 | debugData.Analog[11]);// Gyro compass |
550 | debugData.Analog[11]);// Gyro compass |
505 | */ |
551 | */ |
506 | seconds_since_last_data = 0; |
552 | seconds_since_last_data = 0; |
507 | } |
553 | } |
508 | #else |
554 | #else |
509 | if (rxd_buffer[2] == 'O') { // NC OSD Data |
555 | if (rxd_buffer[2] == 'O') { // NC OSD Data |
510 | Decode64(); |
556 | Decode64(); |
511 | naviData = *((NaviData_t*) pRxData); |
- | |
512 | 557 | naviData = *((NaviData_t*) pRxData); |
|
513 | // init on first data retrival, distinguished by last battery :) |
- | |
514 | // TODO: this is testing stuff, strings should go progmem and so on... |
558 | |
515 | if (last_UBat == 255) { |
- | |
516 | clear(); |
- | |
517 | // fix for min_bat glitch caused by data only gathered during motors up |
- | |
518 | min_UBat = naviData.UBat; |
559 | // init on first data retrival, distinguished by last battery :) |
519 | write_ascii_string(2, 2, "C-OSD Initialisation"); |
- | |
520 | uint8_t cellnum = 0; |
- | |
521 | if (CELL_NUM == -1) { |
- | |
522 | write_ascii_string(2, 5, "Guessing Number of Cells"); |
- | |
523 | do { |
- | |
524 | cellnum++; |
- | |
525 | } while (naviData.UBat > ((cellnum * CELL_VOLT_MAX) + 10)); |
- | |
526 | } else { |
- | |
527 | cellnum = CELL_NUM; |
- | |
528 | } |
- | |
529 | min_voltage = cellnum * CELL_VOLT_MIN; |
- | |
530 | max_voltage = cellnum * CELL_VOLT_MAX; |
- | |
531 | write_ascii_string(2, 7, "Number of Cells:"); |
- | |
532 | write_ndigit_number_u(21, 7, cellnum, 1, 0); |
- | |
533 | write_ascii_string(2, 8, "Warn Voltage :"); |
- | |
534 | write_ndigit_number_s_10th(20, 8, min_voltage, 100, 0); |
- | |
535 | write_ascii_string(2, 9, "Max Voltage :"); |
- | |
536 | write_ndigit_number_s_10th(20, 9, max_voltage, 100, 0); |
- | |
537 | _delay_ms(200); |
- | |
538 | clear(); |
- | |
Line 539... | Line 560... | ||
539 | // update flags to paint display again because of clear |
560 | if (last_UBat == 255) { |
540 | COSD_FLAGS &= ~COSD_ICONS_WRITTEN; |
561 | auto_config(naviData.UBat, &min_UBat); |
Line 541... | Line 562... | ||
541 | } |
562 | } |
542 | 563 | ||
543 | // first line |
564 | // first line |
544 | write_ndigit_number_u(2, top_line, (uint16_t) (((uint32_t) naviData.GroundSpeed * (uint32_t)9) / (uint32_t)250), 100, 0); |
565 | write_ndigit_number_u(2, top_line, (uint16_t) (((uint32_t) naviData.GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 100, 0); |
545 | 566 | ||
546 | write_ndigit_number_u(7, top_line, naviData.RC_Quality, 100, 0); |
567 | write_ndigit_number_u(7, top_line, naviData.RC_Quality, 100, 0); |
547 | if (naviData.RC_Quality <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) { |
568 | if (naviData.RC_Quality <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) { |
548 | for (uint8_t x = 0; x < 4; x++) |
569 | for (uint8_t x = 0; x < 4; x++) |
549 | write_char_att_xy(7 + x, top_line, BLINK); |
570 | write_char_att_xy(7 + x, top_line, BLINK); |
550 | } else if (naviData.RC_Quality > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) { |
571 | } else if (naviData.RC_Quality > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) { |
551 | for (uint8_t x = 0; x < 4; x++) |
572 | for (uint8_t x = 0; x < 4; x++) |
552 | write_char_att_xy(7 + x, top_line, 0); |
573 | write_char_att_xy(7 + x, top_line, 0); |
553 | } |
574 | } |
554 | last_RC_Quality = naviData.RC_Quality; |
575 | last_RC_Quality = naviData.RC_Quality; |
555 | 576 | ||
Line 556... | Line 577... | ||
556 | if (naviData.NCFlags & NC_FLAG_NOSERIALLINK) { |
577 | if (naviData.NCFlags & NC_FLAG_NOSERIALLINK) { |
Line 557... | Line 578... | ||
557 | write_char_xy(11, top_line, 0); // clear |
578 | write_char_xy(11, top_line, 0); // clear |
558 | } else { |
579 | } else { |
559 | write_char_xy(11, top_line, 0xC6); // PC icon |
580 | write_char_xy(11, top_line, 0xC6); // PC icon |
Line 560... | Line 581... | ||
560 | } |
581 | } |
561 | 582 | ||
562 | write_ndigit_number_u(13, top_line, naviData.CompassHeading, 100, 0); |
583 | write_ndigit_number_u(13, top_line, naviData.CompassHeading, 100, 0); |
563 | 584 | ||
564 | write_ascii_string(17, top_line, directions[heading_conv(naviData.CompassHeading)]); |
585 | write_ascii_string(17, top_line, directions[heading_conv(naviData.CompassHeading)]); |
565 | 586 | ||
566 | draw_variometer(21, top_line, naviData.Variometer); |
587 | draw_variometer(21, top_line, naviData.Variometer); |
567 | 588 | ||
568 | //note:lephisto:according to several sources it's /30 |
589 | //note:lephisto:according to several sources it's /30 |
Line 569... | Line 590... | ||
569 | if (naviData.Altimeter > 300 || naviData.Altimeter < -300) { |
590 | if (naviData.Altimeter > 300 || naviData.Altimeter < -300) { |
570 | // above 10m only write full meters |
591 | // above 10m only write full meters |
Line 571... | Line 592... | ||
571 | write_ndigit_number_s(23, top_line, naviData.Altimeter / 30, 1000, 0); |
592 | write_ndigit_number_s(23, top_line, naviData.Altimeter / 30, 1000, 0); |
572 | } else { |
593 | } else { |
573 | // up to 10m write meters.dm |
594 | // up to 10m write meters.dm |
574 | //write_number_u_10th(21, top_line, naviData.Altimeter / 3); |
595 | //write_number_u_10th(21, top_line, naviData.Altimeter / 3); |
575 | write_ndigit_number_s_10th(23, top_line, naviData.Altimeter / 3, 100, 0); |
596 | write_ndigit_number_s_10th(23, top_line, naviData.Altimeter / 3, 100, 0); |
Line 576... | Line 597... | ||
576 | } |
597 | } |
Line 577... | Line 598... | ||
577 | 598 | ||
578 | // seccond line |
599 | // seccond line |
Line 594... | Line 615... | ||
594 | COSD_FLAGS &= ~COSD_ICONS_WRITTEN; |
615 | COSD_FLAGS &= ~COSD_ICONS_WRITTEN; |
595 | } |
616 | } |
596 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
617 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
597 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
618 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
598 | } |
619 | } |
599 | // motors are on, assume we were/are flying |
620 | // motors are on, assume we were/are flying |
600 | COSD_FLAGS |= COSD_WASFLYING; |
621 | COSD_FLAGS |= COSD_WASFLYING; |
601 | } else { |
622 | } else { |
602 | // stats |
623 | // stats |
603 | if ((COSD_FLAGS & COSD_WASFLYING) && (COSD_FLAGS & COSD_FLAG_STATS)) { |
624 | if ((COSD_FLAGS & COSD_WASFLYING) && (COSD_FLAGS & COSD_FLAG_STATS)) { |
604 | write_ascii_string_pgm(2, 4, stats_item_pointers[0]); // max Altitude |
625 | write_ascii_string_pgm(2, 4, stats_item_pointers[0]); // max Altitude |
605 | write_ndigit_number_s(18, 4, max_Altimeter / 30, 1000, 0); |
626 | write_ndigit_number_s(18, 4, max_Altimeter / 30, 1000, 0); |
606 | write_char_xy(22, 4, 204); // small meters m |
627 | write_char_xy(22, 4, 204); // small meters m |
607 | write_ascii_string_pgm(2, 5, stats_item_pointers[1]); // max Speed |
628 | write_ascii_string_pgm(2, 5, stats_item_pointers[1]); // max Speed |
608 | write_ndigit_number_u(19, 5, (uint16_t) (((uint32_t) max_GroundSpeed * (uint32_t)9) / (uint32_t)250), 100, 0); |
629 | write_ndigit_number_u(19, 5, (uint16_t) (((uint32_t) max_GroundSpeed * (uint32_t) 9) / (uint32_t) 250), 100, 0); |
609 | write_char_xy(22, 5, 203); // km/h |
630 | write_char_xy(22, 5, 203); // km/h |
610 | write_ascii_string_pgm(2, 6, stats_item_pointers[2]); // max Distance |
631 | write_ascii_string_pgm(2, 6, stats_item_pointers[2]); // max Distance |
611 | write_ndigit_number_u(19, 6, max_Distance / 10, 100, 0); |
632 | write_ndigit_number_u(19, 6, max_Distance / 10, 100, 0); |
612 | write_char_xy(22, 6, 204); // small meters m |
633 | write_char_xy(22, 6, 204); // small meters m |
613 | write_ascii_string_pgm(2, 7, stats_item_pointers[3]); // min voltage |
634 | write_ascii_string_pgm(2, 7, stats_item_pointers[3]); // min voltage |
614 | write_ndigit_number_u_10th(18, 7, min_UBat, 100, 0); |
635 | write_ndigit_number_u_10th(18, 7, min_UBat, 100, 0); |
615 | write_char_xy(22, 7, 0x9E); // small v |
636 | write_char_xy(22, 7, 0x9E); // small v |
616 | write_ascii_string_pgm(2, 8, stats_item_pointers[4]); // max time |
637 | write_ascii_string_pgm(2, 8, stats_item_pointers[4]); // max time |
617 | write_time(16, 8, max_FlyingTime); |
638 | write_time(16, 8, max_FlyingTime); |
618 | write_char_xy(22, 8, 210); // fly clock |
639 | write_char_xy(22, 8, 210); // fly clock |
619 | write_ascii_string_pgm(2, 9, stats_item_pointers[5]); // longitude |
640 | write_ascii_string_pgm(2, 9, stats_item_pointers[5]); // longitude |
620 | write_gps_pos(15, 9, naviData.CurrentPosition.Longitude); |
641 | write_gps_pos(15, 9, naviData.CurrentPosition.Longitude); |
621 | write_ascii_string_pgm(2, 10, stats_item_pointers[6]); // latitude |
642 | write_ascii_string_pgm(2, 10, stats_item_pointers[6]); // latitude |
622 | write_gps_pos(15, 10, naviData.CurrentPosition.Latitude); |
643 | write_gps_pos(15, 10, naviData.CurrentPosition.Latitude); |
623 | } else if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon |
644 | } else if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon |
624 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
645 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
625 | } |
646 | } |
626 | } |
647 | } |
627 | if (COSD_FLAGS & COSD_FLAG_BIGVARIO) { |
648 | if (COSD_FLAGS & COSD_FLAG_BIGVARIO) { |
628 | draw_big_variometer(27, 8, naviData.Variometer); |
649 | draw_big_variometer(27, 8, naviData.Variometer); |
629 | } |
650 | } |
Line 630... | Line 651... | ||
630 | 651 | ||
631 | // bottom line |
652 | // bottom line |
632 | draw_battery(2, bottom_line, min_voltage, naviData.UBat, max_voltage); |
653 | draw_battery(2, bottom_line, min_voltage, naviData.UBat, max_voltage); |
633 | write_ndigit_number_u_10th(3, bottom_line, naviData.UBat, 100, 0); |
654 | write_ndigit_number_u_10th(3, bottom_line, naviData.UBat, 100, 0); |
634 | if (naviData.UBat <= min_voltage && last_UBat > min_voltage) { |
655 | if (naviData.UBat <= min_voltage && last_UBat > min_voltage) { |
635 | for (uint8_t x = 2; x < 8; x++) |
656 | for (uint8_t x = 2; x < 8; x++) |
636 | write_char_att_xy(x, bottom_line, BLINK); |
657 | write_char_att_xy(x, bottom_line, BLINK); |
637 | } else if (naviData.UBat > min_voltage && last_UBat < min_voltage) { |
658 | } else if (naviData.UBat > min_voltage && last_UBat < min_voltage) { |
638 | for (uint8_t x = 2; x < 8; x++) |
659 | for (uint8_t x = 2; x < 8; x++) |
639 | write_char_att_xy(x, bottom_line, 0); |
660 | write_char_att_xy(x, bottom_line, 0); |
640 | } |
661 | } |
641 | // remember last values |
662 | // remember last values |
Line 642... | Line 663... | ||
642 | last_UBat = naviData.UBat; |
663 | last_UBat = naviData.UBat; |
643 | 664 | ||
Line 644... | Line 665... | ||
644 | write_time(8, bottom_line, uptime); |
665 | write_time(8, bottom_line, uptime); |
Line 645... | Line 666... | ||
645 | write_time(15, bottom_line, naviData.FlyingTime); |
666 | write_time(15, bottom_line, naviData.FlyingTime); |
646 | 667 | ||
647 | write_ndigit_number_u(24, bottom_line, naviData.SatsInUse, 10, 0); |
668 | write_ndigit_number_u(24, bottom_line, naviData.SatsInUse, 10, 0); |
648 | 669 | ||
649 | if (naviData.NCFlags & NC_FLAG_MANUAL_CONTROL) { |
670 | if (naviData.NCFlags & NC_FLAG_MANUAL_CONTROL) { |
Line 662... | Line 683... | ||
662 | 683 | ||
663 | //write_number_s(8, 5, RxDataLen); |
684 | //write_number_s(8, 5, RxDataLen); |
Line 664... | Line 685... | ||
664 | //write_number_s(16, 5, setsReceived++); |
685 | //write_number_s(16, 5, setsReceived++); |
665 | 686 | ||
666 | // remember statistics (only when engines running) |
687 | // remember statistics (only when engines running) |
667 | if (naviData.MKFlags & FLAG_MOTOR_RUN) { |
688 | if (naviData.MKFlags & FLAG_MOTOR_RUN) { |
668 | if (naviData.Altimeter > max_Altimeter) max_Altimeter = naviData.Altimeter; |
689 | if (naviData.Altimeter > max_Altimeter) max_Altimeter = naviData.Altimeter; |
669 | if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed; |
690 | if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed; |
670 | if (naviData.HomePositionDeviation.Distance > max_Distance) { |
691 | if (naviData.HomePositionDeviation.Distance > max_Distance) { |
671 | max_Distance = naviData.HomePositionDeviation.Distance; |
692 | max_Distance = naviData.HomePositionDeviation.Distance; |
672 | } |
693 | } |
673 | if (naviData.UBat < min_UBat) min_UBat = naviData.UBat; |
694 | if (naviData.UBat < min_UBat) min_UBat = naviData.UBat; |
Line 674... | Line 695... | ||
674 | if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime; |
695 | if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime; |
675 | } |
696 | } |
676 | 697 | ||
677 | old_MKFlags = naviData.MKFlags; |
698 | old_MKFlags = naviData.MKFlags; |
678 | seconds_since_last_data = 0; |
699 | seconds_since_last_data = 0; |
679 | } |
700 | } |
680 | #endif |
701 | #endif |
Line 685... | Line 706... | ||
685 | if (s1_pressed()) { |
706 | if (s1_pressed()) { |
686 | config_menu(); |
707 | config_menu(); |
687 | } |
708 | } |
688 | if (seconds_since_last_data > 2) { |
709 | if (seconds_since_last_data > 2) { |
689 | #if FCONLY |
710 | #if FCONLY |
690 | // request data ever 100ms from FC; |
711 | // request data ever 100ms from FC; |
691 | usart1_request_mk_data(0, 'd', 100); |
712 | usart1_request_mk_data(0, 'd', 100); |
692 | #else |
713 | #else |
693 | // request OSD Data from NC every 100ms |
714 | // request OSD Data from NC every 100ms |
694 | usart1_request_mk_data(1, 'o', 100); |
715 | usart1_request_mk_data(1, 'o', 100); |
Line 695... | Line 716... | ||
695 | 716 | ||
696 | // and disable debug... |
717 | // and disable debug... |
697 | usart1_request_mk_data(0, 'd', 0); |
718 | usart1_request_mk_data(0, 'd', 0); |
698 | #endif |
719 | #endif |
699 | } |
720 | } |
700 | } |
721 | } |
701 | #endif |
722 | #endif |