Rev 412 | Rev 454 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 412 | Rev 453 | ||
---|---|---|---|
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 * |
22 | * Holger Buss & Ingo Busker from mikrokopter.de for the MK project * |
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 | 36 | ||
37 | /* TODO: |
37 | /* TODO: |
38 | * - verifiy correctness of values |
38 | * - verifiy correctness of values |
39 | * - clean up code :) |
39 | * - clean up code :) |
40 | */ |
40 | */ |
41 | 41 | ||
42 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
42 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
43 | // data structs not needed for character flashin |
43 | // data structs not needed for character flashin |
44 | #include "mk-data-structs.h" |
44 | #include "mk-data-structs.h" |
45 | 45 | ||
46 | /* ########################################################################## |
46 | /* ########################################################################## |
47 | * global definitions and global vars |
47 | * global definitions and global vars |
48 | * ##########################################################################*/ |
48 | * ##########################################################################*/ |
49 | 49 | ||
50 | volatile uint16_t setsReceived = 0; |
50 | volatile uint16_t setsReceived = 0; |
51 | 51 | ||
52 | volatile NaviData_t naviData; |
52 | volatile NaviData_t naviData; |
53 | volatile DebugOut_t debugData; |
53 | volatile DebugOut_t debugData; |
54 | 54 | ||
55 | // cache old vars for blinking attribute, checkup is faster than full |
55 | // cache old vars for blinking attribute, checkup is faster than full |
56 | // attribute write each time |
56 | // attribute write each time |
57 | volatile uint8_t last_UBat = 255; |
57 | volatile uint8_t last_UBat = 255; |
58 | volatile uint8_t last_RC_Quality = 255; |
58 | volatile uint8_t last_RC_Quality = 255; |
59 | 59 | ||
60 | // 16bit should be enough, normal LiPos don't last that long |
60 | // 16bit should be enough, normal LiPos don't last that long |
61 | volatile uint16_t uptime = 0; |
61 | volatile uint16_t uptime = 0; |
62 | volatile uint16_t timer = 0; |
62 | volatile uint16_t timer = 0; |
63 | 63 | ||
64 | // remember last time data was received |
64 | // remember last time data was received |
65 | volatile uint8_t seconds_since_last_data = 0; |
65 | volatile uint8_t seconds_since_last_data = 0; |
66 | 66 | ||
67 | // store stats description in progmem to save space |
67 | // store stats description in progmem to save space |
68 | char stats_item_0[] PROGMEM = "max Altitude:"; |
68 | char stats_item_0[] PROGMEM = "max Altitude:"; |
69 | char stats_item_1[] PROGMEM = "max Speed :"; |
69 | char stats_item_1[] PROGMEM = "max Speed :"; |
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}; |
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 "; |
80 | char OFF[] PROGMEM = "OFF"; |
80 | char OFF[] PROGMEM = "OFF"; |
81 | 81 | ||
82 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
82 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
83 | 83 | ||
84 | // general PAL|NTSC distingiusch stuff |
84 | // general PAL|NTSC distingiusch stuff |
85 | uint8_t top_line = 1; |
85 | uint8_t top_line = 1; |
86 | uint8_t bottom_line = 14; |
86 | uint8_t bottom_line = 14; |
- | 87 | ||
- | 88 | // battery voltages |
|
- | 89 | uint8_t min_voltage = 0; |
|
- | 90 | uint8_t max_voltage = 0; |
|
87 | 91 | ||
88 | // Flags |
92 | // Flags |
89 | uint8_t COSD_FLAGS = 0; |
93 | uint8_t COSD_FLAGS = 0; |
90 | 94 | ||
91 | /* ########################################################################## |
95 | /* ########################################################################## |
92 | * debounce buttons |
96 | * debounce buttons |
93 | * ##########################################################################*/ |
97 | * ##########################################################################*/ |
94 | int s1_pressed() { |
98 | int s1_pressed() { |
95 | if (S1_PRESSED) { |
99 | if (S1_PRESSED) { |
96 | _delay_ms(25); |
100 | _delay_ms(25); |
97 | if (S1_PRESSED) return 1; |
101 | if (S1_PRESSED) return 1; |
98 | } |
102 | } |
99 | return 0; |
103 | return 0; |
100 | } |
104 | } |
101 | 105 | ||
102 | int s2_pressed() { |
106 | int s2_pressed() { |
103 | if (S2_PRESSED) { |
107 | if (S2_PRESSED) { |
104 | _delay_ms(25); |
108 | _delay_ms(25); |
105 | if (S2_PRESSED) return 1; |
109 | if (S2_PRESSED) return 1; |
106 | } |
110 | } |
107 | return 0; |
111 | return 0; |
108 | } |
112 | } |
109 | 113 | ||
110 | /* ########################################################################## |
114 | /* ########################################################################## |
111 | * Interrupt handler |
115 | * Interrupt handler |
112 | * ##########################################################################*/ |
116 | * ##########################################################################*/ |
113 | /** |
117 | /** |
114 | * handler for undefined Interrupts |
118 | * handler for undefined Interrupts |
115 | * if not defined AVR will reset in case any unhandled interrupts occur |
119 | * if not defined AVR will reset in case any unhandled interrupts occur |
116 | */ |
120 | */ |
117 | ISR(__vector_default) { |
121 | ISR(__vector_default) { |
118 | asm("nop"); |
122 | asm("nop"); |
119 | } |
123 | } |
120 | 124 | ||
121 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
125 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
122 | /* ########################################################################## |
126 | /* ########################################################################## |
123 | * timer stuff |
127 | * timer stuff |
124 | * ##########################################################################*/ |
128 | * ##########################################################################*/ |
125 | /** |
129 | /** |
126 | * timer kicks in every 1000uS ^= 1ms |
130 | * timer kicks in every 1000uS ^= 1ms |
127 | */ |
131 | */ |
128 | ISR(TIMER0_OVF_vect) { |
132 | ISR(TIMER0_OVF_vect) { |
129 | OCR0 = 15; // preload |
133 | OCR0 = 15; // preload |
130 | if (!timer--) { |
134 | if (!timer--) { |
131 | uptime++; |
135 | uptime++; |
132 | timer = 999; |
136 | timer = 999; |
133 | seconds_since_last_data++; |
137 | seconds_since_last_data++; |
134 | } |
138 | } |
135 | } |
139 | } |
136 | 140 | ||
137 | 141 | ||
138 | /* ########################################################################## |
142 | /* ########################################################################## |
139 | * A simple config menu for the flags |
143 | * A simple config menu for the flags |
140 | * ##########################################################################*/ |
144 | * ##########################################################################*/ |
141 | 145 | ||
142 | /** |
146 | /** |
143 | * helper function for menu updating |
147 | * helper function for menu updating |
144 | */ |
148 | */ |
145 | void config_menu_drawings(uint8_t chosen) { |
149 | void config_menu_drawings(uint8_t chosen) { |
146 | // clear prevoius _cursor_ |
150 | // clear prevoius _cursor_ |
147 | write_ascii_string(3, (chosen + 5) % 8, " "); |
151 | write_ascii_string(3, (chosen + 5) % 8, " "); |
148 | // draw current _cursor_ |
152 | // draw current _cursor_ |
149 | write_ascii_string(3, chosen + 5, ">"); |
153 | write_ascii_string(3, chosen + 5, ">"); |
150 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
154 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
151 | write_ascii_string_pgm(23, 5, ON); |
155 | write_ascii_string_pgm(23, 5, ON); |
152 | } else { |
156 | } else { |
153 | write_ascii_string_pgm(23, 5, OFF); |
157 | write_ascii_string_pgm(23, 5, OFF); |
154 | } |
158 | } |
155 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
159 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
156 | write_ascii_string_pgm(23, 6, ON); |
160 | write_ascii_string_pgm(23, 6, ON); |
157 | } else { |
161 | } else { |
158 | write_ascii_string_pgm(23, 6, OFF); |
162 | write_ascii_string_pgm(23, 6, OFF); |
159 | } |
163 | } |
160 | if (COSD_FLAGS & COSD_FLAG_BIGVARIO) { |
164 | if (COSD_FLAGS & COSD_FLAG_BIGVARIO) { |
161 | write_ascii_string_pgm(23, 7, ON); |
165 | write_ascii_string_pgm(23, 7, ON); |
162 | } else { |
166 | } else { |
163 | write_ascii_string_pgm(23, 7, OFF); |
167 | write_ascii_string_pgm(23, 7, OFF); |
164 | } |
168 | } |
165 | if (COSD_FLAGS & COSD_FLAG_STATS) { |
169 | if (COSD_FLAGS & COSD_FLAG_STATS) { |
166 | write_ascii_string_pgm(23, 8, ON); |
170 | write_ascii_string_pgm(23, 8, ON); |
167 | } else { |
171 | } else { |
168 | write_ascii_string_pgm(23, 8, OFF); |
172 | write_ascii_string_pgm(23, 8, OFF); |
169 | } |
173 | } |
170 | if (COSD_FLAGS & COSD_FLAG_WARNINGS) { |
174 | if (COSD_FLAGS & COSD_FLAG_WARNINGS) { |
171 | write_ascii_string_pgm(23, 9, ON); |
175 | write_ascii_string_pgm(23, 9, ON); |
172 | } else { |
176 | } else { |
173 | write_ascii_string_pgm(23, 9, OFF); |
177 | write_ascii_string_pgm(23, 9, OFF); |
174 | } |
178 | } |
175 | } |
179 | } |
176 | 180 | ||
177 | /** |
181 | /** |
178 | * some sort of clicking response in the menu |
182 | * some sort of clicking response in the menu |
179 | */ |
183 | */ |
180 | void config_menu_doclick(uint8_t chosen, char** menu) { |
184 | void config_menu_doclick(uint8_t chosen, char** menu) { |
181 | write_ascii_string(4, chosen + 5, "DONE "); |
185 | write_ascii_string(4, chosen + 5, "DONE "); |
182 | _delay_ms(1000); |
186 | _delay_ms(1000); |
183 | write_ascii_string(4, chosen + 5, menu[chosen]); |
187 | write_ascii_string(4, chosen + 5, menu[chosen]); |
184 | } |
188 | } |
185 | 189 | ||
186 | /** |
190 | /** |
187 | * a simple config menu tryout |
191 | * a simple config menu tryout |
188 | */ |
192 | */ |
189 | void config_menu(void) { |
193 | void config_menu(void) { |
190 | // disable interrupts (makes the menu more smoothely) |
194 | // disable interrupts (makes the menu more smoothely) |
191 | cli(); |
195 | cli(); |
192 | 196 | ||
193 | // clear screen |
197 | // clear screen |
194 | clear(); |
198 | clear(); |
195 | 199 | ||
196 | char* menu[9] = {"Full HUD", |
200 | char* menu[9] = {"Full HUD", |
197 | "Art.Horizon in HUD", |
201 | "Art.Horizon in HUD", |
198 | "Big Vario bar", |
202 | "Big Vario bar", |
199 | "Statistics", |
203 | "Statistics", |
200 | "Warnings", // TODO: do it! |
204 | "Warnings", // TODO: do it! |
201 | "Reset uptime", |
205 | "Reset uptime", |
202 | "Request OSD-data", |
206 | "Request OSD-data", |
203 | "Disable Debug-data", |
207 | "Disable Debug-data", |
204 | "EXIT"}; |
208 | "EXIT"}; |
205 | 209 | ||
206 | uint8_t inmenu = 1; |
210 | uint8_t inmenu = 1; |
207 | uint8_t chosen = 0; |
211 | uint8_t chosen = 0; |
208 | write_ascii_string(6, 2, "C-OSD Config Menu"); |
212 | write_ascii_string(6, 2, "C-OSD Config Menu"); |
209 | 213 | ||
210 | // wait a bit before doing stuff so user has chance to release button |
214 | // wait a bit before doing stuff so user has chance to release button |
211 | _delay_ms(250); |
215 | _delay_ms(250); |
212 | 216 | ||
213 | write_ascii_string(4, 5, menu[0]); |
217 | write_ascii_string(4, 5, menu[0]); |
214 | write_ascii_string(4, 6, menu[1]); |
218 | write_ascii_string(4, 6, menu[1]); |
215 | write_ascii_string(4, 7, menu[2]); |
219 | write_ascii_string(4, 7, menu[2]); |
216 | write_ascii_string(4, 8, menu[3]); |
220 | write_ascii_string(4, 8, menu[3]); |
217 | write_ascii_string(4, 9, menu[4]); |
221 | write_ascii_string(4, 9, menu[4]); |
218 | write_ascii_string(4, 10, menu[5]); |
222 | write_ascii_string(4, 10, menu[5]); |
219 | write_ascii_string(4, 11, menu[6]); |
223 | write_ascii_string(4, 11, menu[6]); |
220 | write_ascii_string(4, 12, menu[7]); |
224 | write_ascii_string(4, 12, menu[7]); |
221 | write_ascii_string(4, 13, menu[8]); |
225 | write_ascii_string(4, 13, menu[8]); |
222 | 226 | ||
223 | config_menu_drawings(chosen); |
227 | config_menu_drawings(chosen); |
224 | 228 | ||
225 | while (inmenu) { |
229 | while (inmenu) { |
226 | if (s2_pressed()) { |
230 | if (s2_pressed()) { |
227 | write_ascii_string(3, chosen+5, " "); |
231 | write_ascii_string(3, chosen+5, " "); |
228 | chosen = (chosen + 1) % 9; |
232 | chosen = (chosen + 1) % 9; |
229 | write_ascii_string(3, chosen+5, ">"); |
233 | write_ascii_string(3, chosen+5, ">"); |
230 | _delay_ms(500); |
234 | _delay_ms(500); |
231 | } else if (s1_pressed()) { |
235 | } else if (s1_pressed()) { |
232 | switch (chosen) { |
236 | switch (chosen) { |
233 | case 0: // full HUD |
237 | case 0: // full HUD |
234 | COSD_FLAGS ^= COSD_FLAG_HUD; |
238 | COSD_FLAGS ^= COSD_FLAG_HUD; |
235 | config_menu_drawings(chosen); |
239 | config_menu_drawings(chosen); |
236 | break; |
240 | break; |
237 | case 1: // art horizon |
241 | case 1: // art horizon |
238 | COSD_FLAGS ^= COSD_FLAG_ARTHORIZON; |
242 | COSD_FLAGS ^= COSD_FLAG_ARTHORIZON; |
239 | config_menu_drawings(chosen); |
243 | config_menu_drawings(chosen); |
240 | break; |
244 | break; |
241 | case 2: // big vario |
245 | case 2: // big vario |
242 | COSD_FLAGS ^= COSD_FLAG_BIGVARIO; |
246 | COSD_FLAGS ^= COSD_FLAG_BIGVARIO; |
243 | config_menu_drawings(chosen); |
247 | config_menu_drawings(chosen); |
244 | break; |
248 | break; |
245 | case 3: // statistics |
249 | case 3: // statistics |
246 | COSD_FLAGS ^= COSD_FLAG_STATS; |
250 | COSD_FLAGS ^= COSD_FLAG_STATS; |
247 | config_menu_drawings(chosen); |
251 | config_menu_drawings(chosen); |
248 | break; |
252 | break; |
249 | case 4: // warnings |
253 | case 4: // warnings |
250 | COSD_FLAGS ^= COSD_FLAG_WARNINGS; |
254 | COSD_FLAGS ^= COSD_FLAG_WARNINGS; |
251 | config_menu_drawings(chosen); |
255 | config_menu_drawings(chosen); |
252 | break; |
256 | break; |
253 | case 5: // reset uptime |
257 | case 5: // reset uptime |
254 | uptime = 0; |
258 | uptime = 0; |
255 | config_menu_doclick(chosen, menu); |
259 | config_menu_doclick(chosen, menu); |
256 | break; |
260 | break; |
257 | case 6: // re-request OSD data |
261 | case 6: // re-request OSD data |
258 | // request OSD Data from NC every 100ms |
262 | // request OSD Data from NC every 100ms |
259 | usart1_request_mk_data(1, 'o', 100); |
263 | usart1_request_mk_data(1, 'o', 100); |
260 | config_menu_doclick(chosen, menu); |
264 | config_menu_doclick(chosen, menu); |
261 | break; |
265 | break; |
262 | case 7: // disable debug data |
266 | case 7: // disable debug data |
263 | // disable sending of debug data |
267 | // disable sending of debug data |
264 | // may result in smoother ddata display |
268 | // may result in smoother ddata display |
265 | usart1_request_mk_data(0, 'd', 0); |
269 | usart1_request_mk_data(0, 'd', 0); |
266 | config_menu_doclick(chosen, menu); |
270 | config_menu_doclick(chosen, menu); |
267 | break; |
271 | break; |
268 | case 8: // exit |
272 | case 8: // exit |
269 | inmenu = 0; |
273 | inmenu = 0; |
270 | break; |
274 | break; |
271 | } |
275 | } |
272 | _delay_ms(250); |
276 | _delay_ms(250); |
273 | } |
277 | } |
274 | } |
278 | } |
275 | 279 | ||
276 | // clear screen up again |
280 | // clear screen up again |
277 | clear(); |
281 | clear(); |
278 | 282 | ||
279 | // update flags to paint display again if needed |
283 | // update flags to paint display again if needed |
280 | COSD_FLAGS &= ~COSD_ICONS_WRITTEN; |
284 | COSD_FLAGS &= ~COSD_ICONS_WRITTEN; |
281 | 285 | ||
282 | // enable interrupts again |
286 | // enable interrupts again |
283 | sei(); |
287 | sei(); |
284 | } |
288 | } |
285 | 289 | ||
286 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
290 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
287 | /* ########################################################################## |
291 | /* ########################################################################## |
288 | * MAIN |
292 | * MAIN |
289 | * ##########################################################################*/ |
293 | * ##########################################################################*/ |
290 | int main(void) { |
294 | int main(void) { |
291 | // set up FLAGS, compiler should flatten this one |
295 | // set up FLAGS, compiler should flatten this one |
292 | COSD_FLAGS = (NTSC << 0); |
296 | COSD_FLAGS = (NTSC << 0); |
293 | COSD_FLAGS |= (HUD << 1); |
297 | COSD_FLAGS |= (HUD << 1); |
294 | COSD_FLAGS |= (ARTHORIZON << 2); |
298 | COSD_FLAGS |= (ARTHORIZON << 2); |
295 | COSD_FLAGS |= (BIGVARIO << 3); |
299 | COSD_FLAGS |= (BIGVARIO << 3); |
296 | COSD_FLAGS |= (STATS << 4); |
300 | COSD_FLAGS |= (STATS << 4); |
297 | COSD_FLAGS |= (WARNINGS << 5); |
301 | COSD_FLAGS |= (WARNINGS << 5); |
298 | 302 | ||
299 | // set up Atmega162 Ports |
303 | // set up Atmega162 Ports |
300 | DDRA |= (1 << PA1); // PA1 output (/CS) |
304 | DDRA |= (1 << PA1); // PA1 output (/CS) |
301 | MAX_CS_HIGH |
305 | MAX_CS_HIGH |
302 | DDRA |= (1 << PA2); // PA2 output (SDIN) |
306 | DDRA |= (1 << PA2); // PA2 output (SDIN) |
303 | MAX_SDIN_LOW |
307 | MAX_SDIN_LOW |
304 | DDRA |= (1 << PA3); // PA3 output (SCLK) |
308 | DDRA |= (1 << PA3); // PA3 output (SCLK) |
305 | MAX_SCLK_LOW |
309 | MAX_SCLK_LOW |
306 | DDRA |= (1 << PA5); // PA5 output (RESET) |
310 | DDRA |= (1 << PA5); // PA5 output (RESET) |
307 | MAX_RESET_HIGH |
311 | MAX_RESET_HIGH |
308 | 312 | ||
309 | DDRC |= (1 << PC0); // PC0 output (LED1 gn) |
313 | DDRC |= (1 << PC0); // PC0 output (LED1 gn) |
310 | LED1_OFF |
314 | LED1_OFF |
311 | DDRC |= (1 << PC1); // PC1 output (LED2 rt) |
315 | DDRC |= (1 << PC1); // PC1 output (LED2 rt) |
312 | LED2_OFF |
316 | LED2_OFF |
313 | DDRC |= (1 << PC2); // PC2 output (LED3 gn) |
317 | DDRC |= (1 << PC2); // PC2 output (LED3 gn) |
314 | LED3_OFF |
318 | LED3_OFF |
315 | DDRC |= (1 << PC3); // PC3 output (LED4 rt) |
319 | DDRC |= (1 << PC3); // PC3 output (LED4 rt) |
316 | LED4_OFF |
320 | LED4_OFF |
317 | 321 | ||
318 | DDRC &= ~(1 << PC4); // PC4 input (MODE) |
322 | DDRC &= ~(1 << PC4); // PC4 input (MODE) |
319 | PORTC |= (1 << PC4); // pullup |
323 | PORTC |= (1 << PC4); // pullup |
320 | DDRC &= ~(1 << PC5); // PC5 input (SET) |
324 | DDRC &= ~(1 << PC5); // PC5 input (SET) |
321 | PORTC |= (1 << PC5); // pullup |
325 | PORTC |= (1 << PC5); // pullup |
322 | 326 | ||
323 | // set up top and bottom lines |
327 | // set up top and bottom lines |
324 | if (COSD_FLAGS & COSD_FLAG_NTSC) { |
328 | if (COSD_FLAGS & COSD_FLAG_NTSC) { |
325 | bottom_line = 12; |
329 | bottom_line = 12; |
326 | } else { |
330 | } else { |
327 | bottom_line = 14; |
331 | bottom_line = 14; |
328 | } |
332 | } |
329 | 333 | ||
330 | // reset the MAX7456 to be sure any undefined states do no harm |
334 | // reset the MAX7456 to be sure any undefined states do no harm |
331 | MAX_RESET_LOW |
335 | MAX_RESET_LOW |
332 | MAX_RESET_HIGH |
336 | MAX_RESET_HIGH |
333 | 337 | ||
334 | // give the FC/NC and the maxim time to come up |
338 | // give the FC/NC and the maxim time to come up |
335 | LED4_ON |
339 | LED4_ON |
336 | _delay_ms(2000); |
340 | _delay_ms(2000); |
337 | 341 | ||
338 | LED4_OFF |
342 | LED4_OFF |
339 | 343 | ||
340 | 344 | ||
341 | //Pushing NEW chars to the MAX7456 |
345 | //Pushing NEW chars to the MAX7456 |
342 | #if (WRITECHARS != -1) |
346 | #if (WRITECHARS != -1) |
343 | // DISABLE display (VM0) |
347 | // DISABLE display (VM0) |
344 | spi_send_byte(0x00, 0b00000000); |
348 | spi_send_byte(0x00, 0b00000000); |
345 | #include "characters.c" |
349 | #include "characters.c" |
346 | 350 | ||
347 | #endif |
351 | #endif |
348 | 352 | ||
349 | // Setup Video Mode |
353 | // Setup Video Mode |
350 | if (COSD_FLAGS & COSD_FLAG_NTSC) { |
354 | if (COSD_FLAGS & COSD_FLAG_NTSC) { |
351 | // NTSC + enable display immediately (VM0) |
355 | // NTSC + enable display immediately (VM0) |
352 | spi_send_byte(0x00, 0b00001000); |
356 | spi_send_byte(0x00, 0b00001000); |
353 | } else { |
357 | } else { |
354 | // PAL + enable display immediately (VM0) |
358 | // PAL + enable display immediately (VM0) |
355 | spi_send_byte(0x00, 0b01001000); |
359 | spi_send_byte(0x00, 0b01001000); |
356 | } |
360 | } |
357 | 361 | ||
358 | /*// clear all display-mem (DMM) |
362 | /*// clear all display-mem (DMM) |
359 | spi_send_byte(0x04, 0b00000100); |
363 | spi_send_byte(0x04, 0b00000100); |
360 | 364 | ||
361 | // clearing takes 12uS according to maxim so lets wait longer |
365 | // clearing takes 12uS according to maxim so lets wait longer |
362 | _delay_us(120); |
366 | _delay_us(120); |
363 | 367 | ||
364 | // 8bit mode |
368 | // 8bit mode |
365 | spi_send_byte(0x04, 0b01000000);*/ |
369 | spi_send_byte(0x04, 0b01000000);*/ |
366 | 370 | ||
367 | // clear display memory and set to 8bit mode |
371 | // clear display memory and set to 8bit mode |
368 | clear(); |
372 | clear(); |
369 | 373 | ||
370 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
374 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
371 | // init usart |
375 | // init usart |
372 | usart1_init(); |
376 | usart1_init(); |
373 | 377 | ||
374 | // set up timer |
378 | // set up timer |
375 | TCCR0 |= (1 << CS00) | (1 << CS01); // timer0 prescaler 64 |
379 | TCCR0 |= (1 << CS00) | (1 << CS01); // timer0 prescaler 64 |
376 | OCR0 = 15; // preload |
380 | OCR0 = 15; // preload |
377 | TIMSK |= (1 << TOIE0); // enable overflow timer0 |
381 | TIMSK |= (1 << TOIE0); // enable overflow timer0 |
378 | 382 | ||
379 | // enable interrupts |
383 | // enable interrupts |
380 | sei(); |
384 | sei(); |
381 | #endif |
385 | #endif |
382 | 386 | ||
383 | //write_ascii_string(2, 7, " CaScAdE "); |
387 | //write_ascii_string(2, 7, " CaScAdE "); |
384 | //write_ascii_string(2, 8, "is TESTING his open source"); |
388 | //write_ascii_string(2, 8, "is TESTING his open source"); |
385 | //write_ascii_string(2, 9, " EPi OSD Firmware"); |
389 | //write_ascii_string(2, 9, " EPi OSD Firmware"); |
386 | 390 | ||
387 | // we are ready |
391 | // we are ready |
388 | LED3_ON |
392 | LED3_ON |
389 | 393 | ||
390 | #if ALLCHARSDEBUG | (WRITECHARS != -1) |
394 | #if ALLCHARSDEBUG | (WRITECHARS != -1) |
391 | clear(); |
395 | clear(); |
392 | write_all_chars(); |
396 | write_all_chars(); |
393 | #else |
397 | #else |
394 | // clear serial screen |
398 | // clear serial screen |
395 | //usart1_puts("\x1B[2J\x1B[H"); |
399 | //usart1_puts("\x1B[2J\x1B[H"); |
396 | //usart1_puts("hello world!\r\n"); |
400 | //usart1_puts("hello world!\r\n"); |
397 | 401 | ||
398 | 402 | ||
399 | // request data ever 100ms from FC; |
403 | // request data ever 100ms from FC; |
400 | //usart1_request_mk_data(0, 'd', 100); |
404 | //usart1_request_mk_data(0, 'd', 100); |
401 | 405 | ||
402 | // request OSD Data from NC every 100ms |
406 | // request OSD Data from NC every 100ms |
403 | usart1_request_mk_data(1, 'o', 100); |
407 | usart1_request_mk_data(1, 'o', 100); |
404 | 408 | ||
405 | // and disable debug... |
409 | // and disable debug... |
406 | usart1_request_mk_data(0, 'd', 0); |
410 | usart1_request_mk_data(0, 'd', 0); |
407 | 411 | ||
408 | // stats for after flight |
412 | // stats for after flight |
409 | int16_t max_Altimeter = 0; |
413 | int16_t max_Altimeter = 0; |
410 | uint16_t max_GroundSpeed = 0; |
414 | uint16_t max_GroundSpeed = 0; |
411 | int16_t max_Distance = 0; |
415 | int16_t max_Distance = 0; |
412 | uint8_t min_UBat = 255; |
416 | uint8_t min_UBat = 255; |
413 | uint16_t max_FlyingTime = 0; |
417 | uint16_t max_FlyingTime = 0; |
414 | 418 | ||
415 | // flags from last round to check for changes |
419 | // flags from last round to check for changes |
416 | uint8_t old_MKFlags = 0; |
420 | uint8_t old_MKFlags = 0; |
417 | 421 | ||
418 | char* directions[8] = {"NE", "E ", "SE", "S ", "SW", "W ", "NW", "N "}; |
422 | char* directions[8] = {"NE", "E ", "SE", "S ", "SW", "W ", "NW", "N "}; |
419 | //char arrowdir[8] = {218, 217, 224, 223, 222, 221, 220, 219}; |
423 | //char arrowdir[8] = {218, 217, 224, 223, 222, 221, 220, 219}; |
420 | 424 | ||
421 | while (1) { |
425 | while (1) { |
422 | // write icons at init or after menu/mode-switch |
426 | // write icons at init or after menu/mode-switch |
423 | if (!(COSD_FLAGS & COSD_ICONS_WRITTEN) && (COSD_FLAGS & COSD_FLAG_HUD)) { |
427 | if (!(COSD_FLAGS & COSD_ICONS_WRITTEN) && (COSD_FLAGS & COSD_FLAG_HUD)) { |
424 | write_char_xy(5, top_line, 0xCB); // km/h |
428 | write_char_xy(5, top_line, 0xCB); // km/h |
425 | write_char_xy(10, top_line, 0xCA); // RC-transmitter |
429 | write_char_xy(10, top_line, 0xCA); // RC-transmitter |
426 | write_char_xy(16, top_line, 0xD0); // degree symbol |
430 | write_char_xy(16, top_line, 0xD0); // degree symbol |
427 | write_char_xy(27, top_line, 0xCC); // small meters m height |
431 | write_char_xy(27, top_line, 0xCC); // small meters m height |
428 | write_char_xy(20, top_line+1, 0xB0); // left circle |
432 | write_char_xy(20, top_line+1, 0xB0); // left circle |
429 | write_char_xy(22, top_line+1, 0xB2); // right circle |
433 | write_char_xy(22, top_line+1, 0xB2); // right circle |
430 | write_char_xy(27, top_line+1, 0xCC); // small meters m home |
434 | write_char_xy(27, top_line+1, 0xCC); // small meters m home |
431 | write_char_xy(7, bottom_line, 0x9E); // small v |
435 | write_char_xy(7, bottom_line, 0x9E); // small v |
432 | write_char_xy(14, bottom_line, 0xD1); // on clock |
436 | write_char_xy(14, bottom_line, 0xD1); // on clock |
433 | write_char_xy(21, bottom_line, 0xD2); // fly clock |
437 | write_char_xy(21, bottom_line, 0xD2); // fly clock |
434 | write_char_xy(26, bottom_line, 0xC8); // sat1 |
438 | write_char_xy(26, bottom_line, 0xC8); // sat1 |
435 | write_char_xy(27, bottom_line, 0xC9); // sat2 |
439 | write_char_xy(27, bottom_line, 0xC9); // sat2 |
436 | COSD_FLAGS |= COSD_ICONS_WRITTEN; |
440 | COSD_FLAGS |= COSD_ICONS_WRITTEN; |
437 | } |
441 | } |
438 | if (rxd_buffer_locked) { |
442 | if (rxd_buffer_locked) { |
439 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
443 | if (COSD_FLAGS & COSD_FLAG_HUD) { |
440 | if (rxd_buffer[2] == 'D') { // FC Data |
444 | if (rxd_buffer[2] == 'D') { // FC Data |
441 | /*Decode64(); |
445 | /*Decode64(); |
442 | debugData = *((DebugOut_t*) pRxData); |
446 | debugData = *((DebugOut_t*) pRxData); |
443 | write_number_s(12, 2, RxDataLen); |
447 | write_number_s(12, 2, RxDataLen); |
444 | write_number_s(20, 2, setsReceived++); |
448 | write_number_s(20, 2, setsReceived++); |
445 | write_number_s(12, 3, debugData.Analog[0]); // AngleNick |
449 | write_number_s(12, 3, debugData.Analog[0]); // AngleNick |
446 | write_number_s(12, 4, debugData.Analog[1]); // AngleRoll |
450 | write_number_s(12, 4, debugData.Analog[1]); // AngleRoll |
447 | write_number_s(12, 5, debugData.Analog[5]); // Height |
451 | write_number_s(12, 5, debugData.Analog[5]); // Height |
448 | write_number_s(12, 6, debugData.Analog[9]); // Voltage |
452 | write_number_s(12, 6, debugData.Analog[9]); // Voltage |
449 | write_number_s(12, 7, debugData.Analog[10]);// RC Signal |
453 | write_number_s(12, 7, debugData.Analog[10]);// RC Signal |
450 | write_number_s(12, 8, debugData.Analog[11]);// Gyro compass |
454 | write_number_s(12, 8, debugData.Analog[11]);// Gyro compass |
451 | seconds_since_last_data = 0;*/ |
455 | seconds_since_last_data = 0;*/ |
452 | } else if (rxd_buffer[2] == 'O') { // NC OSD Data |
456 | } else if (rxd_buffer[2] == 'O') { // NC OSD Data |
453 | Decode64(); |
457 | Decode64(); |
454 | naviData = *((NaviData_t*) pRxData); |
458 | naviData = *((NaviData_t*) pRxData); |
- | 459 | ||
- | 460 | // init on first data retrival, distinguished by last battery :) |
|
- | 461 | // TODO: this is testing stuff, strings should go progmem and so on... |
|
- | 462 | if (last_UBat == 255) { |
|
- | 463 | clear(); |
|
- | 464 | // fix for min_bat glitch caused by data only gathered during motors up |
|
- | 465 | min_UBat = naviData.UBat; |
|
- | 466 | write_ascii_string(2, 2, "C-OSD Initialisation"); |
|
- | 467 | uint8_t cellnum = 0; |
|
- | 468 | if (CELL_NUM == -1) { |
|
- | 469 | write_ascii_string(2, 5, "Guessing Number of Cells"); |
|
- | 470 | do { |
|
- | 471 | cellnum++; |
|
- | 472 | } while (naviData.UBat > ((cellnum * CELL_VOLT_MAX) + 10)); |
|
- | 473 | } else { |
|
- | 474 | cellnum = CELL_NUM; |
|
- | 475 | } |
|
- | 476 | min_voltage = cellnum * CELL_VOLT_MIN; |
|
- | 477 | max_voltage = cellnum * CELL_VOLT_MAX; |
|
- | 478 | write_ascii_string(2, 7, "Number of Cells:"); |
|
- | 479 | write_ndigit_number_u(21, 7, cellnum, 1, 0); |
|
- | 480 | write_ascii_string(2, 8, "Warn Voltage :"); |
|
- | 481 | write_ndigit_number_s_10th(20, 8, min_voltage, 100, 0); |
|
- | 482 | write_ascii_string(2, 9, "Max Voltage :"); |
|
- | 483 | write_ndigit_number_s_10th(20, 9, max_voltage, 100, 0); |
|
- | 484 | _delay_ms(200); |
|
- | 485 | clear(); |
|
- | 486 | // update flags to paint display again because of clear |
|
- | 487 | COSD_FLAGS &= ~COSD_ICONS_WRITTEN; |
|
- | 488 | } |
|
455 | 489 | ||
456 | // first line |
490 | // first line |
457 | write_ndigit_number_u(2, top_line, (uint16_t) (((uint32_t) naviData.GroundSpeed * (uint32_t)9) / (uint32_t)250), 100, 0); |
491 | write_ndigit_number_u(2, top_line, (uint16_t) (((uint32_t) naviData.GroundSpeed * (uint32_t)9) / (uint32_t)250), 100, 0); |
458 | 492 | ||
459 | write_ndigit_number_u(7, top_line, naviData.RC_Quality, 100, 0); |
493 | write_ndigit_number_u(7, top_line, naviData.RC_Quality, 100, 0); |
460 | if (naviData.RC_Quality <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) { |
494 | if (naviData.RC_Quality <= RCLVL_WRN && last_RC_Quality > RCLVL_WRN) { |
461 | for (uint8_t x = 0; x < 4; x++) |
495 | for (uint8_t x = 0; x < 4; x++) |
462 | write_char_att_xy(7 + x, top_line, BLINK); |
496 | write_char_att_xy(7 + x, top_line, BLINK); |
463 | } else if (naviData.RC_Quality > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) { |
497 | } else if (naviData.RC_Quality > RCLVL_WRN && last_RC_Quality <= RCLVL_WRN) { |
464 | for (uint8_t x = 0; x < 4; x++) |
498 | for (uint8_t x = 0; x < 4; x++) |
465 | write_char_att_xy(7 + x, top_line, 0); |
499 | write_char_att_xy(7 + x, top_line, 0); |
466 | } |
500 | } |
467 | last_RC_Quality = naviData.RC_Quality; |
501 | last_RC_Quality = naviData.RC_Quality; |
468 | 502 | ||
469 | if (naviData.NCFlags & NC_FLAG_NOSERIALLINK) { |
503 | if (naviData.NCFlags & NC_FLAG_NOSERIALLINK) { |
470 | write_char_xy(11, top_line, 0); // clear |
504 | write_char_xy(11, top_line, 0); // clear |
471 | } else { |
505 | } else { |
472 | write_char_xy(11, top_line, 0xC6); // PC icon |
506 | write_char_xy(11, top_line, 0xC6); // PC icon |
473 | } |
507 | } |
474 | 508 | ||
475 | write_ndigit_number_u(13, top_line, naviData.CompassHeading, 100, 0); |
509 | write_ndigit_number_u(13, top_line, naviData.CompassHeading, 100, 0); |
476 | 510 | ||
477 | write_ascii_string(17, top_line, directions[heading_conv(naviData.CompassHeading)]); |
511 | write_ascii_string(17, top_line, directions[heading_conv(naviData.CompassHeading)]); |
478 | 512 | ||
479 | draw_variometer(21, top_line, naviData.Variometer); |
513 | draw_variometer(21, top_line, naviData.Variometer); |
480 | 514 | ||
481 | //note:lephisto:according to several sources it's /30 |
515 | //note:lephisto:according to several sources it's /30 |
482 | if (naviData.Altimeter > 300 || naviData.Altimeter < -300) { |
516 | if (naviData.Altimeter > 300 || naviData.Altimeter < -300) { |
483 | // above 10m only write full meters |
517 | // above 10m only write full meters |
484 | write_ndigit_number_s(23, top_line, naviData.Altimeter / 30, 1000, 0); |
518 | write_ndigit_number_s(23, top_line, naviData.Altimeter / 30, 1000, 0); |
485 | } else { |
519 | } else { |
486 | // up to 10m write meters.dm |
520 | // up to 10m write meters.dm |
487 | //write_number_u_10th(21, top_line, naviData.Altimeter / 3); |
521 | //write_number_u_10th(21, top_line, naviData.Altimeter / 3); |
488 | write_ndigit_number_s_10th(23, top_line, naviData.Altimeter / 3, 100, 0); |
522 | write_ndigit_number_s_10th(23, top_line, naviData.Altimeter / 3, 100, 0); |
489 | } |
523 | } |
490 | 524 | ||
491 | // seccond line |
525 | // seccond line |
492 | draw_compass(11, top_line + 1, naviData.CompassHeading); |
526 | draw_compass(11, top_line + 1, naviData.CompassHeading); |
493 | 527 | ||
494 | // TODO: verify correctness |
528 | // TODO: verify correctness |
495 | uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360 - naviData.CompassHeading) % 360; |
529 | uint16_t heading_home = (naviData.HomePositionDeviation.Bearing + 360 - naviData.CompassHeading) % 360; |
496 | //write_char_xy(21, top_line + 1, arrowdir[heading_conv(heading_home)]); |
530 | //write_char_xy(21, top_line + 1, arrowdir[heading_conv(heading_home)]); |
497 | // finer resolution, 0xa0 is first character and we add the index 0 <= index < 16 |
531 | // finer resolution, 0xa0 is first character and we add the index 0 <= index < 16 |
498 | write_char_xy(21, top_line + 1, 0xa0 + heading_fine_conv(heading_home)); |
532 | write_char_xy(21, top_line + 1, 0xa0 + heading_fine_conv(heading_home)); |
499 | 533 | ||
500 | write_ndigit_number_u(24, top_line + 1, naviData.HomePositionDeviation.Distance / 10, 100, 0); |
534 | write_ndigit_number_u(24, top_line + 1, naviData.HomePositionDeviation.Distance / 10, 100, 0); |
501 | 535 | ||
502 | // center |
536 | // center |
503 | if (naviData.MKFlags & FLAG_MOTOR_RUN) { // should be engines running |
537 | if (naviData.MKFlags & FLAG_MOTOR_RUN) { // should be engines running |
504 | if (!(old_MKFlags & FLAG_MOTOR_RUN)) { // motors just started, clear middle |
538 | if (!(old_MKFlags & FLAG_MOTOR_RUN)) { // motors just started, clear middle |
505 | clear(); |
539 | clear(); |
506 | // update flags to paint display again if needed |
540 | // update flags to paint display again if needed |
507 | COSD_FLAGS &= ~COSD_ICONS_WRITTEN; |
541 | COSD_FLAGS &= ~COSD_ICONS_WRITTEN; |
508 | } |
542 | } |
509 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
543 | if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { |
510 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
544 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
511 | } |
545 | } |
512 | // motors are on, assume we were/are flying |
546 | // motors are on, assume we were/are flying |
513 | COSD_FLAGS |= COSD_WASFLYING; |
547 | COSD_FLAGS |= COSD_WASFLYING; |
514 | } else { |
548 | } else { |
515 | // stats |
549 | // stats |
516 | if ((COSD_FLAGS & COSD_WASFLYING) && (COSD_FLAGS & COSD_FLAG_STATS)) { |
550 | if ((COSD_FLAGS & COSD_WASFLYING) && (COSD_FLAGS & COSD_FLAG_STATS)) { |
517 | write_ascii_string_pgm(2, 4, stats_item_pointers[0]); // max Altitude |
551 | write_ascii_string_pgm(2, 4, stats_item_pointers[0]); // max Altitude |
518 | write_ndigit_number_s(18, 4, max_Altimeter / 30, 1000, 0); |
552 | write_ndigit_number_s(18, 4, max_Altimeter / 30, 1000, 0); |
519 | write_char_xy(22, 4, 204); // small meters m |
553 | write_char_xy(22, 4, 204); // small meters m |
520 | write_ascii_string_pgm(2, 5, stats_item_pointers[1]); // max Speed |
554 | write_ascii_string_pgm(2, 5, stats_item_pointers[1]); // max Speed |
521 | write_ndigit_number_u(19, 5, (uint16_t) (((uint32_t) max_GroundSpeed * (uint32_t)9) / (uint32_t)250), 100, 0); |
555 | write_ndigit_number_u(19, 5, (uint16_t) (((uint32_t) max_GroundSpeed * (uint32_t)9) / (uint32_t)250), 100, 0); |
522 | write_char_xy(22, 5, 203); // km/h |
556 | write_char_xy(22, 5, 203); // km/h |
523 | write_ascii_string_pgm(2, 6, stats_item_pointers[2]); // max Distance |
557 | write_ascii_string_pgm(2, 6, stats_item_pointers[2]); // max Distance |
524 | write_ndigit_number_u(19, 6, max_Distance / 10, 100, 0); |
558 | write_ndigit_number_u(19, 6, max_Distance / 10, 100, 0); |
525 | write_char_xy(22, 6, 204); // small meters m |
559 | write_char_xy(22, 6, 204); // small meters m |
526 | write_ascii_string_pgm(2, 7, stats_item_pointers[3]); // min voltage |
560 | write_ascii_string_pgm(2, 7, stats_item_pointers[3]); // min voltage |
527 | write_ndigit_number_u_10th(18, 7, min_UBat, 100, 0); |
561 | write_ndigit_number_u_10th(18, 7, min_UBat, 100, 0); |
528 | write_char_xy(22, 7, 0x9E); // small v |
562 | write_char_xy(22, 7, 0x9E); // small v |
529 | write_ascii_string_pgm(2, 8, stats_item_pointers[4]); // max time |
563 | write_ascii_string_pgm(2, 8, stats_item_pointers[4]); // max time |
530 | write_time(16, 8, max_FlyingTime); |
564 | write_time(16, 8, max_FlyingTime); |
531 | write_char_xy(22, 8, 210); // fly clock |
565 | write_char_xy(22, 8, 210); // fly clock |
532 | write_ascii_string_pgm(2, 9, stats_item_pointers[5]); // longitude |
566 | write_ascii_string_pgm(2, 9, stats_item_pointers[5]); // longitude |
533 | write_gps_pos(15, 9, naviData.CurrentPosition.Longitude); |
567 | write_gps_pos(15, 9, naviData.CurrentPosition.Longitude); |
534 | write_ascii_string_pgm(2, 10, stats_item_pointers[6]); // latitude |
568 | write_ascii_string_pgm(2, 10, stats_item_pointers[6]); // latitude |
535 | write_gps_pos(15, 10, naviData.CurrentPosition.Latitude); |
569 | write_gps_pos(15, 10, naviData.CurrentPosition.Latitude); |
536 | } else if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon |
570 | } else if (COSD_FLAGS & COSD_FLAG_ARTHORIZON) { // if no stats there is space horizon |
537 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
571 | draw_artificial_horizon(top_line + 2, bottom_line - 1, naviData.AngleNick, naviData.AngleRoll); |
538 | } |
572 | } |
539 | } |
573 | } |
540 | if (COSD_FLAGS & COSD_FLAG_BIGVARIO) { |
574 | if (COSD_FLAGS & COSD_FLAG_BIGVARIO) { |
541 | draw_big_variometer(27, 8, naviData.Variometer); |
575 | draw_big_variometer(27, 8, naviData.Variometer); |
542 | } |
576 | } |
543 | 577 | ||
544 | // bottom line |
578 | // bottom line |
545 | draw_battery(2, bottom_line, naviData.UBat); |
579 | draw_battery(2, bottom_line, min_voltage, naviData.UBat, max_voltage); |
546 | write_ndigit_number_u_10th(3, bottom_line, naviData.UBat, 100, 0); |
580 | write_ndigit_number_u_10th(3, bottom_line, naviData.UBat, 100, 0); |
547 | if (naviData.UBat <= UBAT_WRN && last_UBat > UBAT_WRN) { |
581 | if (naviData.UBat <= min_voltage && last_UBat > min_voltage) { |
548 | for (uint8_t x = 2; x < 8; x++) |
582 | for (uint8_t x = 2; x < 8; x++) |
549 | write_char_att_xy(x, bottom_line, BLINK); |
583 | write_char_att_xy(x, bottom_line, BLINK); |
550 | } else { |
584 | } else if (naviData.UBat > min_voltage && last_UBat < min_voltage) { |
551 | for (uint8_t x = 2; x < 8; x++) |
585 | for (uint8_t x = 2; x < 8; x++) |
552 | write_char_att_xy(x, bottom_line, 0); |
586 | write_char_att_xy(x, bottom_line, 0); |
553 | } |
587 | } |
554 | - | ||
- | 588 | // remember last values |
|
- | 589 | last_UBat = naviData.UBat; |
|
555 | 590 | ||
556 | write_time(8, bottom_line, uptime); |
591 | write_time(8, bottom_line, uptime); |
557 | write_time(15, bottom_line, naviData.FlyingTime); |
592 | write_time(15, bottom_line, naviData.FlyingTime); |
558 | 593 | ||
559 | write_ndigit_number_u(24, bottom_line, naviData.SatsInUse, 10, 0); |
594 | write_ndigit_number_u(24, bottom_line, naviData.SatsInUse, 10, 0); |
560 | 595 | ||
561 | if (naviData.NCFlags & NC_FLAG_MANUAL_CONTROL) { |
596 | if (naviData.NCFlags & NC_FLAG_MANUAL_CONTROL) { |
562 | write_char_xy(23, bottom_line, 0xB3); // rc transmitter |
597 | write_char_xy(23, bottom_line, 0xB3); // rc transmitter |
563 | } else { |
598 | } else { |
564 | write_char_xy(23, bottom_line, 0); // clear |
599 | write_char_xy(23, bottom_line, 0); // clear |
565 | } |
600 | } |
566 | 601 | ||
567 | if (naviData.NCFlags & NC_FLAG_CH) { |
602 | if (naviData.NCFlags & NC_FLAG_CH) { |
568 | write_char_xy(27, bottom_line, 231); // gps ch |
603 | write_char_xy(27, bottom_line, 231); // gps ch |
569 | } else if (naviData.NCFlags & NC_FLAG_PH) { |
604 | } else if (naviData.NCFlags & NC_FLAG_PH) { |
570 | write_char_xy(27, bottom_line, 230); // gps ph |
605 | write_char_xy(27, bottom_line, 230); // gps ph |
571 | } else { // (naviData.NCFlags & NC_FLAG_FREE) |
606 | } else { // (naviData.NCFlags & NC_FLAG_FREE) |
572 | write_char_xy(27, bottom_line, 201); // sat2 (free) |
607 | write_char_xy(27, bottom_line, 201); // sat2 (free) |
573 | } |
608 | } |
574 | 609 | ||
575 | //write_number_s(8, 5, RxDataLen); |
610 | //write_number_s(8, 5, RxDataLen); |
576 | //write_number_s(16, 5, setsReceived++); |
611 | //write_number_s(16, 5, setsReceived++); |
577 | 612 | ||
578 | // remember statistics (only when engines running) |
613 | // remember statistics (only when engines running) |
579 | if (naviData.MKFlags & FLAG_MOTOR_RUN) { |
614 | if (naviData.MKFlags & FLAG_MOTOR_RUN) { |
580 | if (naviData.Altimeter > max_Altimeter) max_Altimeter = naviData.Altimeter; |
615 | if (naviData.Altimeter > max_Altimeter) max_Altimeter = naviData.Altimeter; |
581 | if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed; |
616 | if (naviData.GroundSpeed > max_GroundSpeed) max_GroundSpeed = naviData.GroundSpeed; |
582 | if (naviData.HomePositionDeviation.Distance > max_Distance) { |
617 | if (naviData.HomePositionDeviation.Distance > max_Distance) { |
583 | max_Distance = naviData.HomePositionDeviation.Distance; |
618 | max_Distance = naviData.HomePositionDeviation.Distance; |
584 | } |
619 | } |
585 | if (naviData.UBat < min_UBat) min_UBat = naviData.UBat; |
620 | if (naviData.UBat < min_UBat) min_UBat = naviData.UBat; |
586 | if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime; |
621 | if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime; |
587 | } |
622 | } |
588 | 623 | ||
589 | old_MKFlags = naviData.MKFlags; |
624 | old_MKFlags = naviData.MKFlags; |
590 | seconds_since_last_data = 0; |
625 | seconds_since_last_data = 0; |
591 | } |
626 | } |
592 | } |
627 | } |
593 | rxd_buffer_locked = 0; |
628 | rxd_buffer_locked = 0; |
594 | } |
629 | } |
595 | // handle keypress |
630 | // handle keypress |
596 | if (s1_pressed()) { |
631 | if (s1_pressed()) { |
597 | config_menu(); |
632 | config_menu(); |
598 | } |
633 | } |
599 | if (seconds_since_last_data > 2) { |
634 | if (seconds_since_last_data > 2) { |
600 | // request OSD Data from NC every 100ms |
635 | // request OSD Data from NC every 100ms |
601 | usart1_request_mk_data(1, 'o', 100); |
636 | usart1_request_mk_data(1, 'o', 100); |
602 | seconds_since_last_data = 0; |
637 | seconds_since_last_data = 0; |
603 | } |
638 | } |
604 | } |
639 | } |
605 | #endif |
640 | #endif |
606 | return 0; |
641 | return 0; |
607 | } |
642 | } |
608 | 643 |